Пример #1
0
 def __init__(self):
     self.timer = LocalTimerClass()
     self._parameters = {}
     self.Name = 'General description of script'
     self.Description = """ Does nothing """
     self.init_parameters()
     self.devList = ListOfDevices()
     self.inExecution = False
     self.inTermination = False
     #self.executionThread =
     return
Пример #2
0
 def __init__(self, BUS, MAVmask=16,IfaceReadyMask=2,CMDexecMask=0):
     ASCIIBus.__init__(self, 'gpib', BUS)
     #self.sbr.semafor = GPIB_semafor
     #self.sbr.semafor.acquire()
     print  self.f.vi,':clearing the device buffer...'
     self.clear()
     #self.sbr.semafor.release()
     #self.sbr.MAV = MAVmask    # how to detect the reading was don and response is available
     self.MAVmaks = MAVmask    # sets the message available mask
     self.IfaceReadyMask = IfaceReadyMask    # sets the interface ready mask
     self.CMDexec = CMDexecMask    # command in execution MASK for the status byte
     #self.deviceIBName = deviceIBName
     self.timer = LocalTimerClass()
     return
Пример #3
0
 def __init__(self, deviceIBName, MAVmask=16,IfaceReadyMask=2):
     self.f = Gpib.Gpib(deviceIBName)
     #self.sbr.semafor = GPIB_semafor
     #self.sbr.semafor.acquire()
     print deviceIBName, ':clearing the device buffer...'
     self.clear()
     #self.sbr.semafor.release()
     #self.sbr.MAV = MAVmask    # how to detect the reading was don and response is available
     self.MAVmaks = MAVmask    # sets the message available mask
     self.IfaceReadyMask = IfaceReadyMask    # sets the interface ready mask
     self.CMDexec = 2    # command in execution MASK for the status byte
     self.deviceIBName = deviceIBName
     self.timer = LocalTimerClass()
     return
Пример #4
0
 def __init__(self, type, file_type_interface):
     """ attach the object with read() and write() functions """
     self.f = file_type_interface
     self.type = type
     self.timer = LocalTimerClass()
     self.lastCMDstring = ''    # INITIALIZE the last sent command string value
     return
Пример #5
0
class VISABus:
    "implements general functions of the VISA interface"
    timeout = 5.1  # the commnad issuing and readign timeout

    def __init__(self, VISAresourceName):
        self.timer = LocalTimerClass()
        self.deviceIBName = VISAresourceName
        return

    def write_string(self, message):
        #print self.deviceIBName, ':sending:', message
        #self.sbr.semafor.acquire()
        self.f.write(message)
        self.lastCMDstring = message
        #self.sbr.semafor.release()
        return

    def writelines(self, commandSequenceString):
        for line in commandSequenceString.splitlines():
            self.write_string(line)
        self.lastCMDstring = commandSequenceString
        return

    def read_string_simple(self):
        """ method for old Keithley devices (Electrometer K617) """
        print self.deviceIBName, ":using simple read() method to read form device's buffer...",
        reading = self.f.read()
        print 'DONE!'
        return reading

    def read_string(self, timeout=None):
        """reads the device output buffer
        if it fails, repear the last command and try read again"""
        reading = ''
        if timeout == None:
            timeout = self.timeout
        self.timer.zeroTimer()
        try:
            #self.f.wait_for_srq(timeout)
            reading = self.f.read()
        except:
            #self.sbr.semafor.release()
            print 'read error occurred: clearing the dev buffer..\n ressending the last command'
            try:
                self.f.clear()
            except:
                pass
            self.writelines(self.lastCMDstring)
            reading = self.read_string(
                timeout)  # recurrently call the CMD aggain

        #while timeout > (self.timer.getSinceLastZeroed()):
        #    rsp = ord(self.f.rsp())
        #    #message_available = rsp & self.sbr.MAV
        #    message_available  = rsp & self.MAVmaks
        #    if message_available:
        #        break

        if reading == '':
            reading = '-1e+999'  # this marks error reading
            self.f.clear()  # clear the instrument bus after the problem

        # self.OUTqueue.put(self.reading)
        reading.strip('\n')
        return reading.strip('\n')

    def read_strings(self, number, timeout):
        "reads a given NUMBER of strings"
        response = []  # list of strings in response
        for row in range(number):
            response.append(self.read_string())
        return response

    def read_values(self, timeout=None):
        """reads the device output buffer
        as numerical values - using VISA function"""
        reading = ''
        if timeout == None:
            timeout = self.timeout
        self.timer.zeroTimer()
        try:
            #self.f.wait_for_srq(timeout)
            reading = self.f.read_values()
            #print "reading:", reading
        except:
            #self.sbr.semafor.release()
            print 'read error occurred: clearing the dev buffer..\n ressending the last command'
            self.f.clear()
            self.writelines(self.lastCMDstring)
            reading = self.read_values(
                timeout)  # recurrently call the CMD aggain

        #while timeout > (self.timer.getSinceLastZeroed()):
        #    rsp = ord(self.f.rsp())
        #    #message_available = rsp & self.sbr.MAV
        #    message_available  = rsp & self.MAVmaks
        #    if message_available:
        #        break

        if reading == '':
            reading = '-1e+999'  # this marks error reading
            self.f.clear()  # clear the instrument bus after the problem

        return reading

    def read_floats(self, timeout=None, separators=' '):
        """reads the device output buffer, converts 
        the reading into list of floats"""
        readings = self.read_string(timeout)
        floatList = []
        for reading in readings.split(separators):
            floatList.append(float(reading))
        return floatList

    def ask_for_values(self, command):
        return self.f.ask_for_values(command)

    def clear(self):
        """clears the device buffer"""
        self.f.clear()
        return

    def trigger(self, triggerString=''):
        if triggerString == '':
            self.f.trigger()
        else:
            self.write_string(triggerString)
        return

    def close(self):
        self.f.close()
        return
