#!/bin/bash
VPOINTS=(
0.0
0.01
0.03
0.1
0.2
0.7
1.0
1.2
1.7
2.0
2.3
2.7
3.0
3.8
4.2
4.7
5.1
5.3
5.6
6.0
6.5
7.0
8.0
8.4
9.0
10.0
11.0
12.0
13.0
14.0
15.0
16.0
17.0
18.0
19.0
20.0
21.0
22.0
23.0
24.0
25.0
26.0
27.0
28.0
29.0
30.0
31.0
32.0
33.0
34.0
35.0
36.0
37.0
38.0
39.0
40.0
41.0
42.0
43.0
44.0
45.0
46.0
47.0
48.0
49.0
50.0
51.0
52.0
53.0
54.0
55.0
56.0
57.0
58.0
59.0
60.0
61.0
62.0
63.0
64.0
65.0
66.0
67.0
68.0
69.0
)
CPOINTS=(
0.0
0.001
0.002
0.005
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.05
1.2
1.5
1.7
2.0
2.2
2.5
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
10.49
)
get_device_ip ()
{
local DEVICE="$1"
local IPADDR=`lxi discover | grep "$DEVICE" | grep -oe '[0-9\.]*$'`
echo $IPADDR
}
get_dmm_ip ()
{
get_device_ip DM3068
}
get_ps_ip ()
{
get_device_ip DP821A
}
DMM_IP=10.2.1.150
PS_IP=10.2.1.152
write_ps_cmd ()
{
local CMD="$1"
lxi scpi -a $PS_IP "$CMD"
}
write_dmm_cmd ()
{
local CMD="$1"
lxi scpi -t 10 -a $DMM_IP "$CMD"
}
read_dmm_vdc ()
{
V_SCPI=`write_dmm_cmd ":meas:volt:dc?"`
printf "%f\n" $V_SCPI
}
read_dmm_cdc ()
{
write_dmm_cmd ":meas:curr:dc max"
V_SCPI=`write_dmm_cmd ":meas:curr:dc?"`
printf "%f\n" $V_SCPI
}
read_ref ()
{
local POINT="$1"
if [ "$MODE" = "V" ]; then
REF=${VPOINTS[$POINT]}
elif [ "$MODE" = "C" ]; then
REF=${CPOINTS[$POINT]}
else
REF="somejunk"
fi
echo $REF
}
read_value ()
{
if [ "$MODE" = "V" ]; then
VALUE=`read_dmm_vdc`
elif [ "$MODE" = "C" ]; then
VALUE=`read_dmm_cdc`
else
VALUE="somejunk"
fi
echo $VALUE
}
ps_set_sense ()
{
if [ "$SENSE" = "on" ]; then
write_ps_cmd ":output:sense $CH,on"
elif [ "$SENSE" = "off" ]; then
write_ps_cmd ":output:sense $CH,off"
fi
}
calibration_loop ()
{
echo "CH = $CH, MODE = $MODE, DEV = $DEV, SENSE = $SENSE"
ps_set_sense
write_ps_cmd ":output $CH,on"
for (( POINT = 0; POINT < $NUMPOINTS; POINT++ )); do
local REF=`read_ref $POINT`
echo "POINT = $POINT, REF = $REF"
write_ps_cmd ":calibration:set $CH,$MODE,$POINT,$REF,$DEV"
sleep 2
local VALUE=`read_value`
echo "VALUE = $VALUE"
write_ps_cmd ":calibration:meas $CH,$MODE,$POINT,$VALUE,$DEV"
done
write_ps_cmd ":output $CH,off"
}
calibrate_ch1 ()
{
local CH="CH1"
write_ps_cmd ":calibration:start 11111,$CH"
if [ -n "$VOLTAGE" ]; then
local MODE="V"
write_ps_cmd ":calibration:clear $CH,$MODE"
local SENSE="none"
local NUMPOINTS=79
local DEV="1"
calibration_loop
local DEV="0"
calibration_loop
fi
echo "SWITCH DMM to Current Measurement, press enter to continue ..."
read
if [ -n "$CURRENT" ]; then
MODE="C"
write_ps_cmd ":calibration:clear $CH,$MODE"
local SENSE="none"
local NUMPOINTS=24
local DEV="1"
calibration_loop
local DEV="0"
calibration_loop
fi
write_ps_cmd ":calibration:end `date +%d/%m/%Y`,$CH"
}
calibrate_ch2 ()
{
local CH="CH2"
write_ps_cmd ":calibration:start 11111,$CH"
if [ -n "$VOLTAGE" ]; then
local MODE="V"
write_ps_cmd ":calibration:clear $CH,$MODE"
local SENSE="off"
local NUMPOINTS=24
local DEV="1"
calibration_loop
local DEV="0"
calibration_loop
fi
echo "SWITCH DMM to Current Measurement, press enter to continue ..."
read
if [ -n "$CURRENT" ]; then
MODE="C"
write_ps_cmd ":calibration:clear $CH,$MODE"
local SENSE="on"
local NUMPOINTS=39
local DEV="1"
calibration_loop
local DEV="0"
calibration_loop
fi
write_ps_cmd ":calibration:end `date +%d/%m/%Y`,$CH"
}
# put device into a known state
write_ps_cmd ":*RST"
VOLTAGE=1
CURRENT=1
calibrate_ch1
echo "SWITCH power supply output, press enter to continue ..."
read
calibrate_ch2