July 2021
22
title = "Packet Protocol Reciever"
ver=" V1.5"
headerLength = 22
senderAddrOffset = 2
senderIDOffset = 4
recipientAddrOffset = 5
recipientIDOffset = 7
lengthOffset = 12
chksumOffset = 16
stopRequest = False
stopAck = False
def __init__(self, aPortName, aGui):
threading.Thread.__init__(self)
self.gui = aGui
if self.gui is not None:
aGui.setReader(self)
self.portName = aPortName.upper()
self.ser = None
self.lenPacket = 0
self.parsedChecksum = 0
self.test_directory = self.title.replace(' ', '')
print(self.title + self.ver)
self.test_directory_path = os.path.join("C:/Baker/Test Software", self.test_directory)
self.rawFilename = None
self.rawFile = None
self.dataFilename = None
self.dataFile = None
self.eventFilename = None
self.eventFile = None
if self.gui != None:
self.start()
self.gui.mainloop()
def run(self):
while True:
try:
print(self.portName)
if self.ser is None:
self.ser = Serialize(self.portName)
if self.ser.checkOpen() is False:
self.ser.open()
if self.ser.checkOpen():
print("port open " + self.portName)
if self.gui != None:
self.gui.title(self.title + self.ver + " " + self.portName)
inChar = self.ser.readbytes(1)
while True:
if BPPReader.stopRequest:
BPPReader.stopAck = True
print("BPPReader stopping.")
return
if inChar != b'':
if self.gui is None:
print(inChar)
if inChar == b'#':
inChar = self.ser.readbytes(1)
if inChar == b'@':
if False == self.processPacket():
break
if BPPReader.stopRequest:
BPPReader.stopAck = True
print("BPPReader stopping.")
return
inChar = self.ser.readbytes(1)