diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2023-06-20 17:39:55 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2023-06-20 17:39:55 -0400 |
commit | 78831112a1e9443ea5c1fc527fb753fc1dc01339 (patch) | |
tree | d7a0397138f6e8136f30e46ae5453335eb42a363 /qolab/hardware/multimeter/bk_5491.py | |
parent | 6023425f8db0df9be996e418c53d2634f36054b9 (diff) | |
download | qolab-78831112a1e9443ea5c1fc527fb753fc1dc01339.tar.gz qolab-78831112a1e9443ea5c1fc527fb753fc1dc01339.zip |
added draft of BK_5491 multimeter
Diffstat (limited to 'qolab/hardware/multimeter/bk_5491.py')
-rw-r--r-- | qolab/hardware/multimeter/bk_5491.py | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/qolab/hardware/multimeter/bk_5491.py b/qolab/hardware/multimeter/bk_5491.py new file mode 100644 index 0000000..9186854 --- /dev/null +++ b/qolab/hardware/multimeter/bk_5491.py @@ -0,0 +1,140 @@ +from qolab.hardware.basic import BasicInstrument +from qolab.hardware.multimeter import Multimeter +from qolab.hardware.scpi import SCPI_PROPERTY +from pyvisa import constants as pyvisa_constants +import time + +class 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']='HP 34401' + self.resource.read_termination = '\r\n' + self.resource.baud_rate = 9600 + self.resource.data_bits = 8 + self.resource.parity = pyvisa_constants.Parity.none + 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 + 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 + + self.switchTime = 0.5 # switch time in seconds for Function/Measurement change + self.deviceProperties.update({}) + + def isPrompt(self, string): + if string[1] == '>': + return True + return False + + def isPromptGood(self, prompt): + if prompt[0:2] == '=>': + return True + print(f'Error detected {prompt=}') + return False + + def sendCmd(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) + even if we just send a command not a query. So we have to work around this. + """ + # print(f"dbg: {cmd_string=}") + self.write(cmd_string) + if expect_reply: + reply = self.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 None + else: + reply = None + prompt = self.read() # this should be prompt + self.isPromptGood(prompt) + # print(f"dbg: {prompt=}") + return reply + + def getReading(self): + """ Report current measurement """ + ret_string = self.sendCmd('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) + """ + + def getVdc(self): + self.sendCmd('K1') + return self.getReading() + def getVac(self): + self.sendCmd('K3') + return self.getReading() + def getAdc(self): + self.sendCmd('K2') + return self.getReading() + def getAac(self): + self.sendCmd('K4') + return self.getReading() + def getResistance(self): + self.sendCmd('K5') + return self.getReading() + def getDiode(self): + self.sendCmd('K6') + return self.getReading() + def getFreq(self): + self.sendCmd('K7') + return self.getReading() + + def toLocal(self): + self.sendCmd('K13', expect_reply=False) + + +if __name__ == '__main__': + import pyvisa + print("testing") + rm = pyvisa.ResourceManager() + 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 -------------') |