
; TestController must be restarted before any changes in this file will be used.

; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html

#metadef
#idString Chauvin Arnoux,C.A5292,
#name Chauvin Arnoux CA 5292
#handle CA5292
#replaceText Brand Chauvin Arnoux

#metadef
#idString Chauvin Arnoux,C.A5292-BT,
#name Chauvin Arnoux CA 5292 BT
#handle CA5292
#replaceText Brand Chauvin Arnoux

#metadef
#idString Chauvin Arnoux,C.A5293,
#name Chauvin Arnoux CA 5293
#handle CA5293
#replaceText Brand Chauvin Arnoux

#metadef
#idString Chauvin Arnoux,C.A5293-BT,
#name Chauvin Arnoux CA 5293 BT
#handle CA5293
#replaceText Brand Chauvin Arnoux

#metadef
#idString Metrix,MTX3293B,
#name Metrix MTX3293B
#handle MTX3293B
#replaceText Brand Metrix

#metadef
#idString Metrix,MTX3292B,
#name Metrix MTX3292B
#handle MTX3292B
#replaceText Brand Metrix

#metadef
#idString Metrix,MTX3293B-BT,
#name Metrix MTX3293B BT
#handle MTX3293B
#replaceText Brand Metrix

#metadef
#idString Metrix,MTX3292B-BT,
#name Metrix MTX3292B BT
#handle MTX3292B
#replaceText Brand Metrix

#metadef
#idString Metrix,MTX 3292,
#name Metrix MTX3292
#handle MTX3292B
#replaceText Brand Metrix



#meta
#idString C.A5293-BT,
#name Chauvin Arnoux CA 5293 BT
#handle CA5293
#port comfixedbaud
; Alternate port types: comnobaud or com, com lets the user define baudrate on the "Load devices" page
#baudrate 38400
#driver SCPIx

#notes Meter must be configured to 38400 baud and SCPI protocol. 
Download of log data is supported, but do not log faster than once a second, meter do not record time precise enough for higher sample rate.

#scpiCmd cat? txrxTimeout? 0.1 DATA:CAT?
#scpiCmd readLog? txrxTimeout? 0.5 DATA:VAL? (value)
#scpiCmd *IDN? txrx? *IDN?
:readmath: "Brand,"+getElement(value,0,",")+","+","+getElement(value,1,",")+" "+getElement(value,2,",")

;° symbol is using UTF8, but µ symbol is not. If a software update in the meter fixes this to use UTF8 for both enable this line.
;#charset UTF-8

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6) 
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
#value Voltage V SI VOLTAGE,Voltage,LOWZVOLTAGE,Voltage_LowZ,Diode,DIODE,Diode_high_Volt,DIODEZ
#value Frequency Hz D4 FREQUENCY,Frequency
#value Resistance Ohm SI RESISTANCE,Resistance,Continuity,CONTINUITY,100_ohm,100OHM
#value Current A SI CURRENT,Current
#value Temperature °C D1 TEMPERATURE,Temperature
#value Capacitance F SI CAPACITOR,Capacitance

#cmdModeLayout 2 6

#cmdMode Voltage VOLTAGE
func "VOLTAGE"
#cmdMode Voltage_LowZ LOWZVOLTAGE
func "LOWZVOLTAGE"

#cmdMode Current CURRENT
func "CURRENT"
#cmdMode Frequency FREQUENCY
func "FREQUENCY"

#cmdMode Resistance RESISTANCE
func "RESISTANCE"
#cmdMode 100_ohm 100OHM
func "100OHM"

#cmdMode Diode DIODE
func "DIODE"
#cmdMode Diode_high_Volt DIODEZ
func "DIODEZ"

#cmdMode Continuity CONTINUITY
func "CONTINUITY"
#cmdMode Capacitance CAPACITOR
func "CAPACITOR"

#cmdMode Temperature TEMPERATURE
func "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.
; Number of returned values must match number of columns defined with #value
; 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 

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

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


; String to ask about actual meter mode, it is mostly used for DMM's
; This is a single line command
#askMode FUNCTION?


; 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 arm:sour imm;:arm:count 1;:trig:sour imm;:trig:count 1;:trig:samp:count 1;init

; Initial commands to meter when establishing connection, used to disable local control
;#initCmd  

; Final command to meter before breaking connection, used to restore local control
#finalCmd LOCAL

; Used to turn output off for power supplies, generators and electronic loads
;#outputOff 

#interfaceType DMM
#interface readValue 0


#cmdSetup radio Coupling Voltage
:read: INPUT:COUP?
:write: INPUT:COUP
:string:
:update: Filter
AC AC
DC DC
AC+DC ACDC