Пример #6
0
 def __init__(self, VISAresourceName):
     self.timer = LocalTimerClass()
     self.deviceIBName = VISAresourceName
     return
Пример #7
0
class GPIBBus(ASCIIBus):
    #class SBRclass:
    #    "GPIB status byte register"
    #    MAV = 16 # message available - HAS SOME TROUBLES - it is common object to ALL GPIBBus devices
    #    MSS = 32 # Master Summary Status summarizes the ESB and MAV bits.
    #    semafor = None
    lastCMDstring = ''
    #sbr = SBRclass()
    timeout = 0.5 # the commnad issuing and reading timeout
    def __init__(self, BUS, MAVmask=16,IfaceReadyMask=2,CMDexecMask=0):
        ASCIIBus.__init__(self, 'gpib', BUS)
        #self.sbr.semafor = GPIB_semafor
        #self.sbr.semafor.acquire()
        print  self.f.vi,':clearing the device buffer...'
        self.clear()
        #self.sbr.semafor.release()
        #self.sbr.MAV = MAVmask    # how to detect the reading was don and response is available
        self.MAVmaks = MAVmask    # sets the message available mask
        self.IfaceReadyMask = IfaceReadyMask    # sets the interface ready mask
        self.CMDexec = CMDexecMask    # command in execution MASK for the status byte
        #self.deviceIBName = deviceIBName
        self.timer = LocalTimerClass()
        return
    def read_stb(self):
        stb = vpp43.read_stb(self.f.vi)
        return stb
    def write_string(self, message,timeout=None):
        #self.writebuffer.put(str(message))
        #print self.deviceIBName, ':sending:', message
        #self.sbr.semafor.acquire()
        #if not simple:
        # wait for the interface to get ready
        if timeout == None:
            timeout = self.timeout
        self.timer.zeroTimer()
        if self.IfaceReadyMask:
            while timeout > (self.timer.getSinceLastZeroed()):
                rsp = self.read_stb()
                interface_ready  = not (rsp & self.IfaceReadyMask)
                if interface_ready:
                    self.f.write(message)
                    self.lastCMDstring = message
                    break
                else:
                    pass
        else:
            self.f.write(message)
            self.lastCMDstring = message
        #self.sbr.semafor.release()
        return
    def read_string_simple(self):
        """ method for old Keithley devices (Electrometer K617) """
        #print self.deviceIBName,":using simple read() method to read form device's buffer...",
        reading = self.f.read()
        #print 'DONE!'
        return reading
    def read_string(self, timeout=None):
        """reads the device output buffer
        if it fails, repear the last command and try read again"""
        reading = ''
        if timeout == None:
            timeout = self.timeout
        self.timer.zeroTimer()
        while timeout > (self.timer.getSinceLastZeroed()):
            rsp = self.read_stb()
            #message_available = rsp & self.sbr.MAV
            message_available  = rsp & self.MAVmaks
            if message_available:
                break
        while message_available:      
            #self.sbr.semafor.acquire()
            #print self.deviceIBName,":Attempting to read form device's buffer...",
            try:
                reading = reading + self.f.read()
                #print ' DONE!'
                #self.sbr.semafor.release()
                
            except vpp43.VisaIOError:    # repeat the previous command in case of gpib read error
                #self.sbr.semafor.release()
                print 'read error occurred: clearing the dev buffer..%d \n ressending the last command' % self.f.vi
                print self.lastCMDstring
                self.f.clear()
                self.writelines(self.lastCMDstring)
                reading = self.read_string(timeout) # recurrently call the CMD aggain
            rsp = self.read_stb()
            message_available  = rsp & self.MAVmaks
            #message_available = rsp & self.sbr.MAV # works NOT WELL - it is hared between the GPIBBus devices
        if reading=='':
            reading = '-1e+999'    # this marks error reading
            self.clear()    # clear the instrument bus after the problem
        # self.OUTqueue.put(self.reading)
        reading.strip('\n')
        return reading.strip('\n')
    def clear(self):
        """clears the device buffer"""
        self.f.clear()
        return
    def trigger(self, triggerString=''):
        if triggerString == '':
            self.f.trigger()
        else:
            self.write_string(triggerString)
        return
    def ident(self):
        self.Bus.write_string('*IDN?')
        self.timer.Wait(0.2)
        return self.read_string()
    def read_bin_floats(self,timeout=None):
        defaultTimeout = self.f.timeout
        if timeout != None:
            self.f.timeout = timeout
        list_of_floats = self.f.read_values(visa.single)
        if timeout != None:
            self.f.timeout = defaultTimeout
        return list_of_floats
    def close(self):
        self.clear()
        return
