try:
self.serSer.open()
if self.serSer.isOpen():
self.alive = True
except Exception as e:
self.alive = False
logging.error(e)
def stop(self):
self.alive = False
if self.serSer.isOpen():
self.serSer.close()
def read(self):
while self.alive:
try:
number = self.serSer.inWaiting()
if number:
self.receive_data += self.serSer.read(number).replace(binascii.unhexlify("00"), "")
if self.thresholdValue <= len(self.receive_data):
self.receive_data = ""
except Exception as e:
logging.error(e)
def write(self, data, isHex=False):
if self.alive:
if self.serSer.isOpen():
if isHex:
# data = data.replace(" ", "").replace("n", "")
data = binascii.unhexlify(data)
self.serSer.write(data)