{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example of Fake Instrument\n",
    "When an instrument is loaded but it can be found the class moves to a fake instrument mode that logs write and read commands"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Importing pyMez, this should take roughly 30 seconds\n",
      "Importing Code.DataHandlers.GeneralModels\n",
      "It took 0.497028 s to import Code.DataHandlers.GeneralModels\n",
      "Importing Code.DataHandlers.HTMLModels\n",
      "It took 0.155009 s to import Code.DataHandlers.HTMLModels\n",
      "Importing Code.DataHandlers.NISTModels\n",
      "The module smithplot was not found,please put it on the python path\n",
      "It took 0.685039 s to import Code.DataHandlers.NISTModels\n",
      "Importing Code.DataHandlers.TouchstoneModels\n",
      "It took 0.002 s to import Code.DataHandlers.TouchstoneModels\n",
      "Importing Code.DataHandlers.XMLModels\n",
      "It took 0.077005 s to import Code.DataHandlers.XMLModels\n",
      "Importing Code.DataHandlers.ZipModels\n",
      "It took 0.008 s to import Code.DataHandlers.ZipModels\n",
      "Importing Code.InstrumentControl.Experiments\n",
      "It took 3.010172 s to import Code.InstrumentControl.Experiments\n",
      "Importing Code.InstrumentControl.Instruments\n",
      "It took 0.001 s to import Code.InstrumentControl.Instruments\n",
      "Importing Code.Utils.Names\n",
      "It took 0.0 s to import Code.Utils.Names\n",
      "It took 4.437253 s to import all of the active modules\n"
     ]
    }
   ],
   "source": [
    "from pyMez import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unable to load resource entering fake mode ...\n"
     ]
    }
   ],
   "source": [
    "# This loads the sheet that has GPIB::16 address\n",
    "fake_instrument=VisaInstrument(\"GPIB::16\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Agilent Technologies,E8361A,US43140754,A.07.50.67'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This is the idn established on the xml description sheet\n",
    "fake_instrument.idn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'SENS:BAND': 'Buffer Read at 2018-11-07T06:38:03.896646',\n",
       " 'SENS:AVER': 'Buffer Read at 2018-11-07T06:38:03.897646',\n",
       " 'SOUR:POW:SLOP': 'Buffer Read at 2018-11-07T06:38:03.898646',\n",
       " 'SOUR:POW': 'Buffer Read at 2018-11-07T06:38:03.899647',\n",
       " 'SOUR:POW:CORR:STAT': 'Buffer Read at 2018-11-07T06:38:03.900647',\n",
       " 'SENS:CORR:STAT': 'Buffer Read at 2018-11-07T06:38:03.901647',\n",
       " 'SENS:SWE:TYPE': 'Buffer Read at 2018-11-07T06:38:03.903647'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This gets the default state defined in the xml sheet\n",
    "# instead of returning values it returns a buffer read and time stamp\n",
    "fake_instrument.get_state()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This is a fake write command\n",
    "fake_instrument.write(\"MyFake:GPIB:COMMAND\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'Timestamp': '2018-11-07T06:38:03.778640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:BAND?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.778640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.778640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.779640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:AVER?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.779640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.779640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.780640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:SLOP?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.780640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.780640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.781640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.781640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.781640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.782640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.782640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.782640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.783640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.783640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.783640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.784640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:SWE:TYPE?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.784640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.784640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.785640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:BAND?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.785640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.785640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.786640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:AVER?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.786640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.786640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.787640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:SLOP?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.787640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.787640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.788640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.788640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.788640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.789640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.789640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.789640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.790640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.790640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.790640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.791640',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:SWE:TYPE?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.791640',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.791640'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.896646',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:BAND?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.896646',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.896646'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.897646',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:AVER?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.897646',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.897646'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.898646',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:SLOP?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.898646',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.898646'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.899647',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.899647',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.899647'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.900647',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SOUR:POW:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.900647',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.900647'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.901647',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:CORR:STAT?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.901647',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.901647'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.903647',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'SENS:SWE:TYPE?',\n",
       "  'Response': None},\n",
       " {'Timestamp': '2018-11-07T06:38:03.903647',\n",
       "  'Action': 'self.read',\n",
       "  'Argument': None,\n",
       "  'Response': 'Buffer Read at 2018-11-07T06:38:03.903647'},\n",
       " {'Timestamp': '2018-11-07T06:38:03.961650',\n",
       "  'Action': 'self.write',\n",
       "  'Argument': 'MyFake:GPIB:COMMAND',\n",
       "  'Response': None}]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The history attribute saves a log of all communication\n",
    "fake_instrument.history"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the fake mode attribute is set to true so that derived classes can integrate it\n",
    "fake_instrument.fake_mode"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
