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

Appendix A. Advanced Programming Techniques
'SlowSequence with RS-232 measurements
SlowSequence
'Configure the COM port used with the PS/CH200
SerialOpen (COMPRT,9600,3,0,150)
Scan(30,sec,0,0)
'Get the PS/CH200 status information.
'Call 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
'Clear out QLoss
'Call WAKEUP to wake up the PS/CH200.
'If Clear_QLoss is set to true then set QLoss in the CH200 to zero.
If Clear_QLoss = True Then
CallTable ClearQLoss
Clear_QLoss = False
Call WAKEUP
'Send "read status" command to PS200 followed by a carriage return.
SerialOut (COMPRT,QLOSS_RES_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)
'Return strings are different for both instructions. Have to process them
'different as well.
QL_OK_Loc = InStr(1,xmit_str,"K",2)
QL_ReturnStr = Mid (xmit_str,QL_OK_Loc-1,2)
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).
A-30