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

Appendix A. Advanced Programming Techniques
'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
'Get the PS/CH200 extended status information.
'Call 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
'Add up the current being consumed by the system. Include battery current in
'the calculation ONLY when it is positive - going into the battery.
'Current values coming from the PS/CH200 are in amps. Have to convert that to
'amp-hours based on the slow scan rate.
Sys_Amp_hr = Sys_Amp_hr + ILoad
If IBatt > 0 Then
Sys_Amp_hr = Sys_Amp_hr + IBatt
Batt_Amp_hr = IBatt
EndIf
Load_Amp_hr = ILoad
For n = 1 To 3
Amp_Hour(n) = Amp_Hour(n) * SlowScan/3600
Next n
'Must call these tables from the slow scan or the values will be wrong!
CallTable Amp_hr
CallTable Amp_Day
NextScan
EndProg
A-36