I am trying to use the "PreserveVariables" function, and have run into a problem with two of my variables. I am using a CR800 to control an ISCO sampler on a time based sampling scheme. To do this, I am using a timer and pulse counter as public variables:
Public ISCO_Pulse_Counter
Public ISCODelayTime
I need to use the PreserveVariables function in order to maintain my stage offset, however, this function essentially freezes my sampling routine. I can think of 2 options, but am open to any suggestions.
1. Deteremine a way, if possible, to keep ISCO_Pulse_Counter and ISCODelayTime active (somehow separate them from the "PreserveVariables" function.
2. Somehow move my Constants into public fields, however, I still want to manipulate the fields as needed, and have deault values in place.
Does anyone have suggestions?
Thanks
Here is my program:
'CR800
'Declare Constants
ConstTable
Const ISCO_TIMER = 1
Const ETI_Interval = 36000 'seconds
Const ETI_Pulses = 96 '1 sample per hour * 96 times = 4 day ETI
EndConstTable
'Declare Variables and Units
Public Batt_Volt
Public Act_stage
Public STGADJ
Public Cr800Temp_C
Public CS450_Stg
Public SFSTG_ft
Public Stage_avg
Public CS450(2)
Public CS650(3)
Public StageTimerActive As Boolean
Public ISCO_Pulse_Counter
Public ISCODelayTime
Alias CS450(1)=CS450_PS
Alias CS450(2)=CS450_WTemp
Alias CS650(1)=VolWatCon
Alias CS650(2)=ElecCondu
Alias CS650(3)=SoiltTemp
Units Batt_Volt=Volts
Units Cr800Temp_C=Deg C
Units CS450_Stg=feet
Units SFSTG_ft=feet
Units Stage_avg=feet
Units VolWatCon=m^3/m^3
Units ElecCondu=ds/m
Units SoiltTemp=C
Dim LogerTime(10)
	'1 - Year, 2 - Month, 3 - Day of Month, 4 - Hour, 5 - Minute
	'6 - Second, 7 - Microsecond, 8 - Day Of Week (Sunday = 1), 9 - Day of Yea
	
'Define Data Tables
DataTable(SR3_ETI_FLOW10,True,-1)
	DataInterval(0,10,Min,10)
	Average (1,Cr800Temp_C,FP2,False)
	Average(1,SFSTG_ft,IEEE4,False)
	Average(1,Stage_avg,IEEE4,False)
	Average (3,CS650(),FP2,False)
	Minimum(1,Batt_Volt,FP2,False,False)
	EndTable
	
DataTable (ETI_SampleOut, 1, -1)
	DataInterval (0, 0, Sec, 0)
	Sample (1, ISCO_Pulse_Counter, FP2)
EndTable
PreserveVariables
'Main Program
BeginProg
	Scan(60,Sec,1,0)
	  SW12 (1 )
	  'Default Datalogger Battery Voltage measurement Batt_Volt:
		Battery(Batt_Volt)
		'Wiring Panel Temperature measurement PTemp_C
		PanelTemp(Cr800Temp_C,_60Hz)
		'CS650 Soil Moisture Probe Generic SDI-12 Sensor measurements VolWatCon, ElecCondu, SoiltTemp,
		SDI12Recorder(CS650(),3,"0","M!",1,0)
		'CS450 Pressure Transducer Generic SDI-12 Sensor measurements
		SDI12Recorder (CS450,1,0,"M!",1.0,0)
		'Convert PS to Stage (ft)
		CS450_Stg=(CS450_PS)*2.31
	
		'Allows for stage offset to be adjusted  
		SFSTG_ft= (CS450_Stg) + (STGADJ)
		'Calculate 15 minute average stage to activate samplers
		AvgRun (Stage_avg,1,SFSTG_ft,10) 
      
    'ETI Sampling Routine
    If NOT StageTimerActive Then
    If (Stage_avg >= Act_stage) Then
    'pulse the port
     WriteIO (&B10,&B10) 'same as PortSet(2,1), but for conditional control
    Delay(1,1,Sec)
    WriteIO (&B10,&B00) 'same as PortSet(2,0), but for conditional control
    'Increment Isco pulse counter
    ISCO_Pulse_Counter = 1
    CallTable ETI_SampleOut
    'reset the Timer
    Timer(ISCO_TIMER,Sec,2)
    'Start the Timer
    'Activate Stage Timer
    StageTimerActive = True
    EndIf
    
     Else ' Once the Stage Timer is activated
    'Read Timer
    ISCODelayTime = Timer(ISCO_TIMER,Sec,4)
    'After 1 hour,
    If ISCODelayTime > ETI_Interval Then
    'pulse the port
    WriteIO (&B10,&B10) 'same as PortSet(2,1), but for conditional control
    Delay(1,1,Sec)
    WriteIO (&B10,&B00) 'same as PortSet(2,0), but for conditional control
    'Increment Isco pulse counter
    ISCO_Pulse_Counter = ISCO_Pulse_Counter+ 1
    CallTable ETI_SampleOut
    'reset the Timer
     Timer(ISCO_TIMER,Sec,2)
    EndIf
    EndIf
  
   'AFter desired number of samples collected, stop pulsing
    If (ISCO_Pulse_Counter >= ETI_Pulses) Then   
    'Clear the StageTimerActive (stops hourly pulsing continuing)
    StageTimerActive = False
    'Stop and clear the timer
    Timer(ISCO_TIMER,Sec,3)
    ISCO_Pulse_Counter = 0
    ISCODelayTime = 0
    EndIf
						
    CallTable(SR3_ETI_FLOW10)
	
	NextScan
EndProg
Instead of PreserveVariables, you might want to look into using the CalFile instruction, which will write values out to a file or read them back in.
So you could set your stage offset and write those out to a CalFile. Then write some "run once" code to read those values back in.
Dana W.