Fake_Instrument_Control_Example

# Example of Fake Instrument¶

When an instrument is loaded but it can be found the class moves to a fake instrument mode that logs write and read commands

In [1]:

    from pyMez import *

    Importing pyMez, this should take roughly 30 seconds
    Importing Code.DataHandlers.GeneralModels
    It took 0.497028 s to import Code.DataHandlers.GeneralModels
    Importing Code.DataHandlers.HTMLModels
    It took 0.155009 s to import Code.DataHandlers.HTMLModels
    Importing Code.DataHandlers.NISTModels
    The module smithplot was not found,please put it on the python path
    It took 0.685039 s to import Code.DataHandlers.NISTModels
    Importing Code.DataHandlers.TouchstoneModels
    It took 0.002 s to import Code.DataHandlers.TouchstoneModels
    Importing Code.DataHandlers.XMLModels
    It took 0.077005 s to import Code.DataHandlers.XMLModels
    Importing Code.DataHandlers.ZipModels
    It took 0.008 s to import Code.DataHandlers.ZipModels
    Importing Code.InstrumentControl.Experiments
    It took 3.010172 s to import Code.InstrumentControl.Experiments
    Importing Code.InstrumentControl.Instruments
    It took 0.001 s to import Code.InstrumentControl.Instruments
    Importing Code.Utils.Names
    It took 0.0 s to import Code.Utils.Names
    It took 4.437253 s to import all of the active modules

In [2]:

    # This loads the sheet that has GPIB::16 address
    fake_instrument=VisaInstrument("GPIB::16")

    Unable to load resource entering fake mode ...

In [3]:

    # This is the idn established on the xml description sheet
    fake_instrument.idn

Out[3]:

    'Agilent Technologies,E8361A,US43140754,A.07.50.67'

In [4]:

    # This gets the default state defined in the xml sheet
    # instead of returning values it returns a buffer read and time stamp
    fake_instrument.get_state()

Out[4]:

    {'SENS:BAND': 'Buffer Read at 2018-11-07T06:38:03.896646',
     'SENS:AVER': 'Buffer Read at 2018-11-07T06:38:03.897646',
     'SOUR:POW:SLOP': 'Buffer Read at 2018-11-07T06:38:03.898646',
     'SOUR:POW': 'Buffer Read at 2018-11-07T06:38:03.899647',
     'SOUR:POW:CORR:STAT': 'Buffer Read at 2018-11-07T06:38:03.900647',
     'SENS:CORR:STAT': 'Buffer Read at 2018-11-07T06:38:03.901647',
     'SENS:SWE:TYPE': 'Buffer Read at 2018-11-07T06:38:03.903647'}

In [5]:

    # This is a fake write command
    fake_instrument.write("MyFake:GPIB:COMMAND")

In [6]:

    # The history attribute saves a log of all communication
    fake_instrument.history

Out[6]:

    [{'Timestamp': '2018-11-07T06:38:03.778640',
      'Action': 'self.write',
      'Argument': 'SENS:BAND?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.778640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.778640'},
     {'Timestamp': '2018-11-07T06:38:03.779640',
      'Action': 'self.write',
      'Argument': 'SENS:AVER?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.779640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.779640'},
     {'Timestamp': '2018-11-07T06:38:03.780640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:SLOP?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.780640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.780640'},
     {'Timestamp': '2018-11-07T06:38:03.781640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.781640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.781640'},
     {'Timestamp': '2018-11-07T06:38:03.782640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.782640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.782640'},
     {'Timestamp': '2018-11-07T06:38:03.783640',
      'Action': 'self.write',
      'Argument': 'SENS:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.783640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.783640'},
     {'Timestamp': '2018-11-07T06:38:03.784640',
      'Action': 'self.write',
      'Argument': 'SENS:SWE:TYPE?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.784640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.784640'},
     {'Timestamp': '2018-11-07T06:38:03.785640',
      'Action': 'self.write',
      'Argument': 'SENS:BAND?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.785640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.785640'},
     {'Timestamp': '2018-11-07T06:38:03.786640',
      'Action': 'self.write',
      'Argument': 'SENS:AVER?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.786640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.786640'},
     {'Timestamp': '2018-11-07T06:38:03.787640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:SLOP?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.787640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.787640'},
     {'Timestamp': '2018-11-07T06:38:03.788640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.788640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.788640'},
     {'Timestamp': '2018-11-07T06:38:03.789640',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.789640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.789640'},
     {'Timestamp': '2018-11-07T06:38:03.790640',
      'Action': 'self.write',
      'Argument': 'SENS:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.790640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.790640'},
     {'Timestamp': '2018-11-07T06:38:03.791640',
      'Action': 'self.write',
      'Argument': 'SENS:SWE:TYPE?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.791640',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.791640'},
     {'Timestamp': '2018-11-07T06:38:03.896646',
      'Action': 'self.write',
      'Argument': 'SENS:BAND?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.896646',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.896646'},
     {'Timestamp': '2018-11-07T06:38:03.897646',
      'Action': 'self.write',
      'Argument': 'SENS:AVER?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.897646',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.897646'},
     {'Timestamp': '2018-11-07T06:38:03.898646',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:SLOP?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.898646',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.898646'},
     {'Timestamp': '2018-11-07T06:38:03.899647',
      'Action': 'self.write',
      'Argument': 'SOUR:POW?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.899647',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.899647'},
     {'Timestamp': '2018-11-07T06:38:03.900647',
      'Action': 'self.write',
      'Argument': 'SOUR:POW:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.900647',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.900647'},
     {'Timestamp': '2018-11-07T06:38:03.901647',
      'Action': 'self.write',
      'Argument': 'SENS:CORR:STAT?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.901647',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.901647'},
     {'Timestamp': '2018-11-07T06:38:03.903647',
      'Action': 'self.write',
      'Argument': 'SENS:SWE:TYPE?',
      'Response': None},
     {'Timestamp': '2018-11-07T06:38:03.903647',
      'Action': 'self.read',
      'Argument': None,
      'Response': 'Buffer Read at 2018-11-07T06:38:03.903647'},
     {'Timestamp': '2018-11-07T06:38:03.961650',
      'Action': 'self.write',
      'Argument': 'MyFake:GPIB:COMMAND',
      'Response': None}]

In [7]:

    # the fake mode attribute is set to true so that derived classes can integrate it
    fake_instrument.fake_mode

Out[7]:

    True