#cmdSetup radio Range Voltage
:read: RANGE?
:readmath: doubleSI(getMatch(value,"[0-9.]+[m ]+"));
:write: RANGE
:enable: Voltage.Auto_range.on==0 && Voltage.Auto_range.Peak==0
100mV 0.1
1V 1.0
10V 10.0
100V 100.0
1000V 1000.0


#cmdSetup checkbox Auto_range Voltage
:read: range:auto?
:write: range:auto
:update: Range
on 0 1

#cmdSetup checkbox Auto_range Voltage
:read: range:auto:peak?
:write: range:auto:peak
:update: Range
Peak 0 1


#cmdSetup checkbox High_Impedance Voltage
:read: INP:IMP?
:write: INP:IMP
:tip: This setting is used in 0.1V & 1V DC ranges.
on 1E+7 1E+9

#cmdSetup checkbox Filter Voltage
:read: FILTER?
:write: FILTER
:enable: Voltage.Coupling!="DC"
on 0 1

#cmdSetup radio Secondary Voltage
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
:enable: Voltage.Waveform.on==0
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC

#cmdSetup checkbox Waveform Voltage
:read: CALC:WFORM:STAT?
:write: CALC:WFORM:STAT
:update: Secondary
:enable: Voltage.Coupling!="DC"
:tip: Show the waveform, works up to 600Hz
on 0 1

#cmdSetup radio Secondary LowZVoltage
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC


#cmdSetup radio Coupling Current
:read: INPUT:COUP?
:write: INPUT:COUP
:string:
:update: Filter
AC AC
DC DC
AC+DC ACDC

#cmdSetup radio Range Current
:read: RANGE?
:readmath: doubleSI(getMatch(value,"[0-9.]+[muµ ]+"));
:write: RANGE
:updatedelayed: 0.3
:enable: Current.Auto_range.on==0 && Current.Auto_range.Peak==0
1mA 1e-3
10mA 10e-3
100mA 100e-3
1A 1
10A 10
100A 100


#cmdSetup checkbox Auto_range Current
:read: range:auto?
:write: range:auto
:update: Range
on 0 1

#cmdSetup checkbox Auto_range Current
:read: range:auto:peak?
:write: range:auto:peak
:update: Range
Peak 0 1



#cmdSetup checkbox Filter Current
:read: FILTER?
:write: FILTER
:enable: Current.Coupling!="DC"
on 0 1

#cmdSetup radio Secondary Current
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
:enable: Current.Waveform.on==0
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC

#cmdSetup checkbox Waveform Current
:read: CALC:WFORM:STAT?
:write: CALC:WFORM:STAT
:update: Secondary
:enable: Current.Coupling!="DC"
:tip: Show the waveform, works up to 600Hz
on 0 1


#cmdSetup radio Frequency_range Frequency
:read: FREQ:MODE?
:write: FREQ:MODE
:string:
<200Khz INF200KHZ
>200Khz SUP200KHZ

#cmdSetup radio Voltage_range Frequency
:read: FREQ:THR:VOLT:RANG?
:write: FREQ:THR:VOLT:RANG
:readmath: replace(value,"V","");
100mV 0.1
1V 1
10V 10
100V 100
1000V 1000

#cmdSetup checkbox Filter Frequency
:read: FILTER?
:write: FILTER
on 0 1

#cmdSetup radio Secondary Frequency
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC



#cmdSetup radio Secondary Resistance
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC

#cmdSetup radio Range Resistance
:read: RANGE?
:readmath: doubleSI(getMatch(value,"[0-9.]+[muµ kM]+"));
:write: RANGE
:updatedelayed: 0.3
:enable: Resistance.Auto_range.on==0
1kohm 1e3
10kohm 10e3
100kohm 100e3
1Mohm 1e6
10Mohm 10e6
100Mohm 100e6


#cmdSetup checkbox Auto_range Resistance
:read: range:auto?
:write: range:auto
:update: Range
on 0 1


#cmdSetup radio Secondary Resistance100
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV


#cmdSetup radio Secondary Continuity 
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Specifications SPEC

#cmdSetup radio Diode Diode
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Specifications SPEC

#cmdSetup radio Diode Diode_high_Volt
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Specifications SPEC

#cmdSetup radio Capacitance Capacitance
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV
Specifications SPEC


#cmdSetup radio Range Capacitance
:read: RANGE?
:readmath: doubleSI(getMatch(value,"[0-9.]+[muµn kM]+"));
:write: RANGE
:updatedelayed: 0.3
:enable: Capacitance.Auto_range.on==0
:tip: This do not work correctly, the meter reports wrong ranges.
1nF 1e-9
10nF 10e-9
100nF 100e-9
1uF 1e-6
10uF 10e-6
100uF 100e-6
1mF 1e-3
10mF 10e-3


#cmdSetup checkbox Auto_range Capacitance
:read: range:auto?
:write: range:auto
:update: Range
on 0 1


