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.

CR800 Remotely Controled ISCO Timed Sampling


brianjastram Nov 10, 2022 10:29 PM

I'm trying to use a CR800 to control an ISCO sampler to collect one sample per hour.

I've been trying to merge two CR Basic programs to accomplish this goal. I currently use one to control an ISCO sampler for flow paced sampling (see code below). The other program I found on this forum (https://www.campbellsci.com/forum?forum=1&l=thread&tid=1641) is designed to control a sampler based on one sample per hour. Maybe there is an easy way to repurpose the program I currently use to change the enable level and begin time based sampling.

Here is the program that I'm using now for flow paced sampling. Any ideas for adjusting this to accomplish hourly sample collection are much appreciated.

 

'CR800 Series Datalogger
'***********************
'NOTE:  1.2NE Pakbus Address is 7
'***********************
'Brian Jastram - MWMO - 10-29-19, 12/10/2021
'***********************
PreserveVariables
'Declare Variables and Units
Const RainPerTip = 0.01
Const ISCO6712port = Com1

Public CSI_Batt
Public ISCO_Batt
Public LoggerTemp
Public ISCO_Data(50) As String * 20
Public ISCO_Instring As String * 1000
Public ISCO_Bottle(3) As String * 3
Public ISCO_Bottle1 As Long  'Integer version of ISCO_Bottle(1) string
Public ISCO_BottleTime(3) As String * 20
Public ISCO_TodaysRain As Long
Public ISCO_Checksum As Long
Public ISCO_Description As String * 20
Public ISCO_Flow
Public ISCO_ID As String *20
Public ISCO_Level
Public ISCO_Model As String * 10
Public ISCO_YesterdaysRain
Public ISCO_Rain
Public ISCO_RainTips As Long
Public LastRainTips As Long
Public ISCO_EnableState As Boolean
Public ISCO_Time As String * 20
Public ISCO_Velocity
Public ISCO_Volume
Public Last_ISCO_Volume
Public ISCO_Volume_LastSample
Public VolumeBetweenSamples_ft3
Public VolumeBetweenSamples
Public ISCO_Level_Threshold_ft
Public ISCO_Level_Threshold
Public ISCO_Volume_Reset As Boolean
Public ISCO_Sampling_Enabled As Boolean
Public SampleOnEnable As Boolean
Public ISCO_VelSigStrength
Public ISCO_VelSpecStrength
Public NextEmptyBottleNum As Long
Public NextEmptyBottleStr As String * 2
Public SampleVolume As String * 3
Public SampleRequest As Boolean
Public SamplesTaken As Long
Dim I As Long
Public ChargingISCOBattery As Boolean
Public Nighttime As Boolean
Public YSIAttached As Boolean
Public ISCOCommFailure As Boolean

'following added for conductivity
Public ConductivityAttached As Boolean
Public Rcable, Rp, CellConstant, TempCoef
Public Rs, Ct
Public TempDeg_C
Public C25mScm_1
Units Ct=mS/cm
Units C25mScm_1=mS/cm
Units TempDeg_C=Deg C
Dim OneOvrRs

'variables for 2150 AV probe and Modbus
Const AV2150port = ComRS232

Dim ISCOregister(138) As Long
Public AV2150Attached As Boolean
Public ModuleName As String * 38
Public ModelNumber As String * 8
Public AV2150TakeReadingFlag As Long
Public AV2150Temp
Public AV2150Volts
Units AV2150Temp = Deg C
Units AV2150Volts = Volts
'the following ???StatTime(7) arrays are a combination of the Status (???StatTime(1)) and the 6 integer time (???StatTime(2-7))
Public LevelStatTime(7) As Long
Public VelocityStatTime(7) As Long
Public FlowStatTime(7) As Long
Public VolumeStatTime(7) As Long
Public AV2150TempStatTime(7) As Long
Public AV2150VoltsStatTime(7) As Long
Public ModbusResultModel As Long
Public ModbusResultTakeReadingWrite As Long
Public ModbusResultTakeReadingRead As Long
Public ModbusResultLevel As Long
Public ModbusResultLevelStatTime As Long
Public ModbusResultVelocity As Long
Public ModbusResultVelocityStatTime As Long
Public ModbusResultFlow As Long
Public ModbusResultFlowStatTime As Long
Public ModbusResultVolume As Long
Public ModbusResultVolumeStatTime As Long
Public ModbusResultTemp As Long
Public ModbusResultTempStatTime As Long
Public ModbusResultVolts As Long
Public ModbusResultVoltsStatTime As Long
Public AV2150CommFailure As Boolean

