I'm trying to count the number of times the CH200 is in each Charge State and Charge Source on an hourly and daily basis. As I understand the DataEvent command, I could perform this calculation but would need to create a data table for each of the 7 possible outcomes.
I would prefer these count values to be output in the same hourly and daily data tables that include many other CH200 parameters I process.
I was wondering if anyone had a suggestion that would allow me to accumulate the number of times the CH200 Charge Source is in No Charge, Current Limited, Cycle, Float and Charge Source is in None, AC, and Solar and to totalize each of these variables within tables that are called hourly and daily. Any suggestions would be greatly appreciate.
I developed the following solution to this question. There may (likely) be a more elegant way to count the number of occurences for each Charge State and Charge Source, but this worked for me so I thought I would share it so this question can be resolved.
'Date: 2017-10-19
'Purpose: Test CH200 Charge State Counter
Public BattV
Public PTemp_C
Dim i
'CH200
Public CH200_M0_MEM(9) 'Array to hold all the data coming from the CH200
Alias CH200_M0_MEM(1)=VBatt 'Battery voltage: VDC
Alias CH200_M0_MEM(2)=IBatt 'Current going into, or out of, the battery: Amps
Alias CH200_M0_MEM(3)=ILoad 'Current going to the load: Amps
Alias CH200_M0_MEM(4)=V_in_chg 'Voltage coming into the charger: VDC
Alias CH200_M0_MEM(5)=I_in_chg 'Current coming into the charger: Amps
Alias CH200_M0_MEM(6)=Chg_TmpC 'Charger temperature: Celsius
Alias CH200_M0_MEM(7)=Chg_State 'Charging state: Cycle, Float, Current Limited, or None
Alias CH200_M0_MEM(8)=Chg_Source 'Charging source: None, AC, or Solar
Alias CH200_M0_MEM(9)=Ck_Batt 'Check battery error: 0=normal, 1=check battery
'Variables for counting Charge State and 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 rTime(9) 'declare as public and dimension rTime to 9
Alias rTime(1) = Year 'assign the alias Year to rTime(1)
Alias rTime(2) = Month 'assign the alias Month to rTime(2)
Alias rTime(3) = DOM 'assign the alias DOM to rTime(3)
Alias rTime(4) = Hour 'assign the alias Hour to rTime(4)
Alias rTime(5) = Minute 'assign the alias Minute to rTime(5)
Alias rTime(6) = Second 'assign the alias Second to rTime(6)
Alias rTime(7) = uSecond 'assign the alias uSecond to rTime(7)
Alias rTime(8) = WeekDay 'assign the alias WeekDay to rTime(8)
Alias rTime(9) = Day_of_Year 'assign the alias Day_of_Year to rTime(9)
DataTable(SimCH200_10sec,True,-1)
DataInterval(0,10,Sec,10)
Sample(1,Counts_Charge_State_None,FP2)
Sample(1,Counts_Charge_State_Current_Ltd,FP2)
Sample(1,Counts_Charge_State_Cyclic,FP2)
Sample(1,Counts_Charge_State_Float,FP2)
Sample(1,Counts_Charge_Source_None,FP2)
Sample(1,Counts_Charge_Source_Solar,FP2)
EndTable
DataTable(SimCH200_1min,True,-1)
DataInterval(0,1,Min,10)
Totalize(1,Counts_Charge_State_None,FP2,False)
Totalize(1,Counts_Charge_State_Current_Ltd,FP2,False)
Totalize(1,Counts_Charge_State_Cyclic,FP2,False)
Totalize(1,Counts_Charge_State_Float,FP2,False)
Totalize(1,Counts_Charge_Source_None,FP2,False)
Totalize(1,Counts_Charge_Source_Solar,FP2,False)
EndTable
'Main Program
BeginProg
'Initialize random number generator using seconds since 1990 + microseconds in datalogger clock
Randomize(Status.Timestamp(1,1) + Status.Timestamp(7,1))
Scan(10,sec,1,0)
Battery(BattV)
PanelTemp(PTemp_C,60)
'create dummy data to simulate CH200
RealTime(rTime())
For i = 1 To 9
CH200_M0_MEM(i) = INT( 6 * RND + 0)
Next i
'Set each counter to 0 at the beginning of 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
'Evaluate current Charge State and Charge Source and parse into appropriate counter
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
EndSelect
CallTable SimCH200_1min
CallTable SimCH200_10sec
NextScan
EndProg