comparison rsib.py @ 79:84f96c5fe791

Use different message ID that does not result in "Query UNTERMINATE" messages in the error log. Fix testsrq. Rename queryrsb to querystb as that matches the operating manual.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Fri, 27 Sep 2024 16:53:43 +0930
parents 576f112e0aba
children
comparison
equal deleted inserted replaced
78:47da95b31dcb 79:84f96c5fe791
51 # Offs Value Meaning 51 # Offs Value Meaning
52 # 00 00 ? 52 # 00 00 ?
53 # 01 00 ? 53 # 01 00 ?
54 # 02 00 ? 54 # 02 00 ?
55 # 03 05 Length 55 # 03 05 Length
56 # 04 90 MsgID 56 # 04 94 MsgID
57 # 05 00 ? 57 # 05 00 ?
58 # 06 03 Seq number 58 # 06 03 Seq number
59 # 07 2a (*) Cmd byte 0 59 # 07 2a (*) Cmd byte 0
60 # 08 49 (I) Cmd byte 1 60 # 08 49 (I) Cmd byte 1
61 # 09 44 (D) Cmd byte 2 61 # 09 44 (D) Cmd byte 2
62 # 10 4a (N) Cmd byte 3 62 # 10 4a (N) Cmd byte 3
63 # 10 3f (?) Cmd byte 4 63 # 10 3f (?) Cmd byte 4
64 # 64 #
65 # Interactive program seems to cap length at 0x99 but perhaps the 65 # Interactive program seems to cap length at 0x99 but perhaps the
66 # first 4 bytes are length. 66 # first 4 bytes are length.
67 #
68 # MsgID is 0x94 but 0x90 works but then we get "Query UNTERMINATED"
69 # from SYS:ERR? Could be EoM bit.
67 # 70 #
68 # Reply to command: 71 # Reply to command:
69 # <- 00 00 00 23 80 00 01 52 6f 68 ... 72 # <- 00 00 00 23 80 00 01 52 6f 68 ...
70 # 73 #
71 # Offs Value Meaning 74 # Offs Value Meaning
76 # 04 00/80 Is 0x80 if this is the last block in a sequence 79 # 04 00/80 Is 0x80 if this is the last block in a sequence
77 # 05 00 ? 80 # 05 00 ?
78 # 06 01 Seq number 81 # 06 01 Seq number
79 82
80 MSG_HELLO = 0x40 # We send this on connect 83 MSG_HELLO = 0x40 # We send this on connect
81 MSG_CMD = 0x90 # Command to the instrument
82 MSG_SRQ = 0x91 # Query SRQ 84 MSG_SRQ = 0x91 # Query SRQ
83 85
84 import socket 86 import socket
85 import time 87 import time
86 88
120 if len(cmd) > 0x99: 122 if len(cmd) > 0x99:
121 raise ValueError("Command too long") 123 raise ValueError("Command too long")
122 124
123 # Pre-increment for easy comparison in read 125 # Pre-increment for easy comparison in read
124 self.tag = (self.tag + 1) & 0xff 126 self.tag = (self.tag + 1) & 0xff
125 msg = b'\x00\x00\x00' + bytes([len(cmd)]) + b'\x90\x00' + bytes([self.tag]) + cmd.encode('ascii') 127 msg = b'\x00\x00\x00' + bytes([len(cmd)]) + b'\x94\x00' + bytes([self.tag]) + cmd.encode('ascii')
126 self.s1.send(msg) 128 self.s1.send(msg)
127 129
128 def read(self, timeout = 0.5): 130 def read(self, timeout = 0.5):
129 """Read data from the device, waits for up to timeout seconds for each TCP read""" 131 """Read data from the device, waits for up to timeout seconds for each TCP read"""
130 132
175 def ask(self, s, timeout = None): 177 def ask(self, s, timeout = None):
176 '''Wrapper to send a command and wait for a reply''' 178 '''Wrapper to send a command and wait for a reply'''
177 self.write(s) 179 self.write(s)
178 return self.read(timeout = timeout) 180 return self.read(timeout = timeout)
179 181
180 def queryrsb(self): 182 def querystb(self):
181 msg = b'\x00\x00\x00\x00\xd1\x18\x00' 183 msg = b'\x00\x00\x00\x00\xd1\x18\x00'
182 self.s2.send(msg) 184 self.s2.send(msg)
183 185
184 reply = b'' 186 reply = b''
185 while len(reply) < 7: 187 while len(reply) < 7:
187 if rx == b'': 189 if rx == b'':
188 raise IOError("EOF from device") 190 raise IOError("EOF from device")
189 reply += rx 191 reply += rx
190 192
191 # '\x00\x00\x00\x00\x80\x04\x01' => STB = 4 193 # '\x00\x00\x00\x00\x80\x04\x01' => STB = 4
192 if rx[4] != b'\x80': 194 if rx[4] != 0x80:
193 raise IOError("Incorrect Msg ID in response to STB query") 195 raise IOError("Incorrect Msg ID in response to STB query")
194 196
195 return rx[5] 197 return rx[5]
196 198
197 def waitsrq(self): 199 def waitsrq(self):