More debugging.
This commit is contained in:
parent
182575f41f
commit
509dc9eb11
@ -2,8 +2,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
class IPTCMessage(object):
|
class IPTCMessage(object):
|
||||||
def __init__(self):
|
def __init__(self, raw):
|
||||||
print("Hello world!")
|
self.raw = raw
|
||||||
|
print("Message: %s" % repr(self.raw))
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
print("Testmode!")
|
print("Testmode!")
|
||||||
|
@ -6,34 +6,36 @@ import IPTCMessage
|
|||||||
|
|
||||||
class _main(object):
|
class _main(object):
|
||||||
def __init__(self, port='/dev/tty706'):
|
def __init__(self, port='/dev/tty706'):
|
||||||
self.openPort(port)
|
ser = self.openPort(port)
|
||||||
while True:
|
while True:
|
||||||
msg = self.waitForStart()
|
msg = self.waitForStart(ser)
|
||||||
msg += self.readUntilEOM()
|
msg += self.readUntilEOM(ser)
|
||||||
print("This is the message: %s" % repr(msg))
|
iptc = IPTCMessage(msg)
|
||||||
|
|
||||||
def openPort(self, port):
|
def openPort(self, port):
|
||||||
self.port = serial.Serial(port, baudrate=4800, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None)
|
ser = serial.Serial(port=port, baudrate=4800, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None)
|
||||||
print("%s opened with %i baud. Timeout is %s seconds." % (self.port.name, self.port.baudrate, self.port.timeout))
|
print("%s opened with %i baud. Timeout is %s seconds." % (ser.name, ser.baudrate, ser.timeout))
|
||||||
|
return ser
|
||||||
|
|
||||||
def waitForStart(self):
|
def waitForStart(self, ser):
|
||||||
print("Waiting for start indicator: ", end='', flush=True)
|
print("Waiting for start indicator (%i): " % ser.inWaiting(), end='', flush=True)
|
||||||
while True:
|
while True:
|
||||||
byte = self.port.read()
|
byte = ser.read(size=1)
|
||||||
print(".", end='', flush=True)
|
print(".", end='', flush=True)
|
||||||
if byte == b'\x01':
|
if byte == b'\x01':
|
||||||
print("Found.")
|
print("Found.")
|
||||||
return byte
|
return byte
|
||||||
|
|
||||||
def readUntilEOM(self):
|
def readUntilEOM(self, ser):
|
||||||
print("Reading data until EOM.", end='', flush=True)
|
print("Reading data until EOM.", end='', flush=True)
|
||||||
msg = b''
|
msg = b''
|
||||||
ctr = 0
|
ctr = 0
|
||||||
while True:
|
while True:
|
||||||
byte = self.port.read()
|
print("%i>" % ser.inWaiting(), end='', flush=True)
|
||||||
|
byte = ser.read(size=1)
|
||||||
ctr+=1
|
ctr+=1
|
||||||
if ctr % 10 is 0:
|
# if ctr % 10 is 0:
|
||||||
print(".", end='', flush=True)
|
print(".", end='', flush=True)
|
||||||
if byte == b'\x01':
|
if byte == b'\x01':
|
||||||
print("PROBLEM: Got start indicator, but message not yet finished.")
|
print("PROBLEM: Got start indicator, but message not yet finished.")
|
||||||
break
|
break
|
||||||
@ -43,8 +45,8 @@ class _main(object):
|
|||||||
print("Got %i bytes." % len(msg))
|
print("Got %i bytes." % len(msg))
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def readLine(self):
|
def readLine(self, ser):
|
||||||
rcv = self.port.readline()
|
rcv = ser.readline()
|
||||||
print("Got: %s" % repr(rcv))
|
print("Got: %s" % repr(rcv))
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
|
Reference in New Issue
Block a user