Beispiel #1
0
    def __init__(self):
        self.serialPort = serial_rx_tx.SerialPort()
        self.serialPort.Open(myComPort, myBaudRate)
        self.serialPort.RegisterReceiveCallback(self.OnReceiveSerialData)
        self.ReceiveCallback = None
        self.receivedMessage = ""
        self.recievedList = []

        self.temp = 20
        self.humidity = 40
        self.batVoltage = 29
IP = ''
config_file = sys.argv[1]
commands = ''
set_default = True
serial_number = ''
with open(config_file, 'r') as f:
    commands = f.readlines()
    for comm in commands:
        if comm.startswith("COM Port:"):
            comport = comm[9:].rstrip()
        elif comm.startswith("Baud Rate:"):
            baudrate = comm[10:].rstrip()
        else:
            pass
#f.close()
serialPort = serial_rx_tx.SerialPort()


def OnReceiveSerialData():
    time.sleep(1.0)
    while serialPort.serialport.in_waiting > 0:
        print(
            serialPort.serialport.read(
                serialPort.serialport.in_waiting).decode("utf-8"))
        time.sleep(1.0)


def OpenCommand():
    global comport
    global baudrate
    serialPort.Open(comport, baudrate)