Units ISCO_Bottle()=Bottle#
Units ISCO_BottleTime()=Date&Time
Units ISCO_TodaysRain=Tips
Units ISCO_Flow=M^3/S
Units ISCO_Level=Meters
Units ISCO_YesterdaysRain=Tips
Units ISCO_Rain=Inches
Units ISCO_RainTips=Tips
Units ISCO_Time=Date&Time
Units ISCO_Velocity=M/S
Units ISCO_Volume=M^3
Units Last_ISCO_Volume=M^3
Units ISCO_Volume_LastSample=M^3
Units VolumeBetweenSamples_ft3=ft^3
Units VolumeBetweenSamples=M^3
Units ISCO_Level_Threshold_ft=ft
Units ISCO_Level_Threshold=M
Units ISCO_VelSigStrength=%
Units ISCO_VelSpecStrength=%
Units ISCO_Batt=Volts

Units CSI_Batt=Volts
Units LoggerTemp=Deg C

'Define Data Tables
DataTable(ISCOData,True,-1)
  DataInterval(0,5,Min,10)
  Sample(1,CSI_Batt,FP2)
  Sample(1,ISCO_Batt,FP2)
  Sample(1,ISCO_Bottle(),String)
  Totalize(1,ISCO_Rain,FP2,False)
  Average(1,ISCO_Level,FP2,ISCO_Level=NaN)
  Average(1,ISCO_Velocity,FP2,ISCO_Velocity=NaN)
  Totalize(1,SamplesTaken,UINT2,False)'added to be able to count samples during DataInterval in systems with AV2150
  Average(1,LoggerTemp,FP2,LoggerTemp=NaN)
  Sample(1,ISCO_Level_Threshold_ft,FP2)
  Sample(1,VolumeBetweenSamples_ft3,IEEE4)
  Totalize(1,AV2150CommFailure,FP2,False)
EndTable

DataTable (Conductivity,True,-1)  'conductivity measurements
  DataInterval(0,5,Min,10)
  Average (1,Ct,FP2,False)
  Average (1,TempDeg_C,FP2,False)
  Average (1,C25mScm_1,FP2,False)
EndTable

DataTable(BatteryData,True,-1)
  DataInterval(0,6,Hr,10)
  Minimum(1,CSI_Batt,FP2,False,False)
  Minimum(1,ISCO_Batt,FP2,False,False)
  Totalize(1,ChargingISCOBattery,FP2,False)
EndTable

'Define Subroutines
Sub OpenISCOComm
  ISCOCommFailure=False
  SerialOpen(ISCO6712port,9600,0,0,10000)
  SerialOut(ISCO6712port,CHR(13)+CHR(10),"",0,100)  'see if 6712 is awake
  SerialIn(ISCO_Instring,ISCO6712port,10,">",200)  'if response is a prompt, 6712 is awake.  If not...
  If ISCO_Instring="" Then  'wakeup 6712 by sending ?'s 1 sec apart
    For I = 1 To 10
      SerialOut(ISCO6712port,"?","",1,100)  'send ?'s 1 sec apart
      SerialIn(ISCO_Instring,ISCO6712port,10,-1,200)  'look for any response
      If ISCO_Instring<>"" Then ExitFor  'ISCO is awake
      If I = 10 Then ISCOCommFailure=True    'ISCO never responded to ?'s
    Next I
    SerialOut(ISCO6712port,CHR(13)+CHR(10),"",0,100)  'send 
    SerialIn(ISCO_Instring,ISCO6712port,50,">",200)  '6712 responds with prompt
  EndIf
EndSub

Sub SendISCOCommand(Command As String * 20, TerminationChar As Long)
  SerialOut(ISCO6712port,Command+CHR(13)+CHR(10),"",1,100)
  SerialIn(ISCO_Instring,ISCO6712port,50,TerminationChar,500)
  ISCO_Instring=Right(ISCO_Instring,Len(ISCO_Instring)-1)  'strip LineFeed character from beginning of string
