diff options
Diffstat (limited to 'qolab/hardware/multimeter/bk_5491.py')
-rw-r--r-- | qolab/hardware/multimeter/bk_5491.py | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/qolab/hardware/multimeter/bk_5491.py b/qolab/hardware/multimeter/bk_5491.py index 677f40a..015c36c 100644 --- a/qolab/hardware/multimeter/bk_5491.py +++ b/qolab/hardware/multimeter/bk_5491.py @@ -3,18 +3,21 @@ from qolab.hardware.multimeter import Multimeter from pyvisa import constants as pyvisa_constants import time + class BK_5491(Multimeter): - """ BK 5491 multimeter """ + """BK 5491 multimeter""" + """ rm = pyvisa.ResourceManager() instr=rm.open_resource('ASRL/dev/ttyUSB0::INSTR') Make sure to switch off the ECHO at the multimeter communication setup """ + def __init__(self, resource, *args, **kwds): super().__init__(*args, **kwds) self.resource = resource - self.config['Device model']='BK 5491' - self.resource.read_termination = '\r\n' + self.config["Device model"] = "BK 5491" + self.resource.read_termination = "\r\n" self.resource.baud_rate = 9600 self.resource.data_bits = 8 self.resource.parity = pyvisa_constants.Parity.none @@ -31,22 +34,23 @@ class BK_5491(Multimeter): self.read_binary_values = self.resource.read_binary_values self.query_binary_values = self.resource.query_binary_values - self.switchTime = 0.5 # switch time in seconds for Function/Measurement change - self.deviceProperties.update({'Function'}) + self.switchTime = 0.5 # switch time in seconds for Function/Measurement change + self.deviceProperties.update({"Function"}) def isPrompt(self, string): - if string[1] == '>': + if string[1] == ">": return True return False def isPromptGood(self, prompt): - if prompt[0:2] == '=>': + if prompt[0:2] == "=>": return True - print(f'Error detected {prompt=}') + print(f"Error detected {prompt=}") return False 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) @@ -57,33 +61,37 @@ class BK_5491(Multimeter): 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 + self.resource.read_bytes(self.resource.bytes_in_buffer) # clear read buffer # print(f"dbg: {cmd_string=}") self.resource.write(cmd_string) if expect_reply: - reply = self.resource.read() # this should be result + reply = self.resource.read() # this should be result # print(f"dbg: {reply=}") if self.isPrompt(reply): prompt = reply - if prompt[0] == '@': + if prompt[0] == "@": if Nattemts >= 2: # print('dbg: numeric reading is not available yet, attempt one more time') time.sleep(self.switchTime) - 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 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.resource.read() # this should be 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 displayed on the first/main display """ - ret_string = self.query('R1') - # print(f'dbg: getReading received "{ret_string}"') - return float(ret_string) + """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) """ BK_5491 has two displays which could be set and read separately, @@ -94,37 +102,45 @@ class BK_5491(Multimeter): If this is needed it would be followed by 3 symbols specifiers as outline in the manual. """ + @BasicInstrument.tsdb_append def getVdc(self): - self.write('S10') + self.write("S10") return self.getReading() + @BasicInstrument.tsdb_append def getVac(self): - self.write('S11') + self.write("S11") return self.getReading() + @BasicInstrument.tsdb_append def getAdc(self): - self.write('S14') + self.write("S14") return self.getReading() + @BasicInstrument.tsdb_append def getAac(self): - self.write('S15') + self.write("S15") return self.getReading() + @BasicInstrument.tsdb_append def getResistance(self): - self.write('S12') + self.write("S12") return self.getReading() + @BasicInstrument.tsdb_append def getResistance4Wires(self): - self.write('S13') + self.write("S13") return self.getReading() + @BasicInstrument.tsdb_append def getDiode(self): - self.write('S16') + self.write("S16") return self.getReading() + @BasicInstrument.tsdb_append def getFreq(self): - self.write('S17') + self.write("S17") return self.getReading() """ @@ -151,11 +167,12 @@ class BK_5491(Multimeter): 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) + self.sendCmd("K13", expect_reply=False) def getFunction(self): - reply = self.query('R0') + reply = self.query("R0") """ According to the manual: The reply is in 10 digits in the form <h1><h2><g1><g2><v><x><f1><r1><f2><r2> @@ -198,14 +215,14 @@ class BK_5491(Multimeter): return "Unknown" - -if __name__ == '__main__': +if __name__ == "__main__": import pyvisa + print("testing") rm = pyvisa.ResourceManager() - print(rm.list_resources()) - instr=rm.open_resource('ASRL/dev/ttyUSB0::INSTR') + print(rm.list_resources()) + instr = rm.open_resource("ASRL/dev/ttyUSB0::INSTR") multimeter = BK_5491(instr) - print('------ Header start -------------') - print(str.join('\n', multimeter.getHeader())) - print('------ Header ends -------------') + print("------ Header start -------------") + print(str.join("\n", multimeter.getHeader())) + print("------ Header ends -------------") |