From 88aae05251b532e8e9f8e325455a8d6f43cffb89 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Thu, 6 Jan 2022 21:05:45 -0500 Subject: extra safety net for replies from iServer --- qolab/hardware/i_server/i800.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qolab/hardware/i_server/i800.py b/qolab/hardware/i_server/i800.py index 2b3f55f..b7b2fc9 100644 --- a/qolab/hardware/i_server/i800.py +++ b/qolab/hardware/i_server/i800.py @@ -38,13 +38,15 @@ class I800(BasicInstrument): s.send(qstr.encode('ascii')) reply = s.recv(100).decode('ascii') s.close() + rlist=reply.split(); # occasionally there is more than one reply, it also removes \r + reply=rlist[-1]; # we will use the last one if reply[0:5] != f'{modbus_cmnd}': # check the proper echo response print(f'Warning: expected {modbus_cmnd} but got {reply[0:5]}') if trials > 0: return self.query(cmnd, trials -1 ) return None - return reply[5:-1] # last symbol is '\r' + return reply[5:] @BasicInstrument.tsdb_append @cached(cache=TTLCache(maxsize=1, ttl=TTL_MEASURED)) @@ -72,11 +74,11 @@ class I800(BasicInstrument): elif raw & (0b100 << 20): scale = 100 else: - print('Error: unknown decimal point position') - return None + print(f'Error: unknown decimal point position in decoded {spStr}') + return float('nan') val = raw & 0xFFFFF - return(sign*val/scale) + return float(sign*val/scale) @BasicInstrument.tsdb_append @cached(cache=TTLCache(maxsize=1, ttl=TTL_SEATABLES)) -- cgit v1.2.3