Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Last Program Compiled: Warning: Variable ChargeStateArr out of bounds


Terrapin Jan 31, 2018 07:06 PM

I've been using the following code provided by CSI for collecting SDI-12 data from my CH200.  For quite some time I wasn't seeing the following compile error message: Last Program Compiled: Warning: Variable ChargeStateArr out of bounds. 

But several months ago this message started appearing after downloading a new program. In addition, I now get the following Status Error (Variable Out of Bounds: There is a program) after downloading a new program or when the CH200 is disconnected from the CR1000

I've updated the firmware of the CH200 and CR1000's and wonder if there is something in the latest versions of each that might be causing this problem to occur now.

Does anyone have any suggestions for how to avoid both the compile error message as well as the Variable Out of Bounds: There is a program Status Error I now get when the program is first downloaded and if the CH200 is disconnected from the CR1000?

'@@@@@@@@@@@@@@@@@@@@@@@@@   DECLARATIONS   @@@@@@@@@@@@@@@@@@@@@@@@@

'Declare Constants
Const Prog_ID_Constant = 18.016

'I like to use the words "on" and "off" vs. "true" and "false".
Const On = True
Const Off = False

StationName(CH200_Test)

'Declare Variables and Units
Public Prog_ID
Public Bat_Volt


'@@@@@@@@@@@@@@@@@@@@@@@@@   CH200 Battery Section   @@@@@@@@@@@@@@@@@@@@@@@@@

Const CH200Scan = 300                    'Scan rate that calculates current loss/gain

Public ActBattCap                        'Actual battery capacity (Ah)
Public CyclicBattCap                     'Battery capacity (Ah) required to force cyclic charging

Public Clear_QLoss As Boolean            'Setting the variable Clear_QLoss = True will clear QLoss.

Public Amp_Hour(3)                       'Array holding all the three Amp-hour calculations
Alias Amp_Hour(1) = Sys_Amp_hr           'Amp-hours used by the entire system.
Alias Amp_Hour(2) = Load_Amp_hr          'Amp-hours used by the datalogger, sensors and any communication options.
Alias Amp_Hour(3) = Batt_Amp_hr          'Amp-hours going into the battery. Current coming out of the battery is part of the Load_Amp_hr value.

Dim n                                    'Used as a counter.

Public CH200_M0(9)                       'Array to hold all the data coming from the CH200
Alias CH200_M0(1)=VBatt                  'Battery voltage: VDC
Alias CH200_M0(2)=IBatt                  'Current going into, or out of, the battery: Amps
Alias CH200_M0(3)=ILoad                  'Current going to the load: Amps
Alias CH200_M0(4)=V_in_chg               'Voltage coming into the charger: VDC
Alias CH200_M0(5)=I_in_chg               'Current coming into the charger: Amps
Alias CH200_M0(6)=Chg_TmpC               'Charger temperature: Celsius
Alias CH200_M0(7)=Chg_State              'Charging state: Cycle, Float, Current Limited, or None
Alias CH200_M0(8)=Chg_Source             'Charging source: None, AC, or Solar
Alias CH200_M0(9)=Ck_Batt                'Check battery error: 0=normal, 1=check battery

Public I_In_Chg_Amp_hr                   'Total current coming into charger: Amps

'Arrays to hold the associated words for the charge state, charge source, and check battery values.
Dim ChargeStateArr(7) As String
Dim ChargeSourceArr(4) As String
Dim CheckBatteryArr(3) As String

'Variables to hold the words for charge state, charge source, and check battery.
Public ChargeState As String
Public ChargeSource As String
Public CheckBattery As String

Public CH200_MX(4)                       'Array to hold extended data from the CH200
Alias CH200_MX(1) = BattTargV            'Battery charging target voltage.
Alias CH200_MX(2) = DgtlPotSet           'Digital potentiometer setting.
Alias CH200_MX(3) = BattCap              'Present battery capacity.
Alias CH200_MX(4) = Qloss                'Battery charge deficit.

Public CH200_SDI12Command As String      'SDI-12 formatted battery capacity value.
Public CH200_SDI12Result As String       'Stores the results from the CH200 query. In this case nothing is returned.

Public CH200_SDI12_Address As String     'Existing SDI-12 address in the CH200

'Variables for counting Charge State and Charge Source Observations
Public Counts_Charge_State_None
Public Counts_Charge_State_Current_Ltd
Public Counts_Charge_State_Cyclic
Public Counts_Charge_State_Float

Public Counts_Charge_Source_None
Public Counts_Charge_Source_Solar
Public Counts_Charge_Source_Continuous


'@@@@@@@@@@@@@@@@@@@@@@@@@   CH200 Battery Section   @@@@@@@@@@@@@@@@@@@@@@@@@