EndSub

Sub CloseISCOComm
  SerialClose(ISCO6712port)
EndSub

Sub ProcessISCOData
  Dim Bottle As Long

  SplitStr (ISCO_Data(),ISCO_Instring,",",50,5)
  Bottle=1
  For I = 1 To 49 Step 2
    If Left(ISCO_Data(I),1)="B" Then
      ISCO_Bottle(Bottle)=Mid(ISCO_Data(I),2,2)
      ISCO_BottleTime(Bottle)=ISCO_Data(I+1)
      Bottle=Bottle+1
    EndIf
    ISCO_Bottle1=ISCO_Bottle(1)   'Integer version of ISCO_Bottle(1) string
    If ISCO_Data(I)="CR" Then ISCO_TodaysRain=ISCO_Data(I+1)
    If ISCO_Data(I)="CS" Then ISCO_Checksum=ISCO_Data(I+1)
    If ISCO_Data(I)="DE" Then ISCO_Description=ISCO_Data(I+1)
    If ISCO_Data(I)="FL" Then ISCO_Flow=ISCO_Data(I+1)
    If ISCO_Data(I)="ID" Then ISCO_ID=ISCO_Data(I+1)
    If ISCO_Data(I)="LE" Then ISCO_Level=ISCO_Data(I+1)
    If ISCO_Data(I)="MO" Then ISCO_Model=ISCO_Data(I+1)
    If ISCO_Data(I)="PR" Then ISCO_YesterdaysRain=ISCO_Data(I+1)
    If ISCO_Data(I)="RA" Then ISCO_RainTips=ISCO_Data(I+1)
    If ISCO_Data(I)="SS" Then ISCO_EnableState=ISCO_Data(I+1)
    If ISCO_Data(I)="TI" Then ISCO_Time=ISCO_Data(I+1)
    If ISCO_Data(I)="VE" Then ISCO_Velocity=ISCO_Data(I+1)
    If ISCO_Data(I)="VO" Then ISCO_Volume=ISCO_Data(I+1)
    If ISCO_Data(I)="VSI" Then ISCO_VelSigStrength=ISCO_Data(I+1)
    If ISCO_Data(I)="VSP" Then ISCO_VelSpecStrength=ISCO_Data(I+1)
  Next I
  If ISCO_RainTips 0 Then
    AV2150CommFailure = True    'AV2150 never responded
    ExitSub  '2150 didn't respond
  Else
    AV2150CommFailure = False    'AV2150 responded
  EndIf
  ' AV2150TakeReadingFlag = 1   'Set the flag to take a set of readings on demand
  AV2150TakeReadingFlag = 2  'Set the flag to cause an automatic, 15 second update of readings
  ModbusMaster (ModbusResultTakeReadingWrite,AV2150port,9600,2,6,AV2150TakeReadingFlag,25,1,20,40,10)  'Write Take Reading Flag to register 25
  ModbusMaster (ModbusResultTakeReadingRead,AV2150port,9600,2,3,AV2150TakeReadingFlag,25,1,20,40,11)  'Read take reading flag from register 25
  ModbusMaster (ModbusResultLevel,AV2150port,9600,2,3,ISCO_Level,40,1,20,40,12)  'Level
  ModbusMaster (ModbusResultLevelStatTime,AV2150port,9600,2,3,LevelStatTime(),42,7,20,40,11)  'Level Status & Time
  ModbusMaster (ModbusResultVelocity,AV2150port,9600,2,3,ISCO_Velocity,55,1,20,40,12)  'Velocity
  ModbusMaster (ModbusResultVelocityStatTime,AV2150port,9600,2,3,VelocityStatTime(),57,7,20,40,11)  'Velocity Status & Time
  ModbusMaster (ModbusResultFlow,AV2150port,9600,2,3,ISCO_Flow,70,1,20,40,12)  'Flow
  ModbusMaster (ModbusResultFlowStatTime,AV2150port,9600,2,3,FlowStatTime(),72,7,20,40,11)  'Flow Status & Time
  ModbusMaster (ModbusResultVolume,AV2150port,9600,2,3,ISCO_Volume,100,1,20,40,12)  'Volume
  ModbusMaster (ModbusResultVolumeStatTime,AV2150port,9600,2,3,VolumeStatTime(),102,7,20,40,11)  'Volume Status & Time
  ModbusMaster (ModbusResultVolts,AV2150port,9600,2,3,AV2150Volts,130,1,20,40,12)  'Voltage
  ModbusMaster (ModbusResultVoltsStatTime,AV2150port,9600,2,3,AV2150VoltsStatTime(),132,7,20,40,11)  'Voltage Status & Time
  ModbusMaster (ModbusResultTemp,AV2150port,9600,2,3,AV2150Temp,145,1,20,40,12)  'Temperature
  ModbusMaster (ModbusResultTempStatTime,AV2150port,9600,2,3,AV2150TempStatTime(),147,7,20,40,11)  'Temperature Status & Time
