#metadef
#name Agilent 34401A
#remove #cmdMode Temperature

#metadef
#name Hewlett-Packard 34401A
#remove #cmdMode Temperature

#metadef
#name Hewlett-Packard 34401A Enhanced
#handle HP34401A

#metadef
#name Agilent 34401A Enhanced
#handle HP34401A


#meta
#author maukka 
#idString HEWLETT-PACKARD,34401A,
#name HP/Agilent 34401A Enhanced
#handle HP34401A
#port com gpib
#baudrate 9600N82H
#driver SCPIx

#notes The baud rate setting must match the meters setting, this also include parity/bits: 
always two parity bits, DTR / DSR handshake
WA: added configururation for Measurement functions, correct baudrate setting: 2 stoppbits DTR / DSR handshake
The meter must not be set at address 31, it has special meaning.
The "Enhanced" model are done by enabling hidden features of 34401A FW 07-xx-yy and later. See https://www.eevblog.com/forum/testgear/hp-agilent-34401a-hidden-menu/ for details

 
; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
#value VoltageDC V D6 DC_Voltage,Diode
#value CurrentDC A si DC_Current
#value VoltageAC V D6 AC_Voltage
#value CurrentAC A si AC_Current
#value Resistance ohm si 2W_Resistance,4W_Resistance,Continuity
#value Frequency Hz si Frequency
#value Ratio - d3 Ratio
#value Period s d6 Period
#value Temperature °C d3 Temperature
 
; 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 READ?
 
 
; When it gets extra measurements they will be put into the log window.
; It may be due to a timeout on reading the data or because it receives two lines of data.
; You can change the timeout with (Default is 1 second)
#readingDelay 10
#modeChangeDelay 10
  
; String to ask about actual meter mode,
; This is a single line command
#askMode FUNC?
 
 
; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
; #mayModifyMode

; Prepare the meter to response to #askValues
#prepareSample

#scpiCmd SerialInit #pgm#
if (portType!="GPIB")
  deviceWrite(handle,"SYST:REM;[500]");
endif;

; Initial commands to meter when establishing connection
#initCmd SerialInit;

#scpiCmd SerialExit #pgm#
if (portType!="GPIB")
  deviceWrite(handle,"system:local");
endif;

; Final command to meter before breaking connection
#finalCmd SerialExit;
 
#interfaceType DMM BMM
#interface readValue 0
 
#cmdModeLayout 3 4
 
#cmdMode DC_Voltage VOLT
CONF:VOLT:DC;[500]

#cmdMode AC_Voltage VOLT:AC
CONF:VOLT:AC;[500]
 
#cmdMode 2W_Resistance RES
CONF:RES;[500]

#cmdMode DC_Current CURR
CONF:CURR:DC;[500]
 
#cmdMode AC_Current CURR:AC
CONF:CURR:AC;[500]
 
#cmdMode 4W_Resistance FRES
CONF:FRES;[500]
 
#cmdMode Diode DIOD
CONF:DIOD;[500]
 
#cmdMode Continuity CONT
CONF:CONT;[500]
 
#cmdMode Frequency FREQ
CONF:FREQ;[500]
 
#cmdMode Period PER
CONF:PER;[500]

#cmdMode Ratio VOLT:RAT
CONF:VOLT:DC:RAT;[500]

#cmdMode Temperature TEMP
CONF:TEMP;[500]
 
;Mode-------------------------------------------------------------------------------------------
#cmdSetup info Active_Mode
:read: FUNC?
:readmath: getElement("DC Voltage;AC Voltage;2W_Resistance;DC Current;AC Current;4W_Resistance;Diode;Continuity;Frequency;Period;Ratio;Temperature",listIndex(unQuote(value),"VOLT VOLT:AC RES CURR CURR:AC FRES DIOD CONT FREQ PER VOLT:RAT TEMP"," "),";")
:updatemodechange:
 
 ; ------------------------------------- Volt DC -----------------------------------------------------------
#cmdSetup radio Range_Auto DC_Voltage
:read: VOLT:DC:RANG:AUTO?
:write: VOLT:DC:RANG:AUTO #;[500]
:updatedelayed: 0.5
:update: Range DC_Voltage
Auto 1
Manual 0
:updatemodechange:

#cmdSetup radio Range DC_Voltage
:write: VOLT:DC:RANG #;[500]
:read: VOLT:DC:RANG?
:updatedelayed: 0.5
:update: Range_Auto DC_Voltage
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000
:updatemodechange:

#cmdSetup radio Auto_Zero DC_Voltage
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
:updatedelayed: 1
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio Input_impedance_Auto DC_Voltage
:write: INP:IMP:AUTO #;[500]
:read: INP:IMP:AUTO?
Off 0
On 1
:updatemodechange:

#cmdSetup radio NPLCycles DC_Voltage
:write: VOLT:DC:NPLC #;[500]
:read: VOLT:DC:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

