#author Flavio Molinelli based on XDM3041 by Mark Wilson. 220625FM
#idString OWON,XDM1241
#name Owon XDM1241
#handle XDM1241
#port com
#baudrate 115200

#notes Many thanks to work done by: https://lygte-info.dk, TheHWCave, Mark Wilson, EEVBlog boys .....
FW 3.3.1 bug CONF:DIOD put it in DIOD but FUNC? returns CONT; CONF:CONT put it in CONT but FUNC? returns DIOD ...

;Driver locked to only use temperature in deg C.  Changing the unit of a value isn't clear in the documentation.
;entering offset values for relative measurement doesn't always seem to work correctly
;does not handle dual readings right now


; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
#value VoltageDC V si DC_Voltage,Continuity
#value CurrentDC A si DC_Current
#value VoltageAC V si AC_Voltage
#value CurrentAC A si AC_Current
#value Resistance ohm si Resistance,Diode
#value Capacitance F si Capacitance
#value Temperature C si Temperature
#value Frequency Hz si Frequency
#value Period s si Period

; 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 MEAS?

; Format of answer: f=float, u=remove trailing letters, x=skip, *=Zero upper case values if this value is 0
#askValuesReadFormat f

; Accept this delay when reading values (seconds)
#readingDelay 3

; Mode change have a longer delay on reading values (seconds)
#modeChangeDelay 5

; Switch meter to this mode during start, leave empty to avoid any switching
#initialMode

; String to ask about actual meter mode,
; This is a single line command
#askMode FUNC?
; Remove spaces from returned result: "VOLT AC" and "CURR AC" to "VOLTAC" and "CURRAC"
#askModeMathFormat unQuote(replace(replace(value,"VOLT AC","VOLTAC"),"CURR AC","CURRAC"))



; 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
#mayModifyMode CONF
;#mayModifyMode meas
;#mayModifyMode abor
;#mayModifyMode trig

; Prepare the meter to response to #askValues
;#prepareSample

; Initial commands to meter when establishing connection
#initCmd SYST:REM; TEMP:RTD:UNIT C

; Final command to meter before breaking connection
#finalCmd *cls; SYST:LOC

#interfaceType DMM
#interface readValue 0

; Strings to configure device in different modes
; First parameter must match a #value (4 parameter) and second parameter must match what #askMode returns
; First parameter is also used in shortcut menu
;#cmdMode

#cmdModeLayout 3 4

#cmdMode DC_Voltage VOLT
CONF:VOLT:DC

#cmdMode AC_Voltage VOLTAC
CONF:VOLT:AC

#cmdMode Resistance RES
CONF:RES

#cmdMode DC_Current CURR
CONF:CURR:DC

#cmdMode AC_Current CURRAC
CONF:CURR:AC

#cmdMode Diode DIOD
CONF:DIOD

#cmdMode Continuity CONT
CONF:CONT

#cmdMode Temperature TEMP
CONF:TEMP:RTD PT100
TEMP:RTD:UNIT C
TEMP:RTD:SHOW ALL

#cmdMode Capacitance CAP
CONF:CAP

#cmdMode Frequency FREQ
CONF:FREQ

#cmdMode Period PER
CONF:PER

; Setup menu functions
; The parameters on the first line is: type name page
; Settings on the following lines are:
; read: SCPI to read value from device, is used to synchronize when opening setup page or setting equal named fields. Not always used
; readformat: Parse read value.
; write: Send the value to device, this field is used in combination with data fields in the details to send updates to device.
; tip: Add this tip to all components for this input field.

;Mode-------------------------------------------------------------------------------------------
#cmdSetup info Active_Mode
:read: FUNC?
:readmath: getElement("Diode;DC Voltage;AC Voltage;DC Current;AC Current;Temperature;Capacitance;Resistance;Frequency;Period;Continuity",listIndex(unQuote(replace(replace(value,"VOLT AC","VOLTAC"),"CURR AC","CURRAC")),"CONT,VOLT,VOLTAC,CURR,CURRAC,TEMP,CAP,RES,FREQ,PER,DIOD",","),";")
:updatemodechange:

#cmdSetup Updater update
:update: Auto Range Speed Threshold
3.0

;DC_Voltage-------------------------------------------------------------------------------------
#cmdSetup radio Speed DC_Voltage
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto DC_Voltage
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range DC_Voltage
:read: RANGE?
_
_
:updatemodechange:

#cmdSetup comboboxHot SetRange DC_Voltage
:write: CONF:VOLT:DC
:read: RANGE?
:string:
50_mV 50E-3
500_mV 500E-3
5_V 5
50_V 50
500_V 500
1000_V 1000
:updatemodechange:


;#cmdSetup number Null_Value DC_Voltage
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;Volts -1000 +1000
;:updatemodechange:


;AC_Voltage-------------------------------------------------------------------------------------
#cmdSetup radio Speed AC_Voltage
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto AC_Voltage
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range AC_Voltage
:read: RANGE?
_
_
:updatemodechange:

#cmdSetup comboboxHot SetRange AC_Voltage
:write: CONF:VOLT:AC
:read: RANGE?
:string:
50_mV 50E-3
500_mV 500E-3
5_V 5
50_V 50
500_V 500
1000_V 1000
:updatemodechange:

