beautypg.com

A.2.2 – Campbell Scientific PS200/CH200 12 V Charging Regulators User Manual

Page 70

background image

Appendix A. Advanced Programming Techniques

A.2.2 Change Battery Capacity RS-232 Programming Example

'CR1000 Series Datalogger
'Program: RS-232_Set_Batt_Cap.CR1
'Date: 1.November.2010

'Ver: A
'
'Notes: This program sets the battery capacity value in the PS/CH200.

'Connect the PS200/CH200 to RS-232 port COM2 of the CR1000.
'Use Campbell Scientific RS-232 cable part # 25356.
'

'RS-232 CABLE TO CR1000 WIRING
'-----------------------------
'GREEN: C3 (TX)

'WHITE: C4 (RX)
'BLACK: G

'CLEAR: G
'
'This program uses the RS-232 command "WR_BC(nnnn)>" to write battery capacity to the PS/CH200.

'It also collects extended PS/CH200 information using the "RD_SPECIAL>" command.

'Constants & Public Variables

'Change this constant if using a different com port on the CR1000.
Const COMPRT = COM2
'Hexadecimal equivalent of a carriage return.

Const CR = CHR(&H0D)
'It is a comma. Used to sort PS/CH200 strings.
Const COMMA = CHR(&H2C)


Public PanelTempC

'Datalogger panel temperature: Celsius

'Battery temperature from an external thermocouple.
Public ExtBatTempC

'Variables and constants used to get status information from the PS/CH200
'Command sent to the PS/CH200 to get status information.
Const CH200STATS_CMD = "RD_STAT>"

'Holds the check sum value of the received PS/CH200 string.
Public Check_sum
'Used to catch clutter from the PS/CH200

Dim xmit_str As String
'Holds the entire status string coming from the PS/CH200.

Dim CH200string As String * 140
'Holds parsed string values.
Dim CH200_M0(9) As String * 20

'Battery voltage: VDC
Public VBatt
'Current going into, or out of, the battery: Amps

Public IBatt
'Current going to the load: Amps
Public ILoad

'Voltage coming into the charger: VDC
Public V_in_chg
'Current coming into the charger: Amps

Public I_in_chg
'Charger temperature: Celsius

Public Chg_TmpC
'Charging state: Cycle, Float, Current Limited, or None
Public ChargeState As String

'Charging source: None, AC, or Solar
Public ChargeSource As String
'Check battery error: 0=normal, 1=check battery

Public Ck_Batt
'Word or phrase equivalent of check battery error.
Public CheckBattery As String

'Array to hold the names of the battery error information.
Dim CheckBatteryArr(2) As String

A-8