
#metadef
#idString AGILENT,U1211A,
#name Keysight U1211A
#handle K1211

#metadef
#idString AGILENT,U1212A,
#name Keysight U1212A
#handle K1212

#metadef
#idString AGILENT,U1213A,
#name Keysight U1213A
#handle K1213

#meta
#idString AGILENT,U1213A,
#name Keysight U1213A
#handle K1213

#port com
#driver KeysightDMM
#baudrate 9600
#author WS

#notes Added configuration for measurement ranges
Restrictions: 
- 2nd Function measurement (frequency) for voltage and current measurement not implemented

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
#value DC_Current A si CURR
#value AC_Current A si CURR:AC
#value AC+DC_Current A si CURR:ACDC
#value DC_Voltage V d5 VOLT,DIOD
#value AC_Voltage V d4 VOLT:AC
#value AC+DC_Voltage V d4 VOLT:ACDC
#value Resistance ohm si RES
#value Continuity ohm si CONT
#value Capacity F si CAP
#value Temperature °C d1 TEMP:K,TEMP:J
#value Frequency Hz si FREQDC,FREQAC
#value Period s si PWIDDC,PWIDAC
#value DutyCycle % D2 DUTYDC,DUTYAC,PULS:PDUT
#value Conductance S SI nS

; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; This is a single line command
#askValues FETC?

; String to ask about actual meter mode, 
; This is a single line command
#askMode CONF?
#askModeMathFormat getElement(unQuote(value),0," ");

#interfaceType DMM
#interface readValue 0

;Mode-------------------------------------------------------------------------------------------
#cmdSetup info Active_Mode
:read: CONF?
:readmath: getElement("DC_Voltage;AC_Voltage;AC+DC_Voltage;Resistance;DC_Current;AC_Current;AC+DC_Current;Diode;Continuity;Frequency;Frequency;Capacity;Temperature;Temperature;Temperature",listIndex(getElement(unQuote(value),0," "),"VOLT VOLT:AC VOLT:ACDC RES CURR CURR:AC CURR:ACDC DIOD CONT FREQDC FREQAC CAP TEMP:K TEMP:J TEMP"," "),";")
:updatemodechange:

; Strings to configure device in different modes, using these forces a mode check/change
; When used to select mode first parameter must match a #value (4 parameter) and second parameter must match what #askMode returns
; It can also be used for just checking the mode, then the #value (4 parameter) must match what #askMode returns
; First parameter is also used in shortcut menu
#cmdMode Check_mode _ _

; ------------------------------------- Volt DC -----------------------------------------------------------
#cmdSetup button Auto_Range DC_Voltage
:write: CONF:VOLT:DC
:updatedelayed: 1
:update: Actual_Range DC_Voltage;Auto DC_Voltage

