From 36c7de408cc81c801e93060f606f37c486cd32e5 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Mon, 29 Nov 2021 23:24:28 -0500 Subject: move scpi capable instrument to a separate class --- lockin.py | 63 ++---------------------------------------------------------- scpi.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 scpi.py diff --git a/lockin.py b/lockin.py index 18cffb2..3fc157b 100644 --- a/lockin.py +++ b/lockin.py @@ -3,66 +3,9 @@ provide basic class to operate Lock-in """ import pyvisa +import scpi -class SCPIinstr: - """ Basic class which support SCPI commands """ - """ - Do not instantiate directly, use - rm = pyvisa.ResourceManager() - SCPIinstr(rm.open_resource('TCPIP::192.168.0.2::INSTR')) - """ - def __init__(self, resource): - print(resource) - self.resource = resource - - # convenience pyvisa functions - self.write = self.resource.write - self.read = self.resource.read - self.query = self.resource.query - #self.query_values = self.resource.query_values - - @property - def idn(self): - return self.query("*IDN?") - - def clear_status(self): - self.write("*CLS") - - def set_event_status_enable(self): - self.write("*ESE") - - def query_event_status_enable(self): - self.query("*ESE?") - - def query_event_status_register(self): - self.query("*ESR?") - - def set_wait_until_finished(self): - self.query("*OPC") - - def wait_until_finished(self): - self.query("*OPC?") - - def reset(self): - self.write("*RST") - - def set_service_request_enable(self): - self.write("*SRE") - - def query_service_request_enable(self): - self.query("*SRE?") - - def query_status_byte(self): - self.query("*STB?") - - def self_test_result(self): - self.query("*TST?") - - def wait(self): - self.write("*WAI") - - -class LockIn(SCPIinstr): +class LockIn(scpi.SCPIinstr): """ Do not instantiate directly, use rm = pyvisa.ResourceManager() @@ -79,8 +22,6 @@ if __name__ == '__main__': print(rm.list_resources()) instr=rm.open_resource('TCPIP::192.168.0.51::INSTR') lckn = LockIn(instr) - # lckn = LockIn(rm, 'TCPIP::192.168.0.51::INSTR') - print(lckn.query('*idn?')) print(lckn.idn) diff --git a/scpi.py b/scpi.py new file mode 100644 index 0000000..63b9e0a --- /dev/null +++ b/scpi.py @@ -0,0 +1,66 @@ +""" +provide basic class to operate Lock-in +""" + +import pyvisa + +class SCPIinstr: + """ Basic class which support SCPI commands """ + """ + Do not instantiate directly, use + rm = pyvisa.ResourceManager() + SCPIinstr(rm.open_resource('TCPIP::192.168.0.2::INSTR')) + """ + def __init__(self, resource): + print(resource) + self.resource = resource + + # convenience pyvisa functions + 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 + + @property + def idn(self): + return self.query("*IDN?") + + def clear_status(self): + self.write("*CLS") + + def set_event_status_enable(self): + self.write("*ESE") + + def query_event_status_enable(self): + self.query("*ESE?") + + def query_event_status_register(self): + self.query("*ESR?") + + def set_wait_until_finished(self): + self.query("*OPC") + + def wait_until_finished(self): + self.query("*OPC?") + + def reset(self): + self.write("*RST") + + def set_service_request_enable(self): + self.write("*SRE") + + def query_service_request_enable(self): + self.query("*SRE?") + + def query_status_byte(self): + self.query("*STB?") + + def self_test_result(self): + self.query("*TST?") + + def wait(self): + self.write("*WAI") + + -- cgit v1.2.3