;#cmdSetup number Null_Value AC_Voltage
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;Volts -750 +750
;:updatemodechange:


;Resistance----------------------------------------------------------------------------------
#cmdSetup radio Speed Resistance
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto Resistance
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range Resistance
:read: RANGE?
Ohm
_
:updatemodechange:

#cmdSetup comboboxHot SetRange Resistance
:write: CONF:RES
:read: RANGE?
:string:
500_Ohm 500
5_KOhm 5E3
50_KOhm 50E3
500_KOhm 500E3
5_MOhm 5E6
50_MOhm 50E6
:updatemodechange:

;#cmdSetup number Null_Value Resistance
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;? -60000000 +60000000
;:updatemodechange:


;DC_Current -------------------------------------------------------------------------------------
#cmdSetup radio Speed DC_Current
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto DC_Current
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range DC_Current
:read: RANGE?
_
_
:updatemodechange:

#cmdSetup comboboxHot SetRange DC_Current
:write: CONF:CURR:DC
:read: RANGE?
:string:
500_uA 500E-6
5_mA 5E-3
50_mA 50E-3
500_mA 500E-3
5_A 5
10_A 10
:updatemodechange:


;#cmdSetup number Null_Value DC_Current
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;Amps -10 +10
;:updatemodechange:


;AC_Current-------------------------------------------------------------------------------------
#cmdSetup radio Speed AC_Current
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto AC_Current
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range AC_Current
:read: RANGE?
_
_
:updatemodechange:

#cmdSetup comboboxHot SetRange AC_Current
:write: CONF:CURR:DC
:read: RANGE?
:string:
500_uA 500E-6
5_mA 5E-3
50_mA 50E-3
500_mA 500E-3
5_A 5
10_A 10
:updatemodechange:


;#cmdSetup number Null_Value AC_Current
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;Amps -10 +10
;:updatemodechange:


;Diode  (use CONT for V3.3.1 bug) ------------------------------------------------------------------------------------------
#cmdSetup radio Beeper Continuity
:write: SYST:BEEP
:read: SYST:BEEP?
:readmath: replace(value,"NO","ON")
:string:
On ON
Off OFF
:updatemodechange:

#cmdSetup radio Speed Continuity
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:


;Continuity (user Diode for V3.3.1 bug) ------------------------------------------------------------------------------------------
#cmdSetup radio Beeper Diode
:write: SYST:BEEP
:read: SYST:BEEP?
:readmath: replace(value,"NO","ON")
:string:
On ON
Off OFF
:updatemodechange:

#cmdSetup number Threshold Diode
:read: CONT:THRE?
:write: CONT:THRE
:buttontext: Set
Ohms 0 1000
:updatemodechange:

#cmdSetup radio Speed Diode
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:


;Temperature------------------------------------------------------------------------------------
#cmdSetup comboboxHot SENSORTYPE Temperature
:write: CONF:TEMP:RTD
:read: TEMP:RTD:TYPE?
:string:
THR_KITS90 KITS90
RTD_PT100 PT100
:updatemodechange:

#cmdSetup comboboxHot TEMPUNIT Temperature
:write: TEMP:RTD:UNIT
:read: TEMP:RTD:UNIT?
:string:
Celsius C
Fahrenheiht F
Kelvin K
:updatemodechange:

;#cmdSetup number Null_Value Temperature
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;C -270 +1820
;:updatemodechange:


;Capacitance------------------------------------------------------------------------------------
#cmdSetup radio Speed Capacitance
:write: RATE
:read: RATE?
:string:
Fast F
Middle M
Slow S
:updatemodechange:

#cmdSetup radio Auto Capacitance
:write: AUTO
:read: AUTO?
:readmath: replace(replace(value,"0","OFF"),"1","ON")
:string:
ON ON
OFF OFF
:updatemodechange:

#cmdSetup info Range Capacitance
:read: RANGE?
_
_
:updatemodechange:

#cmdSetup comboboxHot SetRange Capacitance
:write: CONF:CAP
:read: RANGE?
:string:
50_nF 50E-9
500_nF 500E-9
5_uF 5E-6
50_uF 50E-6
500_uF 500E-6
5_mF 5E-3
50_mF 50E-3
:updatemodechange:

;#cmdSetup number Null_Value Capacitance
;:read: CALC:NULL:OFFS?
;:write: CALC:NULL:OFFS
;:buttontext: Set
;mF -10 +10
;:updatemodechange:


;Frequency--------------------------------------------------------------------------------------

;Period-----------------------------------------------------------------------------------------

;Mod sel-------------------------------------------------------------------------------------------
#cmdSetup selector Mode_settings
:read: FUNC?
:readmath: unQuote(replace(replace(value,"VOLT AC","VOLTAC"),"CURR AC","CURRAC"))

:updatemodechange:
VOLT DC_Voltage.
VOLTAC AC_Voltage.
CURR DC_Current.
CURRAC AC_Current.
DIOD Diode.
FREQ Frequency.
TEMP Temperature.
RES Resistance.
CAP Capacitance.
CONT Continuity.
PER Period.