'Stored hourly Amp-hour values and present Qloss value.
DataTable(Amp_Hr,True,-1)
   DataInterval(0,1,Hr,10)
   Sample(1,Prog_ID,IEEE4)
   Totalize(1,Sys_Amp_hr,IEEE4,False)
   Totalize(1,Load_Amp_hr,IEEE4,False)
   Totalize(1,Batt_Amp_hr,IEEE4,False)
   Totalize(1,I_In_Chg_Amp_hr,IEEE4,False)
   Average(1,V_in_chg,IEEE4,False)
   Average(1,VBatt,IEEE4,False)
   Totalize(1,Counts_Charge_State_None,IEEE4,False)
   Totalize(1,Counts_Charge_State_Current_Ltd,IEEE4,False)
   Totalize(1,Counts_Charge_State_Cyclic,IEEE4,False)
   Totalize(1,Counts_Charge_State_Float,IEEE4,False)
   Totalize(1,Counts_Charge_Source_None,IEEE4,False)
   Totalize(1,Counts_Charge_Source_Solar,IEEE4,False)
   Totalize(1,Counts_Charge_Source_Continuous,IEEE4,False)
   Sample(1,Qloss,IEEE4)
EndTable

'Stored hourly Amp-hour values and present Qloss value.
DataTable(Amp_Day,True,-1)
   DataInterval(0,1,Day,10)
   Sample(1,Prog_ID,IEEE4)
   Totalize(1,Sys_Amp_hr,IEEE4,False)
   Totalize(1,Load_Amp_hr,IEEE4,False)
   Totalize(1,Batt_Amp_hr,IEEE4,False)
   Totalize(1,I_In_Chg_Amp_hr,IEEE4,False)
   Average(1,V_in_chg,IEEE4,False)
   Average(1,VBatt,IEEE4,False)
   Totalize(1,Counts_Charge_State_None,IEEE4,False)
   Totalize(1,Counts_Charge_State_Current_Ltd,IEEE4,False)
   Totalize(1,Counts_Charge_State_Cyclic,IEEE4,False)
   Totalize(1,Counts_Charge_State_Float,IEEE4,False)
   Totalize(1,Counts_Charge_Source_None,IEEE4,False)
   Totalize(1,Counts_Charge_Source_Solar,IEEE4,False)
   Totalize(1,Counts_Charge_Source_Continuous,IEEE4,False)
   Sample(1,Qloss,IEEE4)
EndTable

DataTable(Amp_5min,True,-1)
   DataInterval(0,5,Min,10)
   Sample(1,Prog_ID,IEEE4)
   Sample(1,Sys_Amp_hr,IEEE4)
   Sample(1,Load_Amp_hr,IEEE4)
   Sample(1,Batt_Amp_hr,IEEE4)
   Sample(1,I_in_chg,IEEE4)
   Sample(1,V_in_chg,IEEE4)
   Sample(1,VBatt,IEEE4)
   Sample(1,BattTargV,IEEE4)
   Sample(1,DgtlPotSet,IEEE4)
   Totalize(1,Counts_Charge_State_None,IEEE4,False)
   Totalize(1,Counts_Charge_State_Current_Ltd,IEEE4,False)
   Totalize(1,Counts_Charge_State_Cyclic,IEEE4,False)
   Totalize(1,Counts_Charge_State_Float,IEEE4,False)
   Totalize(1,Counts_Charge_Source_None,IEEE4,False)
   Totalize(1,Counts_Charge_Source_Solar,IEEE4,False)
   Sample(1,Qloss,IEEE4)
EndTable


'@@@@@@@@@@@@@@@@@@@@@@@@@   PROGRAM   @@@@@@@@@@@@@@@@@@@@@@@@@
'Executed every 5 minutes
'Sensors are sampled and the values are in engineering units
'SequentialMode

