Beispiel #1
0
def Example2():
    ser = serial.Serial('/dev/ttyS1', 9600, timeout=1)
    x = ser.read()          # read one byte
    print( "read one byte = ", x )
    s = ser.read(10)        # read up to ten bytes (timeout)
    print( "read multiple bytes = ", s )
    line = ser.readline()   # read a '\n' terminated line
    ser.close()
    print( "read a line = ", line )
Beispiel #2
0
def Example3():
    ser = serial.Serial()
    ser.baudrate = 9600
    ser.port = 0
    print( f"Serial port information...\n    {ser}" )

    ser.open()
    print( f"Serial port open = {str( ser.isOpen() )}" )

    ser.close()
    print( f"Serial port open = {str( ser.isOpen() )}" )
def Example3():
    ser = serial.Serial()
    ser.baudrate = 19200
    ser.port = 0
    print(ser)

    ser.open()
    print(str(ser.isOpen()))

    ser.close()
    print(ser.isOpen())
Beispiel #4
0
    def serial_connect(self):
        """
        This method establishes the serial connection with the microcontroller.

        Once the comport of the pump is known we open a serial connection to it using pySerial.
        """

        if self.port == None:
            self.connected = False
        else:
            self.ser = serial.Serial(self.port, self.baud, timeout=3)
            if self.ser.isOpen():
                self.connected = True
            else:
                self.connected = False
from button import Button
from tkinter import Tk, Canvas, CENTER, RIGHT, LEFT, N, PhotoImage
import math
import os

dirname = os.path.dirname(__file__)

test = True

if test:
    import fakeSerial as serial
else:
    import serial

ser = serial.Serial("/dev/ttyAMA0", 9600)  # /dev/ttyAMA0 on the pi

root = Tk()
# Full screen
if not test:
    root.overrideredirect(True)
    root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(),
                                       root.winfo_screenheight()))
    root.focus_set()  #Move focus to this widget
    root.bind("<Escape>", lambda e: root.quit())
    root.config(cursor="none")

# Variables
height = 480
width = 800
color_inactive = "white"
color_active = "#32CD32"  # lime green
Beispiel #6
0
def Example1():
    ser = serial.Serial(0)  # open first serial port
    print( ser.name )       # check which port was really used
    ser.write("My car drives itself")      # write a string
    ser.close()             # close port