EndSub

Sub SetBatteryCharging  'Note: Setting SW12 high sends solar output to ISCO battery
  If ChargingISCOBattery=False Then
    VoltSe(ISCO_Batt,1,mV5000,1,False,0,_60Hz,.003712,0)  '1:3.2 divider (10k, 22k resistors), output in volts
    SW12(1)  'Direct charging to ISCO Battery
    ChargingISCOBattery=True
    Delay (0,30,Sec)
    Battery(CSI_Batt)
  Else
    Battery(CSI_Batt)
    SW12(0)  'Direct charging to CSI Battery
    ChargingISCOBattery=False
    Delay (0,30,Sec)
    VoltSe(ISCO_Batt,1,mV5000,1,False,0,_60Hz,.003712,0)  '1:3.2 divider (10k, 22k resistors), output in volts
  EndIf
  If CSI_Batt<12.2 OR ISCO_Batt>12.4 OR Nighttime Then
    SW12(0)  'Direct charging to CSI Battery
    ChargingISCOBattery=False
  Else
    SW12(1)  'Direct charging to ISCO Battery
    ChargingISCOBattery=True
  EndIf
EndSub

Sub MeasureConductivity
  BrFull(Rs, 1, mV2500, 3, VX1, 1, 2500, True, True, 0, 250, -0.001, 1)
  Rs = 1*Rs/(1.0-Rs)
  Select Case Rs
  Case Is < 1.8
    BrHalf(Rs, 1, mV2500, 6, VX1, 1, 2500, True, 0, 250, 1, 0)
    Rs = (Rs/(1-Rs))
  Case Is < 9.25
    BrFull(Rs, 1, mV2500, 3, VX1, 1, 2500, True, True, 0, 250, -0.001, 1)
    Rs = Rs/(1-Rs)
  Case Is < 280
    BrFull(Rs, 1, mV250, 3, VX1, 1, 2500, True, True, 0, 250, -0.001, 1)
    Rs = Rs/(1-Rs)
  EndSelect
  Rp = -Rcable * (0.000032) - 0.005
  Rs = Rs + Rp
  OneOvrRs = 1 / Rs
  Ct = OneOvrRs * CellConstant
  If (Ct < 0.474) Then
    Ct = (Ct * 0.95031) - 0.00378
  Else
    Ct = -0.02889 + 0.98614 * Ct + 0.02846 * Ct^2
  EndIf
  Therm107 (TempDeg_C,1,3,Vx2,0,_60Hz,1,0)
  C25mScm_1 = (Ct * 100)/(((TempDeg_C-25) * TempCoef) + 100)
EndSub