BeginProg

   'Set datalogger PakBus address
   SetStatus("PakBusAddress","30")

   'Set actual battery capacity (Ah)
   ActBattCap = 13

   'Set battery capacity (Ah) required to force cyclic charging
   CyclicBattCap = 1

   'Set user specified SDI-12 address
   CH200_SDI12_Address = "P"

   'Set CH200 Qloss Flag
   Clear_QLoss = Off

   'Load arrays with words to associate with the charge state, charge source
   'and check battery values from the PS/CH200.
   ChargeStateArr(1) = "Regulator Fault"
   ChargeStateArr(2) = "No Charge"
   ChargeStateArr(3) = "Current Limited"
   ChargeStateArr(4) = "Cycle Charging"
   ChargeStateArr(5) = "Float Charging"
   ChargeStateArr(6) = "Battery Test"
   ChargeStateArr(7) = "Check CH200"

   ChargeSourceArr(1) = "None"
   ChargeSourceArr(2) = "Solar"
   ChargeSourceArr(3) = "Continuous"
   ChargeSourceArr(4) = "Check CH200"

   CheckBatteryArr(1) = "Normal"
   CheckBatteryArr(2) = "Check Battery"
   CheckBatteryArr(3) = "Check CH200"

   Scan(5,Min,3,0)         'Define high frequency scan of sensors for testing purposes

      '########   PROGRAM ID   ########
      'Date when program is modified; format = YY.DDD
      'Units: none
      If Prog_ID <> Prog_ID_Constant Then
         Prog_ID = Prog_ID_Constant
      EndIf

      '########   BATTERY VOLTAGE   ########
      'Units: Volts
      Battery(Bat_Volt)

      '########   PANEL TEMPERATURE   ########
      'Units: C
      PanelTemp(TPanel_C,250)

      '@@@@@@@@@@@@@@@@@@@@@@   START CH200 Battery Section   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

      '########   CH200 BATTERY CHARGER - GET CH200 VALUES   ########
      SDI12Recorder(CH200_M0(),3,CH200_SDI12_Address,"MC!",1,0,-1)

      'Error trap readings obtained from CH200.  
      If CH200_M0(7)= "NAN" Then
         CH200_M0(7)= 5
      EndIf

      If CH200_M0(8)= "NAN" Then
         CH200_M0(8)= 3
      EndIf

      If CH200_M0(9)= "NAN" Then
         CH200_M0(9)= 2
      EndIf

      'Array values start with one. Values for charge state start with -1.
      'Have to shift the value by two to line it up with the correct words
      'in the array.
      ChargeState = ChargeStateArr(Chg_State + 2)

      'Values for charge source start with zero. Have to shift the value
      'by one to line it up with the correct words in the array.
      ChargeSource = ChargeSourceArr(Chg_Source + 1)

      '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)


      '########   CH200 BATTERY CHARGER - GET EXTENDED STATUS VALUES  ########
      SDI12Recorder(CH200_MX(),3,CH200_SDI12_Address,"M6!",1,0,-1)

      '########   MEASURE AND RECORD CURRENT USAGE BY STATION IN AMP-HOURS   ########
      'Add up the current being consumed by the system. Include battery current in
      'the calculation ONLY when it's 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) * CH200Scan/3600
      Next n

      'Calculate total amount of current entering CH200
      I_In_Chg_Amp_hr = I_in_chg * CH200Scan/3600


      '########   CLEAR QLOSS VALUE IF NOT ZERO   ########
      'If Clear_QLoss is set to true then set QLoss in the CH200 to zero.
      If Clear_QLoss = On Then
         Clear_QLoss = Off
         SDI12Recorder(CH200_SDI12Result,3,CH200_SDI12_Address,"XRQ!",1,0,-1)
      EndIf


      '########   SET BATTERY CAPACITY TO USER SPECIFIED VALUE   ########
      'If the present battery capacity isn't the same as the new battery capacity then send the new one to the charger.
      If BattCap <> CyclicBattCap Then
         CH200_SDI12Command = "XC" & FormatFloat (CyclicBattCap,"%4.1f") & "!"
         SDI12Recorder(CH200_SDI12Result,3,CH200_SDI12_Address,CH200_SDI12Command,1.0,0,-1)
      EndIf

      'Set various counters to 0 each scan
      Counts_Charge_State_None =  0
      Counts_Charge_State_Current_Ltd =  0
      Counts_Charge_State_Cyclic =  0
      Counts_Charge_State_Float =  0

      Counts_Charge_Source_None =  0
      Counts_Charge_Source_Solar =  0
      Counts_Charge_Source_Continuous =  0

      'Determine current Charge State and Charge Source and set to 1 for counting purposes
      Select Case Chg_State
      Case 0
         Counts_Charge_State_None =  1
      Case  1
         Counts_Charge_State_Current_Ltd = 1
      Case  2
         Counts_Charge_State_Cyclic = 1
      Case  3
         Counts_Charge_State_Float = 1
      EndSelect

      Select Case Chg_Source
      Case 0
         Counts_Charge_Source_None = 1
      Case  1
         Counts_Charge_Source_Solar = 1
      Case  2
         Counts_Charge_Source_Continuous = 1
      EndSelect

      '@@@@@@@@@@@@@@@@@@@@@@    END CH200 Battery Section  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

      '@@@@@@@@@@@@@@@@@@@@@@@@@   OUTPUT SECTION   @@@@@@@@@@@@@@@@@@@@@@@@@
      'Call Data Tables and Store Data
      CallTable Amp_5min
      CallTable Amp_Hr
      CallTable Amp_Day


   NextScan  

EndProg


JDavis Feb 2, 2018 03:27 PM

I think you are getting the variable out of bounds when your charge state is NAN.

Log in or register to post/reply in the forum.