; HSPY-400-1 400V 1A power supply
; Rev. 1.0 4 Nov 2020
; Rev. 1.1 4 Nov 2020 - implemented HKJ suggestions, fixed interface statements.

#author Hydron
#name HSPY-400-1
#handle HSPY
#idString HSPY, HSPY-400-1
#notes No known method for querying/verifying model. Set unit to address 001, baud to 9600.

; Other baud rates didn't seem to work, stick with default of 9600
#port comfixedbaud
#baudrate 9600
#driver Modbus

#cmdDelayTime 10

#scpiCmd VSet holding 0x1000 (value) *10
#scpiCmd VSet? holding? 0x1000 /10
#scpiCmd ISet holding 0x1001 (value) *1000
#scpiCmd ISet? holding? 0x1001 /1000
#scpiCmd VOut? holding? 0x1002 /10
#scpiCmd IOut? holding? 0x1003 /1000
#scpiCmd OUTPUT holding 0x1004 (value)
#scpiCmd OUTPUT? holding? 0x1004
#scpiCmd KEYLOCK holding 0x1006 (value)
#scpiCmd KEYLOCK? holding? 0x1006
#scpiCmd PSet holding 0x1007 (value) * 10
#scpiCmd PSet? holding? 0x1007 /10
#scpiCmd POut? holding? 0x1008 /10
#scpiCmd MODE? holding? 0x100E
#scpiCmd ControlMode holding 0x1009 (value)
#scpiCmd ControlMode? holding? 0x1009
; mAh (0x1011, r) not implemented, Normal/Power/Ah mode set (0x1009, r/w) only used to force supply to normal mode as the other two are pretty useless (and/or buggy).

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
#value VoltageSet V D1
#value CurrentSet A D3
#value Voltage V D1
#value Current A D3
; #value PowerSet W D1 ; power mode doesn't work very well, not implemented
#value Power W D1

; This is a single line command
#askValues VSet?; ISet?; VOut?; IOut?; POut?

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

; Initial commands to meter when establishing connection
; Turn output OFF to put supply in known state, set to control mode 0 (normal).
;#initCmd OUTPUT 0; KEYLOCK 1
#initCmd OUTPUT 0; ControlMode 0

; Final command to meter before breaking connection
;#finalCmd OUTPUT 0; KEYLOCK 0
#finalCmd OUTPUT 0

; Used when output off button is pressed
#outputOff OUTPUT 0

#interfaceType PS
#interface setVoltage VSet (value)
#interface setCurrent ISet (value)
#interface setOn OUTPUT (value)
#interface getVoltage VSet?
#interface getCurrent ISet?
#interface getOn OUTPUT?
#interface readVoltage 2
#interface readCurrent 3
#interface readPower 4

; 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 

; 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.

#cmdSetup buttonsOn Output
:read: OUTPUT?
:write: OUTPUT 
:tip: Turn output on or off
:updatealloff:
:update: Output
:updatedelayed: 0.3 
Off 0
On 1

; Keylock clutters up the window with minimal benefit - can be added if desired.
;#cmdSetup buttonsOn Keylock
;:read: KEYLOCK?
;:write: KEYLOCK 
;:updatedelayed: 0.3 
;Off 0
;On 1

; Voltage radio options limited to 48V for safety - if you want more, type it in!
#cmdSetup radio Voltage
:read: VSet?
:write: VSet
:update: Voltage
:update: 0.3 
:tip: Setup this voltage
3.3V 3.3
5V 5.0
12V 12.0
24V 24.0
48V 48.0

#cmdSetup radio Current
:read: ISet?
:write: ISet
:update: Current
:updatedelayed: 0.3 
:tip: Output will current limit at this current
10mA 0.01
50mA 0.05
100mA 0.1
500mA 0.5
1A 1.0

#cmdSetup number Voltage 
:read: VSet?
:write: VSet
:tip: Setting this voltage, does not turn output on/off
V 0.0 401.0

#cmdSetup number Current
:read: ISet?
:write: ISet
:tip: Setting this current, does not turn output on/off
A 0.000 1.050

#cmdSetup indicatornum Status
:read: MODE?
CV 1 blue
CC 0 red

; Keep CC/CV mode indicator up to date
#cmdSetup Updater Status
:update: Status
1