From: Wilhelm K. <ku...@t-...> - 2021-12-21 20:00:26
|
Hello Lucas, I'm using linux-gpib with python 3 on my laptop with Ubuntu 20.04. I have also the DMM Keithley Model 2000. Because this device is able to understand SCPI I used the following code to read out the stored data: def read_buffer(geraetename, var): Werte = [] Board = gpib.find("USB-GPIB") # find interface address in gpib.config and assign it to Board Name = gpib.find(geraetename) # find device address in gpib.config and assign it to Name gpib.timeout(Name,0) # set Timeout to 'never timeout' gpib.write(Name,":DATA:DATA?") # ask for data String = gpib.read(Name,var*16) # read data and assign it to String gpib.wait(Board, 0x100) # wait until I/O-Operation complete i=1 while i<=var: Werte.append(float(String[(i-1)*16:(i-1)*16+15])) i=i+1 return Werte With the functions: def clear_buffer(geraetename): Name = gpib.find(geraetename) gpib.write(Name,":DATA:CLEAR") def set_buffer_size(geraetename, var): Name = gpib.find(geraetename) cmd = "" if var>1: if var<1025: cmd=":DATA:POINTS "+str(var) gpib.write(Name,cmd) you can clear and set the buffer. But I have to say, that these were my first tries to program the Keithley Model 2000. It works but it is not a very good programming technique. I searched for better solutions and found the python-ivi project from Alex Forencich. For me it's the best approach to use measurement equipment with python (see https://alexforencich.com/wiki/en/python-ivi/start). I started to write a python-ivi driver for the Keithley Model 2000. It is like this: """ Python Interchangeable Virtual Instrument Library Copyright (c) 2012-2014 Alex Forencich, 2021 Wilhelm Kusian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from .. import ivi from .. import dmm from .. import scpi # for Keithley 2000 individualized Tupel MeasurementAverageMapping = { 'dc_volts': 'volt:dc:average:state', 'ac_volts': 'volt:ac:average:state', 'dc_current': 'curr:dc:average:state', 'ac_current': 'curr:ac:average:state', 'two_wire_resistance': 'res:average:state', 'four_wire_resistance': 'fres:average:state'} MeasurementConfigureMapping = { 'dc_volts': 'configure:volt:dc', 'ac_volts': 'configure:volt:ac', 'dc_current': 'configure:curr:dc', 'ac_current': 'configure:curr:ac', 'two_wire_resistance': 'configure:res', 'four_wire_resistance': 'configure:fres'} MeasurementIntTimeMapping = { 'dc_volts': 'volt:dc:nplcycles', 'ac_volts': 'volt:ac:nplcycles', 'dc_current': 'curr:dc:nplcycles', 'ac_current': 'curr:ac:nplcycles', 'two_wire_resistance': 'res:nplcycles', 'four_wire_resistance': 'fres:nplcycles'} MeasurementRangeMapping = { 'dc_volts': 'volt:dc:range', 'ac_volts': 'volt:ac:range', 'dc_current': 'curr:dc:range', 'ac_current': 'curr:ac:range', 'two_wire_resistance': 'res:range', 'four_wire_resistance': 'fres:range'} TriggerSourceMapping = { 'bus': 'bus', 'external': 'ext', 'immediate': 'imm', 'timer': 'tim', 'manual': 'man'} class keithley2000(scpi.dmm.Base, scpi.dmm.MultiPoint, scpi.dmm.SoftwareTrigger): "Keithley 2000 IVI DMM driver" def __init__(self, *args, **kwargs): self.__dict__.setdefault('_instrument_id', '2000') super(keithley2000, self).__init__(*args, **kwargs) self._identity_description = "Keithley 2000 IVI DMM driver" self._identity_identifier = "" self._identity_revision = "" self._identity_vendor = "" self._identity_instrument_manufacturer = "Keithley" self._identity_instrument_model = "" self._identity_instrument_firmware_revision = "" self._identity_specification_major_version = 1 self._identity_specification_minor_version = 0 self._identity_supported_instrument_models = ['2000'] self._add_property('average', # additional property to set the filter function self._get_average, self._set_average) self._add_property('int_time', # additional property to set the integration time self._get_int_time, self._set_int_time) self._add_property('continuous', # additional property to set the continuous function, i.e. take out of the idle state self._get_continuous, self._set_continuous) def _initialize(self, resource = None, id_query = False, reset = False, **keywargs): "Opens an I/O session to the instrument." super(keithley2000, self)._initialize(resource, id_query, reset, **keywargs) # interface clear if not self._driver_operation_simulate: self._clear() # check ID if id_query and not self._driver_operation_simulate: id = self.identity.instrument_model id_check = self._instrument_id id_short = id[:len(id_check)] if id_short != id_check: raise Exception("Instrument ID mismatch, expecting %s, got %s", id_check, id_short) # reset if reset: self.utility.reset() def _get_average(self): if not self._driver_operation_simulate and not self._get_cache_valid(): func = self._get_measurement_function() if func in MeasurementAverageMapping: cmd = MeasurementAverageMapping[func] value = int(self._ask("%s?" % (cmd))) if value == 0: value = 'off' elif value == 1: value = 'on' self._average = value self._set_cache_valid() return self._average def _set_average(self, value): if value not in dmm.Auto2: raise ivi.ValueNotSupportedException() if not self._driver_operation_simulate: func = self._get_measurement_function() if func in MeasurementAverageMapping: cmd = MeasurementAverageMapping[func] self._write("%s %d" % (cmd, int(value == 'on'))) self._average = value self._set_cache_valid() def _get_int_time(self): if not self._driver_operation_simulate and not self._get_cache_valid(): func = self._get_measurement_function() if func in MeasurementIntTimeMapping: cmd = MeasurementIntTimeMapping[func] value = float(self._ask("%s?" % (cmd))) self._int_time = value*0.02 # power line cycles back converted to time value in 's' self._set_cache_valid() return self._int_time def _set_int_time(self, value): if value > 0.2: value = 0.2 if value < 0.0002: value = 0.0002 if not self._driver_operation_simulate: func = self._get_measurement_function() if func in MeasurementIntTimeMapping: cmd = MeasurementIntTimeMapping[func] self._write("%s %g" % (cmd, value/0.02)) # time value in 's' converted to power line cycles self._int_time = value self._set_cache_valid() def _get_continuous(self): if not self._driver_operation_simulate and not self._get_cache_valid(): cmd = ':INITIATE:CONTINUOUS' value = int(self._ask("%s?" % (cmd))) if value == 0: value = 'off' elif value == 1: value = 'on' self._continuous = value self._set_cache_valid() return self._continuous def _set_continuous(self, value): if value not in dmm.Auto2: raise ivi.ValueNotSupportedException() if not self._driver_operation_simulate: cmd = ':INITIATE:CONTINUOUS' self._write("%s %d" % (cmd, int(value == 'on'))) self._continuous = value self._set_cache_valid() def _get_trigger_source(self): # own function necessary because Keithley 2000 has more trigger source options if not self._driver_operation_simulate and not self._get_cache_valid(): value = self._ask("trigger:source?").lower() value = [k for k,v in TriggerSourceMapping.items() if v==value][0] self._trigger_source = value self._set_cache_valid() return self._trigger_source def _set_trigger_source(self, value): if value not in TriggerSourceMapping: raise ivi.ValueNotSupportedException() if not self._driver_operation_simulate: self._write(":trigger:source %s" % TriggerSourceMapping[value]) self._trigger_source = value def _get_range(self): # own function necessary because no furthe calculation necessary if not self._driver_operation_simulate and not self._get_cache_valid(): func = self._get_measurement_function() if func in MeasurementRangeMapping: cmd = MeasurementRangeMapping[func] value = float(self._ask("%s?" % (cmd))) self._range = value self._set_cache_valid() return self._range def _set_range(self, value): value = float(value) if not self._driver_operation_simulate: func = self._get_measurement_function() if func in MeasurementRangeMapping: cmd = MeasurementRangeMapping[func] self._write("%s %g" % (cmd, value)) self._range = value self._set_cache_valid() def _configure(self, max_time): # own function necessary because configure has an own meaning for this device if not self._driver_operation_simulate: func = self._get_measurement_function() if func in MeasurementConfigureMapping: cmd = MeasurementConfigureMapping[func] self._write("%s" % (cmd)) return 0.0 This works fine for me. I'm sure the package of Alex already implemented to read out the buffer, but I haven't had tested it yet. Hope this helps you. Wilhelm Am 20.12.21 um 21:47 schrieb lucas: > hello all, > > i've successfully installed and tested linux-gpib on a raspberry pi > 4+b with a NI-GPIB-USB-HS dongle and communicating with a Keithley > 2000 DMM instrument using python 3. should be fairly common and > pervasive i have python sending *idn? and receiving the proper > instrument response, "KEITHLEY INSTRUMENT INC., MODEL 2000, ..." etc. > so that much is working well. > > i'd like to setup the dmm to assert and trigger 25 voltage measurement > and when complete, signal back to the waiting raspberry that it's > completed its 25 measurements, and then the computer can download > those 25 measurements and process the voltages accordingly. > > will anyone share or point to some python code where this works > properly under similar circumstances, linux-gpib, GPIB-USB-HS, python, > etc.???? especially how to setup the assert, trigger, and raspberry > wait steps. thank you for your time and effort. > > lucas > > > > _______________________________________________ > Linux-gpib-general mailing list > Lin...@li... > https://lists.sourceforge.net/lists/listinfo/linux-gpib-general |