diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2023-06-21 11:48:19 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2023-06-21 11:48:19 -0400 |
commit | 159b2357fb6ba6dd4293010228de6d18aabd94df (patch) | |
tree | 3c155f5c6e30fcb7b8bf91f0fd49987998b2c157 /qolab/hardware/multimeter | |
parent | 1eb507f97c3aebc76383e29eb703a4286b1aa8c6 (diff) | |
download | qolab-159b2357fb6ba6dd4293010228de6d18aabd94df.tar.gz qolab-159b2357fb6ba6dd4293010228de6d18aabd94df.zip |
rewrite read and write communication with bk_5491
Diffstat (limited to 'qolab/hardware/multimeter')
-rw-r--r-- | qolab/hardware/multimeter/bk_5491.py | 109 |
1 files changed, 64 insertions, 45 deletions
diff --git a/qolab/hardware/multimeter/bk_5491.py b/qolab/hardware/multimeter/bk_5491.py index 0b9d788..cca8d7f 100644 --- a/qolab/hardware/multimeter/bk_5491.py +++ b/qolab/hardware/multimeter/bk_5491.py @@ -22,9 +22,12 @@ class BK_5491(Multimeter): self.resource.stop_bits = pyvisa_constants.StopBits.one self.resource.timeout = 5000 - self.write = self.resource.write self.read = self.resource.read - self.query = self.resource.query + # we need to work around the prompts which BK_5491 sends during + # communication to mimic SCPI + # if you need raw connection use self.resource.write or self.resource.query + # self.write = self.resource.write + # self.query = self.resource.query self.read_bytes = self.resource.read_bytes self.read_binary_values = self.resource.read_binary_values self.query_binary_values = self.resource.query_binary_values @@ -43,88 +46,104 @@ class BK_5491(Multimeter): print(f'Error detected {prompt=}') return False - def sendCmd(self, cmd_string, expect_reply=True, Nattemts=5): + def write(self, cmd_string): + return self._readwrite(cmd_string, expect_reply=False, Nattemts=1) + def query(self, cmd_string): + return self._readwrite(cmd_string, expect_reply=True, Nattemts=5) + + def _readwrite(self, cmd_string, expect_reply=True, Nattemts=5): """ Set command to instrument or query it readings (which is also a command) - BK_5491 in not SCPI instrument, so we get some replies (prompts *>, =>, etc) + BK_5491 is not a SCPI instrument, so we get some replies (prompts *>, =>, etc) even if we just send a command not a query. So we have to work around this. """ self.resource.read_bytes( self.resource.bytes_in_buffer ) # clear read buffer # print(f"dbg: {cmd_string=}") - self.write(cmd_string) + self.resource.write(cmd_string) if expect_reply: - reply = self.read() # this should be result + reply = self.resource.read() # this should be result # print(f"dbg: {reply=}") if self.isPrompt(reply): - # print(f'Error: we ask {cmd_string=} and got prompt "{reply}" instead of result') prompt = reply if prompt[0] == '@': if Nattemts >= 2: # print('dbg: numeric reading is not available yet, attempt one more time') time.sleep(self.switchTime) - return self.sendCmd(cmd_string, expect_reply=expect_reply, Nattemts=Nattemts-1) + return self._readwrite(cmd_string, expect_reply=expect_reply, Nattemts=Nattemts-1) + print(f'Error: we ask {cmd_string=} and got prompt "{reply}" instead of result') return None else: reply = None - prompt = self.read() # this should be prompt - self.isPromptGood(prompt) - # print(f"dbg: {prompt=}") + prompt = self.resource.read() # this should be prompt + if not self.isPromptGood(prompt): + print(f'Error: expected good prompt but got "{prompt=}"') return reply def getReading(self): - """ Report current measurement """ - ret_string = self.sendCmd('R1') + """ Report current measurement displayed on the first/main display """ + ret_string = self.query('R1') # print(f'dbg: getReading received "{ret_string}"') return float(ret_string) - def setFunction(self, key_string): - """ - BK_5491 set the measurement functions according to the front panel keys: - K1 - Vdc - K2 - Adc - K3 - Vac - K4 - Aac - K5 - Resistance - K6 - Diode - K7 - Frequency (Hz) - K8 - Auto - K9 - Up key - K10 - Down key - K11 - MinMax key - K12 - Hold key - K13 - Local (manual does not specify, but it works this way) - K14 - Rel key - K15 - Shift key - K16 - 2nd key - K17 - Vdc and Vac keys simultaneously - K18 - Adc and Aac keys simultaneously - K19 - Shift then Up keys (increasing the intensity of the VFD display) - K20 - Shift then Down keys (decreasing the intensity of the VFD display) - """ - + """ + BK_5491 has two displays which could be set and read separately, + here we use only setting of the 1st display (prefix S1 below) + to set the measurement and read it later. + It is also possible to set range, but I prefer to leave in to + the front panel user. + If this is needed it would be followed by 3 symbols specifiers as + outline in the manual. + """ def getVdc(self): - self.sendCmd('K1') + self.write('S10') return self.getReading() def getVac(self): - self.sendCmd('K3') + self.write('S11') return self.getReading() def getAdc(self): - self.sendCmd('K2') + self.write('S14') return self.getReading() def getAac(self): - self.sendCmd('K4') + self.write('S15') return self.getReading() def getResistance(self): - self.sendCmd('K5') + self.write('S12') + return self.getReading() + def getResistance4Wires(self): + self.write('S13') return self.getReading() def getDiode(self): - self.sendCmd('K6') + self.write('S16') return self.getReading() def getFreq(self): - self.sendCmd('K7') + self.write('S17') return self.getReading() + """ + With BK_5491 + It is possible to send "key presses" like they are coming from the front panel + K1 - Vdc + K2 - Adc + K3 - Vac + K4 - Aac + K5 - Resistance + K6 - Diode + K7 - Frequency (Hz) + K8 - Auto + K9 - Up key + K10 - Down key + K11 - MinMax key + K12 - Hold key + K13 - Local (manual does not specify, but it works this way) + K14 - Rel key + K15 - Shift key + K16 - 2nd key + K17 - Vdc and Vac keys simultaneously + K18 - Adc and Aac keys simultaneously + K19 - Shift then Up keys (increasing the intensity of the VFD display) + K20 - Shift then Down keys (decreasing the intensity of the VFD display) + """ def toLocal(self): self.sendCmd('K13', expect_reply=False) |