From 8e8395d346f141602db00817c8eba9b8e5883d29 Mon Sep 17 00:00:00 2001 From: Grigor Kolev Date: Fri, 14 May 2021 21:10:46 +0300 Subject: [PATCH] fix parity Try that. Your is beter than my. --- sas.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sas.py b/sas.py index f82db52..15dd205 100644 --- a/sas.py +++ b/sas.py @@ -10,7 +10,8 @@ #ser = serial.Serial('/dev/ttyS3','19200', timeout=1) # open first serial port data_to_sent=[0x01, 0x21, 0x00, 0x00] #adress=1 -#print "OK" +#print "OK +PARYTY_CHANGE = True meters = dict.fromkeys(('total_cancelled_credits_meter', 'total_in_meter', 'total_out_meter', @@ -267,7 +268,19 @@ def start(self): return True + + def __events_port_conf(self): + self.connection.close() + self.connection.parity = serial.PARITY_NONE + self.connection.stopbits = serial.STOPBITS_TWO + self.connection.open() + def __port_conf(self): + self.connection.close() + self.connection.parity = serial.PARITY_SPACE + self.connection.stopbits = serial.STOPBITS_ONE + self.connection.open() + def __send_command( self, command, no_response=False, timeout=3, crc_need=True): busy = True response=b'' @@ -358,6 +371,8 @@ def checkResponse(self, rsp): ## return def events_poll(self, timeout=1): + if PARYTY_CHANGE == True: + self.__events_port_conf() event='' cmd=[0x80+self.adress] try: @@ -372,7 +387,9 @@ def events_poll(self, timeout=1): except Exception as e: print e - return None + event = None + if PARYTY_CHANGE == True: + self.__port_conf() return event