Пример #8
0
class TestScript:
    """
    this define sthe generic properties of the script
    """
    def __init__(self):
        self.timer = LocalTimerClass()
        self._parameters = {}
        self.Name = 'General description of script'
        self.Description = """ Does nothing """
        self.init_parameters()
        self.devList = ListOfDevices()
        self.inExecution = False
        self.inTermination = False
        #self.executionThread =
        return

    def _run(self):
        """
        actual test script
        override this method with actual script
        """
        raise NotImplementedError

    def init_datastore(self, filename):
        self.datastore = OutputHandler(self.devList.list())
        self.datastore.setDataFileName(filename)
        self.dataFileName = filename
        return

    def terminate(self):
        self.inTermination = True
        return

    def get_datastore(self):
        """
        returns the datastore of the script
        """
        return self.datastore

    def get_parameter_list(self):
        """
        returns a list of parameters with their properties 
        """
        list_of_parameters = []
        for key in self._parameters.keys():
            list_of_parameters.append(self._parameters[key])
        return list_of_parameters

    def set_parameter_value(self, Name, Value):
        response = self._parameters[Name].setValue(Value)
        return response

    def get_parameter_value(self, Name):
        Value = None
        if Name in self._parameters.keys():
            Value = self._parameters[Name].getValue()
        return Value

    def get_active_devices_list(self):
        return self.devList.list()

    def append_active_devices_list(self, device):
        device.setActive(True)
        self.devList.append(device)

    def get_data_header(self):
        datagramKeys = self.datastore.datagram.extract_header()
        return datagramKeys

    def generate_parameter(self,
                           Name='NoParameter',
                           Unit='Arb.U.',
                           Type=None,
                           Iterable=None,
                           Limits=[None, None, None],
                           Description='self explanatory'):
        """
        creates the object with parameter properties
        Name
        Unit
        Type
        Value
        Limits
        Description
        """
        parameter = GeneralParameter(Name, Unit, Type, Iterable, Limits,
                                     Description)
        # copy the parameter to a structure containing all parameters
        # under the same name
        self._parameters[Name] = parameter
        #print parameter.values['Name']
        return parameter

    def init_parameters(self):
        """
        inits the input parameters edited before starting the test
        override this method with actual script
        """
        raise NotImplementedError

    def init_devices(self):
        """
        inits the devices edited before starting the test
        override this method with actual script
        is should return the list of active devices
        """
        raise NotImplementedError

    def initExecution(self, filenamePath):
        """
        preparation for running the test
        """
        print('Init devices')
        self.init_devices()
        print('Init data file')
        self.init_datastore(filenamePath)
        (dirname, filename) = os.path.split(filenamePath)

        self.datastore.report( ('STARTING: %(script)s, dataFile: %(filename)s' % \
                            {'script':self.get_Name(), "filename":filename}) )
        return

    def Execute(self):

        self._run()
        (dirname, filename) = os.path.split(self.dataFileName)
        self.datastore.report( ('FINISHED: %(script)s, dataFile: %(filename)s' % \
                            {'script':self.get_Name(), "filename":filename}) )
        self.close_devices()
        return

    def observe(self, duration, delay=0.5):
        """general repeating data acquisition cycle"""
        self.timer.zeroTimer()
        while self.timer.getSinceLastZeroed(
        ) < duration:  # observe the temperature variables for about 5 min, wait for the Temp to stabilize
            self.timer.Wait(delay)
            for device in self.get_active_devices_list():
                device.Measure()
                # check if we are isntructed to terminate:
                if self.inTermination:
                    raise JobTerminationException
            self.datastore.acquireData()

    def close_devices(self):
        for device in self.get_active_devices_list():
            #self.datastore.report('closing device...%s' %str(device))
            device.Close()

    def get_Name(self):
        """
        just returns some descriptive string
        """
        return self.Name

    def get_Description(self):
        """
        just returns some descriptive string
        """
        return self.Description

    def generate_script_description_text(self):
        #collumn = event.GetColumn()
        scriptName = self.get_Name()
        scriptDescribe = self.get_Description()
        Parameters = self.get_parameter_list()
        #paramDescribe = ''
        paramDescRows = [[scriptName], [scriptDescribe]]
        paramDescRows.append(["Parameters:"])
        for param in Parameters:
            parName = param.getName()
            parValue = param.getValue()
            parUnit = param.getUnit()
            parDesc = param.getDescription()
            paramRow = [
                str(parName),
                str(parValue),
                str(parUnit),
                str(parDesc)
            ]
            paramDescRows.append(paramRow)
            #paramDescribe = param.getName() + param
        return paramDescRows