#cmdSetup radio Sensor Temperature
:read: TEMP:TRAN?
:write: TEMP:TRAN
:string:
Type-J TCJ
Type-K TCK
RTD_PT100 PT100
RTD_PT1000 PT1000


#cmdSetup radio Secondary Temperature
:read: CALC:FUNC?
:write: CALC:FUNC ("\""+value+"\"")
:string:
Trend GRAPH
Relative REL
Statistic SURV





#cmdSetup Selector No_settings Main
:read: FUNCTION?
:updatemodechange:
VOLTAGE Voltage.
CURRENT Current.
FREQUENCY Frequency.
RESISTANCE Resistance.
100OHM Resistance100.
LOWZVOLTAGE LowZVoltage.
TEMPERATURE Temperature.
CAPACITOR Capacitance.
CONTINUITY Continuity.
DIODE Diode.
DIODEZ Diode_high_Volt. 


;Settings page-------------------------------------------------------------------------------------------

#cmdSetup number Log_sample_rate Settings
:read: TRACE:RATE?
:write: TRACE:RATE
:tip: Avoid specifying rates with a decimal, because time stamp is in full seconds
sec 0.3 86399000


#cmdSetup button Set_date_time Settings
:write: SYST:DATE (formatDateTime("yy,MM,dd",date()));SYST:TIME (formatDateTime("HH,mm,ss",date()))




;Other menu-------------------------------------------------------------------------------------------
;Display uses a 16 color palette and returns a 240x320 image
#ScreenDump CA1
HCOP:SDUM:IMM? 

#otherList
Var list=split(deviceRead(handle,"CAT?"),"[\\n]");
Var line="";
Var n=0;
foreach line in list do
	if (match(line,"MEM[0-9]+.*"))
		menuItem[n]=line+".csv";
		n=n+1;
		endif;
	endforeach


#otherData
var samples=getMatchGroup(name,"\\(([0-9]+)\\)",1);
name=getMatch(name,"MEM[0-9]+");
popupShowProgressAsync("Downloading log "+name+" data from "+handle,-samples,samples/117.0*32000.0);// Download speed 32 seconds for 117 records
var data=split(deviceRead(handle,"readLog? "+name),"[\\n\\r]+");
var line;
var columnName="value";
var unit=trim(getMatchGroup(data[0],"^[^+-]+[+-][0-9.]+[nuµm kMG]([^0-9]{1,3})",1));
if (unit=="F") columnName="Capacitance";
elseif (unit=="VAC" || unit=="VDC" || unit=="VAC+DC" || unit=="V") columnName="Voltage";
elseif (unit=="Hz") columnName="Frequency";
elseif (unit=="Ohm") columnName="Resistance";
elseif (match(unit,".*°C")) columnName="Temperature";
elseif (unit=="Ohm") columnName="Resistance";
elseif (unit=="AAC" || unit=="ADC" || unit=="AAC+DC" || unit=="A") columnName="Current";
endif
var columnsExtra="";
var columnsExtraCount=countMatch(data[0],"[+-][0-9.]+[nuµm kMG]")-1;
if (columnsExtraCount==1) 
	columnsExtra=","+handle+".value";
elseif (columnsExtraCount==2) 
	columnsExtra=","+handle+".value1,"+handle+".value2";
elseif (columnsExtraCount==3) 
	columnsExtra=","+handle+".value1,"+handle+".value2,"+handle+".value3";
endif;

tableInitHeader("index,time,dateTime,"+handle+"."+columnName+columnsExtra);
var startTime=date("dd:MM:yy HH:mm:ss",substring(data[0],6,23))
foreach line in data do
	var index=substring(line,0,5);
	var date = date("dd:MM:yy HH:mm:ss",substring(line,6,23))
	var value=getMatch(line,"[+-][0-9.]+[nuµm kMG]+");
	if (columnsExtraCount==0) 
		tableAddRow(index,int((date-startTime)*24*60*60+0.5),int(date)/1000,doubleSI(value)); 
	elseif (columnsExtraCount==1) 
		var value1=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",1);
		tableAddRow(index,int((date-startTime)*24*60*60+0.5),int(date)/1000,doubleSI(value),doubleSI(value1)); 
	elseif (columnsExtraCount==2) 
		var value1=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",1);
		var value2=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",2);
		tableAddRow(index,int((date-startTime)*24*60*60+0.5),int(date)/1000,doubleSI(value),doubleSI(value1),doubleSI(value2)); 
	elseif (columnsExtraCount==3) 
		var value1=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",1);
		var value2=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",2);
		var value3=getMatch(line,"[+-][0-9.]+[nuµm kMG]*",3);
		tableAddRow(index,int((date-startTime)*24*60*60+0.5),int(date)/1000,doubleSI(value),doubleSI(value1),doubleSI(value2),doubleSI(value3)); 	
	endif;
	endforeach
popupShowProgressSetPosition(1e9);