'Main Program
BeginProg
  AV2150Attached = False
  YSIAttached = False
  ConductivityAttached = False
  SampleVolume = "950"'ml
  SampleOnEnable = True
  'VolumeBetweenSamples_MGal = 0.08'Million Gallons = 300m^3  'note 283.2m^3 = 10000 ft^3
	VolumeBetweenSamples_ft3 = 20000'ft^3 = 560m^3
  ISCO_Level_Threshold_ft = 0.5'ft  'will reset to this when program starts
  'Conductivity:  Evaluate and edit each of these 3 user specific values
  Rcable=40 'edit this value to the actual footage of cable on your sensor
  CellConstant=1.417 'edit this value with the Cell Constant (Kc) printed on the label of each sensor
  TempCoef=2 'see section 9 of the manual for an explanation of how to more precisely determine the value of this coefficient
  Scan(1,Min,1,0)
    ISCO_Level = NaN
    ISCO_Velocity = NaN
    SamplesTaken = 0
    GetISCOData
    If AV2150Attached Then Get2150Data
    VolumeBetweenSamples = VolumeBetweenSamples_ft3 * 0.0283168  'convert to M^3
    ISCO_Level_Threshold = ISCO_Level_Threshold_ft * .3048  'convert to M
    If NOT (ISCO_Volume_LastSample > 0 OR ISCO_Volume = NaN) Then ISCO_Volume_LastSample = ISCO_Volume  'trap for ISCO_Volume_LastSample = 0 or NaN
    If ISCO_Volume < Last_ISCO_Volume - 300 Then   'if volume drops by more than 300m^3 (~10,000ft^3) in 5 minutes, means volume accumulator was reset
      ISCO_Volume_LastSample = ISCO_Volume_LastSample-Last_ISCO_Volume  'this makes ISCO_Volume_LastSample a negative number
      ISCO_Volume_Reset = True
    EndIf
    If ISCO_Level >= ISCO_Level_Threshold Then  'Sampling is enabled
      If ISCO_Volume - ISCO_Volume_LastSample >= VolumeBetweenSamples Then 'More than VolumeBetweenSamples has passed since last sample
        If NOT ISCO_Sampling_Enabled Then  'ISCO_Level just exceeded Threshold and more than VolumeBetweenSamples has passed
          If SampleOnEnable Then TakeSample
        Else  'ISCO_Level had previously exceeded Threshold and more than VolumeBetweenSamples has passed
          TakeSample
        EndIf
        ISCO_Volume_LastSample = ISCO_Volume  'reset logger volume accumulator
      EndIf
      ISCO_Sampling_Enabled = True  'ISCO_Level >= ISCO_Level_Threshold
    Else
      ISCO_Sampling_Enabled = False  'ISCO_Level < ISCO_Level_Threshold
    EndIf
    If ISCO_Volume > 0 Then Last_ISCO_Volume = ISCO_Volume 'Trap for ISCO_Volume=NaN which will cause ISCO_Volume_Reset to fail
    If ConductivityAttached Then
      MeasureConductivity
      CallTable(Conductivity)
    EndIf
    If SampleRequest Then TakeSample
    PanelTemp (LoggerTemp,_60Hz)
    CallTable(ISCOData)
  NextScan

  SlowSequence
  Scan (1,Hr,0,0)
    If TimeIntoInterval(7,24,hr) Then Nighttime=False
    If TimeIntoInterval(19,24,hr) Then Nighttime=True
    'Uncomment the next line for solar powered sites
    SetBatteryCharging
    'Uncomment the next 2 lines for 110VAC powered sites
    'VoltSe(ISCO_Batt,1,mV5000,1,False,0,_60Hz,.003712,0)  'Measure ISCO battery voltage thru 1:3.7 divider (10k, 27k resistors)
    'Battery(CSI_Batt)
    CallTable(BatteryData)
  NextScan

EndProg

 


JDavis Nov 15, 2022 05:57 PM

This is an example program I wrote that can do flow paced or time paced. Constants are used to set the mode. It has been six years since I wrote it, so you will need to read the comments in the program to know how to use it.

 

'Example program for different types of sampler control
'date: June 17, 2016
'program author: Jacob Davis, CSI

ConstTable (Configuration)
  'ISCO Serial
  Const ISCO_Comport = Com1

EndConstTable

PreserveVariables  'This is the simplest way to ensure continued operation after power interruption


Dim rTime(9) As Long
Alias rTime(8) = rDayOfWeek
Alias rTime(4) = rHourOfDay
Alias rTime(5) = rMinute
Dim tempInt As Long