#cmdSetup info Auto DC_Voltage
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range DC_Voltage
:read: CONF?
:readmath: getElement("4V;40V;400V;1000V",listIndex(getElement(unQuote(value),1," "),"+4.000000E+00,+1.000000E-03;+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_4V DC_Voltage
:write: CONF:VOLT:DC 4
:updatedelayed: 0.5
:update: Actual_Range DC_Voltage;Auto DC_Voltage

#cmdSetup button Range_40V DC_Voltage
:write: CONF:VOLT:DC 40
:updatedelayed: 0.5
:update: Actual_Range DC_Voltage;Auto DC_Voltage

#cmdSetup button Range_400V DC_Voltage
:write: CONF:VOLT:DC 400
:updatedelayed: 0.5
:update: Actual_Range DC_Voltage;Auto DC_Voltage

#cmdSetup button Range_1000V DC_Voltage
:write: CONF:VOLT:DC 1000
:updatedelayed: 0.5
:update: Actual_Range DC_Voltage;Auto DC_Voltage

; ------------------------------------- Volt AC -----------------------------------------------------------
#cmdSetup button Auto_Range AC_Voltage
:write: CONF:VOLT:AC
:updatedelayed: 0.5
:update: Actual_Range AC_Voltage;info Auto AC_Voltage

#cmdSetup info Auto AC_Voltage
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range AC_Voltage
:read: CONF?
:readmath: getElement("4V;40V;400V;1000V",listIndex(getElement(unQuote(value),1," "),"+4.000000E+00,+1.000000E-03;+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_4V AC_Voltage
:write: CONF:VOLT:AC 4
:updatedelayed: 0.5
:update: Actual_Range AC_Voltage;info Auto AC_Voltage

#cmdSetup button Range_40V AC_Voltage
:write: CONF:VOLT:AC 40
:updatedelayed: 0.5
:update: Actual_Range AC_Voltage;info Auto AC_Voltage

#cmdSetup button Range_400V AC_Voltage
:write: CONF:VOLT:AC 400
:updatedelayed: 0.5
:update: Actual_Range AC_Voltage;info Auto AC_Voltage

#cmdSetup button Range_1000V AC_Voltage
:write: CONF:VOLT:AC 1000
:updatedelayed: 0.5
:update: Actual_Range AC_Voltage;info Auto AC_Voltage

; ------------------------------------- Volt AC+DC -----------------------------------------------------------
#cmdSetup button Auto_Range AC+DC_Voltage
:write: CONF:VOLT:ACDC
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Voltage;Auto AC+DC_Voltage

#cmdSetup info Auto AC+DC_Voltage
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range AC+DC_Voltage
:read: CONF?
:readmath: getElement("4V;40V;400V;1000V",listIndex(getElement(unQuote(value),1," "),"+4.000000E+00,+1.000000E-03;+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_4V AC+DC_Voltage
:write: CONF:VOLT:ACDC 4
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Voltage;Auto AC+DC_Voltage

#cmdSetup button Range_40V AC+DC_Voltage
:write: CONF:VOLT:ACDC 40
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Voltage;Auto AC+DC_Voltage

#cmdSetup button Range_400V AC+DC_Voltage
:write: CONF:VOLT:ACDC 400
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Voltage;Auto AC+DC_Voltage

#cmdSetup button Range_1000V AC+DC_Voltage
:write: CONF:VOLT:ACDC 1000
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Voltage;Auto AC+DC_Voltage

; ------------------------------------- Current DC -----------------------------------------------------------
#cmdSetup button Auto_Range DC_Current
:write: CONF:CURR:DC
:updatedelayed: 0.5
:update: Actual_Range DC_Current;Auto DC_Current

#cmdSetup info Auto DC_Current
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range DC_Current
:read: CONF?
:readmath: getElement("40A;400A;1000A",listIndex(getElement(unQuote(value),1," "),"+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_40A DC_Current
:write: CONF:CURR:DC 40
:updatedelayed: 0.5
:update: Actual_Range DC_Current;Auto DC_Current

#cmdSetup button Range_400A DC_Current
:write: CONF:CURR:DC 400
:updatedelayed: 0.5
:update: Actual_Range DC_Current;Auto DC_Current

#cmdSetup button Range_1000A DC_Current
:write: CONF:CURR:DC 1000
:updatedelayed: 0.5
:update: Actual_Range DC_Current;Auto DC_Current

; ------------------------------------- Current AC -----------------------------------------------------------
#cmdSetup button Auto_Range AC_Current
:write: CONF:CURR:AC
:updatedelayed: 0.5
:update: Actual_Range AC_Current;Auto AC_Current

#cmdSetup info Auto AC_Current
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range AC_Current
:read: CONF?
:readmath: getElement("40A;400A;1000A",listIndex(getElement(unQuote(value),1," "),"+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_40A AC_Current
:write: CONF:CURR:AC 40
:updatedelayed: 0.5
:update: Actual_Range AC_Current;Auto AC_Current

#cmdSetup button Range_400A AC_Current
:write: CONF:CURR:AC 400
:updatedelayed: 0.5
:update: Actual_Range AC_Current;Auto AC_Current

#cmdSetup button Range_1000A AC_Current
:write: CONF:CURR:AC 1000
:updatedelayed: 0.5
:update: Actual_Range AC_Current;Auto AC_Current

; ------------------------------------- Current AC+DC -----------------------------------------------------------
#cmdSetup button Auto_Range AC+DC_Current
:write: CONF:CURR:ACDC
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Current;Auto AC+DC_Current

#cmdSetup info Auto AC+DC_Current
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range AC+DC_Current
:read: CONF?
:readmath: getElement("40A;400A;1000A",listIndex(getElement(unQuote(value),1," "),"+4.000000E+01,+1.000000E-02;+4.000000E+02,+1.000000E-01;+1.000000E+03,+1.000000E+00",";"),";")

#cmdSetup button Range_40A AC+DC_Current
:write: CONF:CURR:ACDC 40
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Current;Auto AC+DC_Current

#cmdSetup button Range_400A AC+DC_Current
:write: CONF:CURR:ACDC 400
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Current;Auto AC+DC_Current

#cmdSetup button Range_1000A AC+DC_Current
:write: CONF:CURR:ACDC 1000
:updatedelayed: 0.5
:update: Actual_Range AC+DC_Current;Auto AC+DC_Current

; ------------------------------------- Resistance -----------------------------------------------------------
#cmdSetup button Auto_Range Resistance
:write: CONF:RES
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup info Auto Resistance
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range Resistance
:read: CONF?
:readmath: getElement("400Ohm;4kOhm;40kOhm;400kOhm;4MOhm;40MOhm",listIndex(getElement(unQuote(value),1," "),"+4.000000E+02,+1.000000E-01;+4.000000E+03,+1.000000E+00;+4.000000E+04,+1.000000E+01;+4.000000E+05,+1.000000E+02;+4.000000E+06,+1.000000E+03;+4.000000E+07,+1.000000E+04",";"),";")

#cmdSetup button Range_400Ohm Resistance
:write: CONF:RES 400
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup button Range_4kOhm Resistance
:write: CONF:RES 4k
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup button Range_40kOhm Resistance
:write: CONF:RES 40k
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup button Range_400kOhm Resistance
:write: CONF:RES 400k
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup button Range_4MOhm Resistance
:write: CONF:RES 4M
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

#cmdSetup button Range_40MOhm Resistance
:write: CONF:RES 40M
:updatedelayed: 0.5
:update: Actual_Range Resistance;Auto Resistance

; ------------------------------------- Continuity -----------------------------------------------------------
#cmdSetup button Auto_Range Continuity
:write: CONF:RES
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup info Auto Continuity
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range Continuity
:read: CONF?
:readmath: getElement("400Ohm;4kOhm;40kOhm;400kOhm;4MOhm;40MOhm",listIndex(getElement(unQuote(value),1," "),"+4.000000E+02,+1.000000E-01;+4.000000E+03,+1.000000E+00;+4.000000E+04,+1.000000E+01;+4.000000E+05,+1.000000E+02;+4.000000E+06,+1.000000E+03;+4.000000E+07,+1.000000E+04",";"),";")

#cmdSetup button Range_400Ohm Continuity
:write: CONF:RES 400
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup button Range_4kOhm Continuity
:write: CONF:RES 4k
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup button Range_40kOhm Continuity
:write: CONF:RES 40k
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup button Range_400kOhm Continuity
:write: CONF:RES 400k
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup button Range_4MOhm Continuity
:write: CONF:RES 4M
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

#cmdSetup button Range_40MOhm Continuity
:write: CONF:RES 40M
:updatedelayed: 0.5
:update: Actual_Range Continuity;Auto Continuity

; ------------------------------------- Capacity -----------------------------------------------------------
#cmdSetup button Auto_Range Capacity
:write: CONF:CAP
:updatedelayed: 0.5
:update: Actual_Range Capacity;Auto Capacity

#cmdSetup info Auto Capacity
:read: STAT?
:readmath: getElement("Off;On",listIndex(substring(unQuote(value),20,21),"0;1",";"),";")

#cmdSetup info Actual_Range Capacity
:read: CONF?
:readmath: getElement("4uF;40uF;400uF;4000uF",listIndex(getElement(unQuote(value),1," "),"+4.000000E-06,+1.000000E-09;+4.000000E-05,+1.000000E-08;+4.000000E-04,+1.000000E-07;+4.000000E-03,+1.000000E-06",";"),";")

#cmdSetup button Range_4uF Capacity
:write: CONF:CAP 4u
:updatedelayed: 0.5
:update: Actual_Range Capacity;Auto Capacity

#cmdSetup button Range_40uF Capacity
:write: CONF:CAP 40u
:updatedelayed: 0.5
:update: Actual_Range Capacity;Auto Capacity

#cmdSetup button Range_400uF Capacity
:write: CONF:CAP 400u
:updatedelayed: 0.5
:update: Actual_Range Capacity;Auto Capacity

#cmdSetup button Range_4000uF Capacity
:write: CONF:CAP 4000u
:updatedelayed: 0.5
:update: Actual_Range Capacity;Auto Capacity

; -----------------------------------------------------------------------------------------------------------
#cmdSetup selector Mode_settings 
:read: CONF?
:readmath: getElement(unQuote(value),0," ")
:updatemodechange:
VOLT DC_Voltage.
VOLT:AC AC_Voltage.
VOLT:ACDC AC+DC_Voltage.
CURR DC_Current.
CURR:AC AC_Current.
CURR:ACDC AC+DC_Current.
DIOD Diode.
CAP Capacity.
FREQDC Frequency.
FREQAC Frequency.
RES Resistance.
CONT Continuity.
PER Period.
TEMP:K Temperature.
TEMP:J Temperature.
TEMP Temperature.
PULS:PDUT DutyCycle.
