diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-06 21:05:45 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-06 21:05:45 -0500 |
commit | 88aae05251b532e8e9f8e325455a8d6f43cffb89 (patch) | |
tree | 7a72f870e04fc5d667a9569d5cd6b64b5907585a /qolab/hardware/i_server/i800.py | |
parent | 8c982a8371c029e3592ca047f70e0d3422884f91 (diff) | |
download | qolab-88aae05251b532e8e9f8e325455a8d6f43cffb89.tar.gz qolab-88aae05251b532e8e9f8e325455a8d6f43cffb89.zip |
extra safety net for replies from iServer
Diffstat (limited to 'qolab/hardware/i_server/i800.py')
-rw-r--r-- | qolab/hardware/i_server/i800.py | 10 |
1 files 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)) |