Public ResetSamplingSchedule As Boolean = False 'Manually set this to reset bottle numbers etc. Usually set after changing bottles in sampler.
Public EnableSamplerControl As Boolean = False 'Manually set this to true when all parameters are set and you are ready for the datalogger to take over.
'#######Enabling Event#########
Dim ScheduleEnabled As Boolean = False
'Delayed Start
Public DelayStart As Boolean = False 'True to use delay start, false to not delay
Public StartDayOfWeek As Long = 1 '1 is Sunday. These correspond to day of week from realtime
Public StartHHMM As Long = 1200 'Enter as 24 hour time

'Threshold Trigger
Public WaterLevel 'A different parameter could be used to trigger off of, but requires changing code within the body of the program
Public StartThreshold = 1.0
Dim ThresholdGood As Boolean

'Disabling Condition
Public StopThreshold = 0.5


'#######Pacing Control#########
Public TakeSampleAtStartOfInterval As Boolean 'Collect a sample at the beginning of the first interval?
Dim firstSampleTaken As Boolean 'Keeps track of if first sample was taken
Public NumberOfInstalledBottles As Long '1 if composite
Public BottlesPerEvent As Long 'Number of bottles to use per event
Dim remainingBottlesThisEvent As Long
Public VolumePerSample As Long 'Volume to put in each bottle
Public MaxSamples As Long = 24 'Total number of samples to collect before disabling sampler
Dim samplesTaken As Long
Dim TakeASample As Boolean 'True when you should start taking a sample this scan

Const TimePaced = True
Const FlowPaced = False
Public PacingMode As Boolean = True
'TODO, add easy to understand way for changing the pacing mode.

'Time Paced
Public MinutesBetweenSamples As Long
Public IntervalOffset As Long 'Minutes into the interval to use as an offset

'Flow Paced
Public WaterFlow
Public FlowBetweenSampleEvents
Dim accumulatedFlow

'#######Sampler Control########
Public CurrentBottleNumber As Long

'CSI Smart, ISCO 10164-L cable, or ISCO serial



'ISCO serial
Public ISCO_WaterLevel, ISCO_Flow
Public LastBottle As Long, LastVolume As Long
Public ISCO_SampleCode As Long, ISCO_SampleStatus As String * 20
Public ISCO_StatusCode As Long, ISCO_Status As String * 20




'Declare Public Variables
'Example:
Public PTemp, batt_volt

'Declare Other Variables
'Example:
'Dim Counter

'Define Data Tables.
DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate.
  DataInterval (0,15,Min,10)
  Minimum (1,batt_volt,FP2,False,False)
  Sample (1,PTemp,FP2)
EndTable

Sub ISCO_GetStatus(_Comport As Long,_BottleCode As Long, _SampleVolume As Long, _LastSampleStatus As Long, _CurrentStatus As Long) 'Will poll the sampler for the current status
  Dim serialResponse As String * 256
  Dim lBytesBack As Long
  Dim lString(18) As String
  Dim lk As Long

  '  send out repeated ? until you get the > prompt

  lBytesBack = SerialOut (_Comport,"?",">",20,10)

  'TODO, don't have feedback for failed request. All values currently left as is if failed.

  If lBytesBack Then 'Received the prompt
    SerialOut (_Comport,CHR(13),">",1,100)
    SerialFlush(_Comport)
    '  command  STS,2
    SerialOut (_Comport,"STS,2" & CHR(13),"",1,100) 'Command is echoed back. Wait for the echo
    SerialIn (serialResponse,_Comport,200,13,256)
    SplitStr (lString(),serialResponse,",",18,5)

    For lk = 1 To 17
      If InStr (1,lstring(lk),"STS",2) Then
        _CurrentStatus =  lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"BTL",2) Then
        _BottleCode = lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"SVO",2) Then
        _SampleVolume =  lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"SOR",2) Then
        _LastSampleStatus = lstring(lk + 1)
      EndIf
    Next lk
  Else
    'Failed to get prompt
  EndIf
EndSub

