Campbell Scientific PS200/CH200 12 V Charging Regulators User Manual
Page 72

Appendix A. Advanced Programming Techniques
'SlowSequence with RS-232 measurements
SlowSequence
'For this exercise a battery capacity of 12 will be written to the CH200.
NewBattCap = 12
'Configure the COM port used with the PS/CH200
SerialOpen (COMPRT,9600,3,0,150)
Scan(30,sec,0,0)
'NOTE: THE ORDER IN WHICH COMMANDS ARE SENT, AND READ FROM, THE CH200
'IS VERY IMPORTANT! KEEP THE STRUCTURE AS SHOWN IN THIS EXAMPLE. IT
'WILL TAKE TWO COMPLETE SCAN CYCLES TO UPDATE ALL VARIABLE
'INFORMATION.
'Get the PS/CH200 extended status information.
'Send WAKEUP to wake up the PS/CH200.
Call WAKEUP
'Send "read extended status" command to PS/CH200 followed by a carriage
'return.
SerialOut (COMPRT,EXTSTATS_CMD,"",1,3)
SerialOut (COMPRT,CR,"",1,3)
'Discard characters in the receiver buffer up to and including asterisks "*"
SerialIn (xmit_str,COMPRT,50,"*",40)
'Capture the PS/CH200 response string after the asterisks and including the
'string terminator hexadecimal zero (&H00).
SerialIn (CH200string,COMPRT,50,&H00,140)
Check_sum = CheckSum (CH200string,5,0 )
'For the string to be correct the check sum must be zero.
If Check_sum = 0 Then
'Split up the main string from PS/CH200 into separate components.
SplitStr (CH200_MX(),CH200string,COMMA,4,4)
'Sort out the components to specific variables.
BattTargV = CH200_MX(1)
DgtlPotSet = CH200_MX(2)
BattCap = CH200_MX(3)
Qloss = CH200_MX(4)
EndIf
'Get the PS/CH200 status information.
'Send WAKEUP to wake up the PS/CH200.
Call WAKEUP
'Send "read status" command to PS200 followed by a carriage return.
SerialOut (COMPRT,CH200STATS_CMD,"",1,3)
SerialOut (COMPRT,CR,"",1,3)
'Discard characters in the receiver buffer up to and including asterisks "*"
SerialIn (xmit_str,COMPRT,50,"*",40)
'Capture the PS/CH200 response string after the asterisks and including the
'string terminator hexadecimal zero (&H00).
SerialIn (CH200string,COMPRT,50,&H00,140)
Check_sum = CheckSum (CH200string,5,0 )
'For the string to be correct the check sum must be zero.
If Check_sum = 0 Then
'Split up the main string from PS/CH200 into separate components.
SplitStr (CH200_M0(),CH200string,COMMA,9,4)
'Sort out the components to specific variables.
VBatt = CH200_M0(1)
IBatt = CH200_M0(2)
ILoad = CH200_M0(3)
V_in_chg = CH200_M0(4)
I_in_chg = CH200_M0(5)
Chg_TmpC = CH200_M0(6)
ChargeState = CH200_M0(7)
ChargeSource = CH200_M0(8)
Ck_Batt = CH200_M0(9)
'Values for check battery start with zero. Have to shift the value
'by one to line it up with the correct words in the array.
CheckBattery = CheckBatteryArr(Ck_Batt + 1)
EndIf
A-10