;  1/3/22 A GBY Added interface.
; TestController must be restarted before any changes in this file will be used.

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

; Quirk of operation:
;  Supply limits OVP to be at least 105% of actual voltage.
;  Symmetrically it limits the main voltage set point to < OVP/1.05

; There are 12 half rack power supplies in this Sorensen/Ametek XG family.
; Assume the idString for each is "AMETEK,XG <Volt>-<Current>
; There are 12 full rack versions with roughly twice the current, Watt ratings
; Half    Full
; 6-110   6-220
; 8-100   8-200
; 12-70   12-140
; 20-42   20-76
; 33-25   33-50
; 40-21   40-38
; 60-14   60-25
; 80-10.5 80-19
; 100-8.5 100-15
; 150-5.6 150-10
; 300-2.8 300-5
; 600-1.4 600-2.6
; Note that the AG 600-1.4 supply allows voltage, current set points about 4% above rating.
; This extra head room doesn't seem to be documented so for other models just a guess.

#metadef
#idString AMETEK,XG 600-1.4,
#name Ametek XG 600-1.4
#handle A600V1_4A

#replaceText Main_MaxVoltage 660
#replaceText Main_MaxCurrent 1.54

#metadef
#idString AMETEK,XG 80-10.5,
#name Ametek XG 80-10.5
#handle A80V10_5A

#replaceText Main_MaxVoltage 83
#replaceText Main_MaxCurrent 10.8

#meta

#idString AMETEK,XG 600-1.4,
#name Ametek XG600-1.4
#handle A600V1_4A
#port 5025
#author gby
; Alternate port types: comnobaud or com, com lets the user define baudrate on the "Load devices" page


; 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
;  >>>>>>>>>>>>>>>>>>>>>>>
; Per HJK: When using columns to show on/off value, try declaring the datatype "digital(on)" instead of "D0"
;  >>>>>>>>>>>>>>>>>>>>>>>
#value Main_On - digital(on)
#value Main_Voltage Vdc D3 
#value Main_Current Adc D3
#value Aux_On - digital(on)

; 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 OUTP:POW:STAT?;MEAS:SCAL:VOLT:DC?;MEAS:SCAL:CURR:DC?;OUTP:AUX:STAT?

; 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 


; 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 

; Used to turn output off for power supplies, generators and electronic loads
#outputOff OUTP:POW:STAT OFF;OUTP:AUX:STAT OFF

;  **********  Generic Power Supply Interface  *******
;  Modeled after existing Keithley 2280 series power supply from 10/19/20
; Using multi-channel interface in scripts requires vars set for PS, PS:2 in scripts.
; For example:
;  =var PS1=getDevice("PS")
;  =var PS2=getDevice("PS:2")

#interfaceType PS PS:2

#interface setCHVoltage SOUR:VOLT:LEV:IMM:AMPL (value)
#interface getCHVoltage SOUR:VOLT:LEV:IMM:AMPL?
;:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setCHCurrent SOUR:CURR:LEV:IMM:AMPL (value)
#interface getCurrent SOUR:CURR:LEV:IMM:AMPL?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOVP SOUR:VOLT:PROT:OVER (value)
#interface getOVP SOUR:VOLT:PROT:OVER?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOCP SOUR:CURR:PROT (value)
#interface getOCP SOUR:CURR:PROT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOn OUTP:POW:STAT (value)
#interface getOn OUTP:POW:STAT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

;#interface setAllOn OPALL (value)
;#interface getAllOn OPALL?
;:readmath: getMatch(value, "( |^)[-+.0-9].*")

;#interface SetTripReset TRIPRST

;  Pull values from #askValues used for logging.  Index goes 0 to n.
#interface readCH1Voltage 2
#interface readCH1Current 3


;  Setup popup

; Settings Tab
#cmdSetup number Main_Voltage Settings
:read: SOUR:VOLT:LEV:IMM:AMPL?
:write: SOUR:VOLT:LEV:IMM:AMPL
Vdc  0 Main_MaxVoltage

#cmdSetup number Main_Current Settings
:read: SOUR:CURR:LEV:IMM:AMPL?
:write: SOUR:CURR:LEV:IMM:AMPL
Adc  0 Main_MaxCurrent

; Protection/limit Tab
#cmdSetup number Main_OVP Protect
;  Supply limits OVP to be at least 105% of actual voltage.
;  Symmetrically limits the main voltage set point to < OVP/1.05
:read: SOUR:VOLT:PROT:OVER?
:write: SOUR:VOLT:PROT:OVER
Vdc  0 Main_MaxVoltage

; Protection/limit Tab
#cmdSetup number Main_UVP Protect
:read: SOUR:VOLT:PROT:UNDER?
:write: SOUR:VOLT:PROT:UNDER
Vdc  0 Main_MaxVoltage

#cmdSetup number Main_OCP Protect
:read: SOUR:CURR:PROT?
:write: SOUR:CURR:PROT
Adc  0 Main_MaxCurrent

; Button to reset protection shut down

#cmdSetup button Clear_Alarms Protect
:write: OUTP:PROT:CLE
:tip: Clear any active alarms

; Buttons to turn outputs on/off common to all tabs

#cmdSetup buttonsOn Main_Output
:string:
:read: OUTP:POW:STAT?
:readmath: getElement("Off On",value);
:write: OUTP:POW:STAT
:color: (0,255,0)
:tip: Turn Main output on or off
:updatealloff:
Off Off
On On

#cmdSetup buttonsOn Aux_5V_15V
:string:
:read: OUTP:AUX:STAT?
:readmath: getElement("Off On",value);
:write: OUTP:AUX:STAT
:color: (0,255,0)
:tip: Turn Aux outputs on or off
:updatealloff:
Off Off
On On