Sub ISCO_GetData(_Comport As Long,_BottleCode As Long, _SampleVolume As Long, _LastSampleStatus As Long, _CurrentStatus As Long, _WaterLevel As Float, _Flow As Float) 'Will poll the sampler for the current status and sensor data
  Dim serialResponse As String * 256
  Dim lBytesBack As Long
  Dim lString(56) As String
  Dim lk As Long

  '  send out repeated ? until you get the > prompt

  lBytesBack = SerialOut (_Comport,"?",">",20,10)

  'TODO, don't have feedback for failed request. All values currently left as is if failed.

  If lBytesBack Then 'Received the prompt
    SerialOut (_Comport,CHR(13),">",1,100)
    SerialFlush(_Comport)
    '  command  STS,2
    SerialOut (_Comport,"DATA" & CHR(13),"",1,100) 'Command is echoed back. Wait for the echo
    SerialIn (serialResponse,_Comport,200,13,256)
    SplitStr (lString(),serialResponse,",",56,5)

    For lk = 1 To 55
      If InStr (1,lstring(lk),"STS",2) Then
        _CurrentStatus =  lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"BTL",2) Then
        _BottleCode = lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"SVO",2) Then
        _SampleVolume =  lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"SOR",2) Then
        _LastSampleStatus = lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"FL",2) Then
        _Flow = lstring(lk + 1)
      EndIf
      If InStr (1,lstring(lk),"LE",2) Then
        _WaterLevel = lstring(lk + 1)
      EndIf
    Next lk
  Else
    'Failed to get prompt
  EndIf
EndSub

Sub ISCO_TakeSample(_Comport As Long, _BottleNumber As Long, _Volume As Long) 'Will trigger a sample on the specified bottle number and volume
  Dim lBytesBack As Long
  Dim _outCommand As String
  '  send out repeated ? until you get the > prompt
  lBytesBack = SerialOut (_Comport,"?",">",20,10)
  If lBytesBack Then
    SerialOut (_Comport,CHR(13),">",1,100)
    SerialFlush(_Comport)
    '  command  BTL,2,SVO,200
    _outCommand = "BTL," & FormatLong (_BottleNumber,"%u") & ",SVO," & FormatLong(_Volume,"%u") & CHR(13)
    SerialOut (_Comport,_outCommand,"",0,0)
    'This sub doesn't wait for a response. Request the status later to see if the sample was successful.
  EndIf
EndSub

Function ISCO_ConvertStatusCode(SamplerStatusCode As Long) As String * 20
  Select Case SamplerStatusCode
  Case 1
    Return "Waiting for Sample"
  Case 4
    Return "Power Failed"
  Case 5
    Return "Pump Jammed"
  Case 6
    Return "Distributor Jammed"
  Case 9
    Return "Sampler Off"
  Case 12
    Return "Sample in Progress"
  Case 20
    Return "Invalid Command"
  Case 21
    Return "Checksum Mismatch"
  Case 22
    Return "Invalid Bottle"
  Case 23
    Return "Volume Out of Range"
  Case Else
    Return "Invalid Code"
  EndSelect
EndFunction

Function ISCO_ConvertSampleCode(SampleStatusCode As Long) As String * 20
  Select Case SampleStatusCode
  Case 0
    Return "Sample OK"
  Case 1
    Return "No Liquid Found"
  Case 2
    Return "Liquid Lost"
  Case 3
    Return "User Stopped"
  Case 4
    Return "Power Failed"
  Case 5
    Return "Pump Jammed"
  Case 6
    Return "Distributor Jammed"
  Case 8
    Return "Pump Latch Open"
  Case 11
    Return "No Distributor"
  Case 12
    Return "Sample in Progress"
  Case Else
    Return "Invalid Code"
  EndSelect
EndFunction




