Campbell Scientific PS200/CH200 12 V Charging Regulators User Manual

Page 67

Advertising
background image

Appendix A. Advanced Programming Techniques

'SlowSequence with RS-232 measurements
SlowSequence

SendBattTemp = True
'Configure the COM port used with the PS/CH200
SerialOpen (COMPRT,9600,3,0,150)

Scan(30,sec,0,0)
'Measure battery temp with TC attached to external battery
TCDiff (ExtBatTempC,1,mV2_5C,1,TypeT,PanelTempC,True ,0,_60Hz,1.0,0)

'Send the external battery voltage temperature if SendBattTemp is true.
If SendBattTemp Then
'Send out the external battery temperature and format it.

'Convert the digital value for the external battery temperature to an
'ASCII string. Specify four digits with two decimals after the decimal

point.
ExtBatString = FormatFloat (ExtBatTempC,"%04.2f")
'Completed string sent to the PS/CH200 must be "WR_BT(nn.nn)>" where

'nn.nn are the ASCII numeric external battery temperature in Celsius.
xmit_str = WRITE_BATT_TEMP_CMD + ExtBatString + ")>"
Else

'SendBattTemp is false so send the reset string.

xmit_str = RESTR_BATT_TEMP_CMD
EndIf
'Send WAKEUP to wake up the PS/CH200.

Call WAKEUP
'Send out the PS/CH200 command followed by a carriage return.
SerialOut (COMPRT,xmit_str,"",1,3)

SerialOut (COMPRT,CR,"",1,3)
'Bring in the result from either command and process it.

'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.
If SendBattTemp Then
'PS/CH200 should return the battery temperature sent to it.

SplitStr (ReturnStr,CH200string,"String",1,0)
Else

'Reset command sent to the PS/CH200. Look for "OK".

OK_Loc = InStr(1,xmit_str,"O",2)

ReturnStr = Mid (xmit_str,OK_Loc,2)
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)

A-5

Advertising