; ------------------------------------- Volt AC -----------------------------------------------------------
#cmdSetup radio Range_Auto AC_Voltage
:write: VOLT:AC:RANG:AUTO #;[500]
:read: VOLT:AC:RANG:AUTO?
:updatedelayed: 0.5
:update: Range AC_Voltage
Auto 1
Manual 0
:updatemodechange:

#cmdSetup radio Range AC_Voltage
:write: VOLT:AC:RANG #;[500]
:read: VOLT:AC:RANG?
:updatedelayed: 0.5
:update: Range_Auto AC_Voltage
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000
:updatemodechange:

#cmdSetup radio AC_Filter AC_Voltage
:write: DET:BAND #;[500]
:read: DET:BAND?
>3Hz 3
>20Hz 20
>200Hz 200
:updatemodechange:

#cmdSetup radio Auto_Zero AC_Voltage
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
:updatedelayed: 1
Off 0
On 1
Once ONCE
:updatemodechange:

;2W_Resistance----------------------------------------------------------------------------------
#cmdSetup radio Range 2W_Resistance
:read: RES:RANG:AUTO?
:write: RES:RANG:AUTO #;[500]
:updatedelayed: 0.5
:update: Range 2W_Resistance
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range 2W_Resistance
:write: RES:RANGE #;[500]
:read: RES:RANGE?
:updatedelayed: 0.5
:update: Range_Auto 2W_Resistance
100Ohm 100
1kOhm 1000
10kOhm 10000
100kOhm 100000
1MOhm 1000000
10MOhm 10000000
100MOhm 100000000
:updatemodechange:

#cmdSetup radio Auto_Zero 2W_Resistance
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio NPLCycles 2W_Resistance
:write: RES:NPLC #;[500]
:read: RES:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

;4W_Resistance----------------------------------------------------------------------------------
#cmdSetup radio Range 4W_Resistance
:read: FRES:RANG:AUTO?
:write: FRES:RANG:AUTO #;[500]
:updatedelayed: 0.5
:update: Range 4W_Resistance
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range 4W_Resistance
:write: FRES:RANGE #;[500]
:read: FRES:RANGE?
:updatedelayed: 0.5
:update: Range_Auto 4W_Resistance
100Ohm 100
1kOhm 1000
10kOhm 10000
100kOhm 100000
1MOhm 1000000
10MOhm 10000000
100MOhm 100000000
:updatemodechange:

#cmdSetup radio Auto_Zero 4W_Resistance
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio NPLCycles 4W_Resistance
:write: FRES:NPLC #;[500]
:read: FRES:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

;DC_Current-------------------------------------------------------------------------------------
#cmdSetup radio Range DC_Current
:write: CURR:DC:RANG:AUTO #;[500]
:read: CURR:DC:RANG:AUTO?
:updatedelayed: 0.5
:update: Range DC_Current
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range DC_Current
:write: CURR:DC:RANG #;[500]
:read: CURR:DC:RANG?
:updatedelayed: 0.5
:update: Range_Auto DC_Current
10mA 0.01
100mA 0.1
1A 1
3A 3
:updatemodechange:

#cmdSetup radio Auto_Zero DC_Current
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio NPLCycles DC_Current
:write: CURR:DC:NPLC #;[500]
:read: CURR:DC:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

;AC_Current-------------------------------------------------------------------------------------
#cmdSetup radio Range AC_Current
:write: CURR:AC:RANG:AUTO #;[500]
:read: CURR:AC:RANG:AUTO?
:updatedelayed: 0.5
:update: Range AC_Current
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range AC_Current
:write: CURR:AC:RANG #;[500]
:read: CURR:AC:RANG?
:updatedelayed: 0.5
:update: Range_Auto AC_Current
1A 1
3A 3
:updatemodechange:

#cmdSetup radio AC_Filter AC_Current
:write: DET:BAND #;[500]
:read: DET:BAND?
:readFormat: u
>3Hz 3
>20Hz 20
>200Hz 200
:updatemodechange:

#cmdSetup radio Auto_Zero AC_Current
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
Off 0
On 1
Once ONCE
:updatemodechange:

;Continuity------------------------------------------------------------------------------------------
#cmdSetup radio Beeper Continuity
:write: SYST:BEEP:STAT #;[500]
:read: SYST:BEEP:STAT?
Off 0
On 1
:updatemodechange:

;Frequency--------------------------------------------------------------------------------------
#cmdSetup radio Range Frequency
:write: FREQ:VOLT:RANG:AUTO #;[500]
:read: FREQ:VOLT:RANG:AUTO?
:updatedelayed: 0.5
:update: Range Frequency
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range Frequency
:write: FREQ:VOLT:RANG #;[500]
:read: FREQ:VOLT:RANG?
:updatedelayed: 0.5
:update: Range_Auto Frequency
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000
:updatemodechange:

#cmdSetup radio Aperture Frequency
:write: FREQ:APER #;[500]
:read: FREQ:APER?
0.01 0.01
0.1 0.1
1 1
:updatemodechange:

;Period-----------------------------------------------------------------------------------------
#cmdSetup radio Range Period
:write: PER:VOLT:RANG:AUTO #;[500]
:read: PER:VOLT:RANG:AUTO?
:updatedelayed: 0.5
:update: Range Period
AUTO 1
Manual 0
:updatemodechange:

#cmdSetup radio Range Period
:write: PER:VOLT:RANG #;[500]
:read: PER:VOLT:RANG?
:updatedelayed: 0.5
:update: Range_Auto Period
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000
:updatemodechange:

#cmdSetup radio Aperture Period
:write: PER:APER #;[500]
:read: PER:APER?
0.01 0.01
0.1 0.1
1 1
:updatemodechange:

;Ratio-------------------------------------------------------------------------------------
#cmdSetup radio Range_Auto Ratio
:read: VOLT:DC:RANG:AUTO?
:write: VOLT:DC:RANG:AUTO #;[500]
:updatedelayed: 0.5
:update: Range Ratio
Auto 1
Manual 0
:updatemodechange:

#cmdSetup radio Range Ratio
:write: VOLT:DC:RANG #;[500]
:read: VOLT:DC:RANG?
:updatedelayed: 0.5
:update: Range_Auto Ratio
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000
:updatemodechange:

#cmdSetup radio Auto_Zero Ratio
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
:updatedelayed: 1
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio Input_impedance_Auto Ratio
:write: INP:IMP:AUTO #;[500]
:read: INP:IMP:AUTO?
Off 0
On 1
:updatemodechange:

#cmdSetup radio NPLCycles Ratio
:write: VOLT:DC:NPLC #;[500]
:read: VOLT:DC:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

;Temperature----------------------------------------------------------------------------------
#cmdSetup radio Transducer_Type Temperature
:write: TEMP:TRAN:TYPE #;[500]
:read: TEMP:TRAN:TYPE?
:update: Temperature_Settings
:string:
Thermocouple TC
2W_RTD RTD
4W_RTD FRTD
Thermistor THER
:updatemodechange:

#cmdSetup selector Temperature_Settings Temperature
:read: TEMP:TRAN:TYPE?
:update: Transducer_Type
:updatedelayed: 0.2
:updatemodechange:
RTD Temperature2.Transducer_Type Temperature2.RTD_R0 Temperature2.RTD_Type Temperature2.NPLCycles Temperature2.Auto_Zero
FRTD Temperature2.Transducer_Type Temperature2.RTD_R0 Temperature2.RTD_Type Temperature2.NPLCycles Temperature2.Auto_Zero
THER Temperature2.Transducer_Type Temperature2.Thermistor_Type Temperature2.NPLCycles  Temperature2.Auto_Zero
TC Temperature2.Transducer_Type Temperature2.Thermocouple_Type Temperature2.Reference_Junction Temperature2.NPLCycles Temperature2.Auto_Zero

#cmdSetup radio Auto_Zero Temperature2
:write: ZERO:AUTO #;[500]
:read: ZERO:AUTO?
Off 0
On 1
Once ONCE
:updatemodechange:

#cmdSetup radio NPLCycles Temperature2
:write: TEMP:NPLC #;[500]
:read: TEMP:NPLC?
100PLC 100
10PLC 10
1PLC 1
0.2PLC 0.2
0.02PLC 0.02
:updatemodechange:

#cmdSetup comboboxHot Thermocouple_Type Temperature2
:write: TEMP:TRAN:TC:TYPE #;[500]
:read: TEMP:TRAN:TC:TYPE?
:update: Active_Type
B B
E E
J J
K K
N N
R R
S S
T T
:updatemodechange:

#cmdSetup number Reference_Junction Temperature2
:write: TEMP:TRAN:TC:RJUN #;[500]
:read: TEMP:TRAN:TC:RJUN?
:buttontext: Set
°C -1 +55
:updatemodechange:

#cmdSetup radio Thermistor_Type Temperature2
:write: TEMP:TRAN:THER:TYPE #;[500]
:read: TEMP:TRAN:THER:TYPE?
2.2kOhm +2200
5kOhm +5000
10kOhm +10000
:updatemodechange:

#cmdSetup number RTD_R0 Temperature2
:write: TEMP:TRAN:RTD:RES:REF #;[500]
:read: TEMP:TRAN:RTD:RES:REF?
:buttontext: Set
Ω 4.9 2100
:updatemodechange:

#cmdSetup radio RTD_Type Temperature2
:write: TEMP:TRAN:RTD:TYPE #;[500]
:read: TEMP:TRAN:RTD:TYPE?
alpha_=_0.00385 85
alpha_=_0.00391 91
:updatemodechange:

; ------------------------------------------------------------------------------------------------

#cmdSetup selector Mode_settings 
:read: FUNC?
:readmath: unQuote(value)
:updatemodechange:
VOLT DC_Voltage.
VOLT:AC AC_Voltage.
CURR DC_Current.
CURR:AC AC_Current.
DIOD Diode.
FREQ Frequency.
RES 2W_Resistance.
FRES 4W_Resistance.
CONT Continuity.
PER Period.
VOLT:RAT Ratio.
TEMP Temperature.