'Main Program
BeginProg

  'ISCO Serial
  SerialOpen (ISCO_Comport,9600,3,0,256) 'Configure the comport
  'Sending the request status message will turn on the sampler.
  Call  ISCO_GetStatus(ISCO_Comport, LastBottle,LastVolume, ISCO_SampleCode,ISCO_StatusCode) 'Will poll the sampler for the current status


  Scan (1,Min,0,0)
    PanelTemp (PTemp,250)
    Battery (batt_volt)
    'Enter other measurement instructions

    'Read Status from Sampler
    Call  ISCO_GetStatus(ISCO_Comport, LastBottle,LastVolume, ISCO_SampleCode,ISCO_StatusCode) 'Will poll the sampler for the current status

    'ISCO Serial
    Call  ISCO_GetData(ISCO_Comport, LastBottle,LastVolume, ISCO_SampleCode,ISCO_StatusCode,ISCO_WaterLevel,ISCO_Flow) 'Will poll the sampler for the current status
    WaterLevel = ISCO_WaterLevel
    WaterFlow = ISCO_Flow

    ISCO_SampleStatus = ISCO_ConvertSampleCode(ISCO_SampleCode)
    ISCO_Status = ISCO_ConvertStatusCode(ISCO_StatusCode)

    'Manual reset of sampling control
    If ResetSamplingSchedule Then
      ResetSamplingSchedule = False
      EnableSamplerControl = False
      CurrentBottleNumber = 0
      TakeASample = False
      ScheduleEnabled = False
      ThresholdGood = False
      samplesTaken = 0
      firstSampleTaken = False
      accumulatedFlow = 0
      remainingBottlesThisEvent = 0
    EndIf 'ResetSamplingSchedule

    '#######Enabling Event#########
    'Delayed Start
    RealTime(rTime)
    tempInt = rHourOfDay * 100 + rMinute 'HHMM
    If DelayStart Then
      If EnableSamplerControl Then
        If (tempInt > StartHHMM) AND (StartDayOfWeek = rDayOfWeek) Then
          ScheduleEnabled = true
        EndIf
      Else
        ScheduleEnabled = false
      EndIf 'EnableSamplerControl
    Else
      If EnableSamplerControl Then
        ScheduleEnabled = true
      Else
        ScheduleEnabled = false
      EndIf  'EnableSamplerControl
    EndIf ' DelayStart
    'Threshold Trigger
    If WaterLevel > StartThreshold Then ThresholdGood = true

    'Disabling Condition
    If WaterLevel < StopThreshold Then ThresholdGood = false


    '#######Pacing Control#########
    'Time Paced or Flow Paced
    If ScheduleEnabled AND ThresholdGood Then
      If TakeSampleAtStartOfInterval AND firstSampleTaken = false Then
        'Sample trigger for first sample after enabled
        firstSampleTaken = true
        TakeASample = true
      EndIf
      'Time paced
      If PacingMode = TimePaced Then
        'Time Paced
        If TimeIntoInterval (IntervalOffset,MinutesBetweenSamples,Min) Then TakeASample = True
      Else
        'Flow Paced
        '!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!
        'The time units on the flow and the scan time must be compensated for
        'If the scan is 1 minute, and the flow is gpm, you get lucky and end up with gallons
        accumulatedFlow += WaterFlow
        If accumulatedFlow > FlowBetweenSampleEvents Then
          accumulatedFlow -= FlowBetweenSampleEvents
          TakeASample = true
        EndIf
      EndIf 'Pacing Mode
    Else
      TakeASample = false
    EndIf 'ScheduleEnabled and ThresholdGood

    '#######Sampler Control########
    'CSI Smart, ISCO 10164-L cable, or ISCO serial

    'ISCO Serial
    If TakeASample Then
      TakeASample = false
      samplesTaken += 1

      If NumberOfInstalledBottles = 1 Then
        'Composite
        CurrentBottleNumber = 1
      Else
        'Discrete
        If remainingBottlesThisEvent  <= 0 Then
          '0 , so first sample this event
          remainingBottlesThisEvent = BottlesPerEvent
        EndIf 'remainingBottlesThisEvent
        CurrentBottleNumber += 1
        remainingBottlesThisEvent -= 1 'Decrement for this sample
        If remainingBottlesThisEvent Then TakeASample = True 'Marks to take another sample next scan when there are remaining bottles
      EndIf

      If samplesTaken >= MaxSamples Then
        'Sampler will disable itself when it has filled all the bottles
        EnableSamplerControl = False
      EndIf

      'Trigger the sampler
      Call ISCO_TakeSample(ISCO_Comport, CurrentBottleNumber,VolumePerSample)

    EndIf


    'Call Output Tables
    'Example:
    CallTable Test
  NextScan
EndProg

 


brianjastram Nov 15, 2022 07:11 PM

Ok!

Thank you Jacob. I'll dig into this and let you know how it goes.


Plesubt Oct 30, 2024 09:08 AM

Sorry for bumping old thread. Any update?

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