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.

CR1000X with RS232 EXO Sonde using subroutine, SDI-12 backup


Jay Aldrich Mar 10, 2021 05:26 PM

'CR1000X, can be adapted to CR6, RS232 Communication
'SONDE ALIAS/ASSIGNMENTS
Public SONDE (2)
Alias SONDE (1) = Water_Temp                   'Degrees Celsius (*C)
Alias SONDE (2) = Specific_Conductivity      'micro Siemens (uS/cm)
'Constants
Const Serial_Port = ComC5
Const high = true
Const low = false
'PUBLIC VARIABLES
Public Battery_Volt                                        'Campbell System power from main +12 volt battery.
Dim PanelTemp                                             'Internal temperature of data logger.
Units Battery_Volt = Volts_DC                       'System Battery Voltage measured in Volts, direct current.
Units PanelTemp = *C                                   'Internal Temperature of Data Logger measured in Degrees Centigrade.
'TRIGGER
Public Trigger (1) As Boolean                        'Allows a manual trigger of SDI-12 sensors.
Alias Trigger (1) = Trigger_Stage
'BAUD RATE
Public EXO_Baud_Rate_38400 As Boolean        'If baud rate is 38400 vs default 9600.
Public EXO_Baud_Rate
'EXO RS232 COUNTER
Dim Sonde_Data As String * 256               'Raw EXO data string comma delited.
Dim RS232_Count                                     'Counts internal RS232 skipped counts.
Public RS232_Counter                              'Counts if RS-232 was skipped and reran.
'DATA TABLES
DataTable (Station_Data,True,-1)
  DataInterval (0,900,Sec,10)
  Sample (1,SONDE (1),FP2)                     'WT
  Sample (1,SONDE (2),UINT2)                 'SC
EndTable
'EXO SUBROUTINE
Sub EXO
  SerialOpen (Serial_Port,EXO_Baud_Rate,0,0,2000,0)           'ComPort, Baud Rate
  SerialOut (Serial_Port,"0" + CHR(13),"?Command",3,10)       'ComPort, Output String (Charater 13 = ^M)
  Delay (1,500,mSec)
  SerialOut (Serial_Port,"data" + CHR(13) + CHR(10),"",1,0)    'Charater 10 = ^J, Line feed (LF).
  Delay (1,500,mSec)
  SerialIn (Sonde_Data,Serial_Port,100,&H0D0A,200)             'Destination (Raw EXO Data String)
  Erase SONDE()
  Sonde_Data = Trim(Sonde_Data)                                          'Copies String with no leading or trailing charaters.
  SplitStr (SONDE,Sonde_Data,",",2,0)                                    'Splits data by commas, # of parameters, numeric values.
  SerialFlush (Serial_Port)                                                        'Clears data from buffer
  SerialClose (Serial_Port)                                                        'Closes RS-232 ComPort
EndSub
'MAIN PROGRAM
BeginProg 
  SW12 (SW12_1,1)                                             'Power for RV-50 modem, normally on. Turns Switch +12 Volts on or off
  SW12 (SW12_2,1)                                             'Power for Signal Output Adapter (SOA), normally on. Turns Switch +12 Volts on or off
'GET EXO via RS232
SlowSequence
Scan (60,Sec,1,0)
'GET SONDE DATA, via RS-232
  If EXO_Baud_Rate_38400 = True Then                              'RS-232 baud rate on the Signal Output Adapter may be 38400.
  EXO_Baud_Rate = 38400
  EndIf
  If EXO_Baud_Rate_38400  = False Then                            'RS-232 default baud rate of 9600.
  EXO_Baud_Rate = 9600
  EndIf
  If IfTime (0,900,Sec) Then Trigger (1) = high
  If Trigger (1) Then
  Call EXO                                                                              'Calls EXO RS-232 subroutine.
  Trigger (1) = low
  Do                                                                                        'Starts loop, checks for sonde errors / WT = NAN
  If SONDE(1) <> NAN Then RS232_Count = 0                    'RS232 Count stays 0 is data is good.
  If SONDE(1) <> NAN Then ExitDo                                     'Exit DO Loop is data is good.
  If SONDE(1) = NAN Then                                                   'If the EXO WT reads NAN and the RS2323 Counter < 5
  RS232_Count = RS232_Count + 1                                    'Increment Pulse Counter by 1
  RS232_Counter = RS232_Count                                       'Makes internal RS-232 Count = RS232 Counter
  Delay (0,5,Sec)                                                                   'Delay in loop for EXO RS232 scan to allow the EXO
  If RS232_Count < 5 Then Call EXO                                   'Calls EXO RS-232 subrountine in loop, if NAN in WT.
  If RS232_Count = 0 Then ExitDo
  If RS232_Count = 5 Then ExitDo
  Loop
  EndIf
  EndIf
  If RS232_Count >= 5 Then SDI12Recorder (SONDE(),C3,1,"M!",1,0,-1)   'Calls EXO via SDI-12 if RS-232 fails
  If SONDE(1) = 0 Then SDI12Recorder (SONDE(),C3,1,"M!",1,0,-1)          'Calls EXO via SDI-12 if RS-232 fails
  RS232_Count = 0
  RS232_Counter = 0
'GET SYSTEM DATA
  Battery (Battery_Volt)
  PanelTemp (PanelTemp,_60Hz)
CallTable Station_Data
NextScan


Dana Mar 11, 2021 12:11 AM

Jay,

Thank you for sharing your code with the CS community!

Best, Dana


SophieS Sep 20, 2021 08:03 PM

Jay,

I'm trying to do a similar deployment, a Exo2 to a CR1000X via RS-232, and just can't get it to work. The sonde is connected to the datalogger through the SOA DCP Sonde then a four channel SDM-SIO1A Serial I/O Module, which is why the serialopen command is port 32. I've checked and rechecked all the wiring, and was hoping you could look at my code:

Public EXO(24) As String * 100,Recieved,NBytesReturned

'24 variables measured by EXO2 sonde

Alias EXO(1)=Chlorophyll
Alias EXO(2)=nLFCond
Alias EXO(3)=Pressure
Alias EXO(4)=Turbidity
Alias EXO(5)=Temp
Alias EXO(6)=Cond
Alias EXO(7)=D_OX
Alias EXO(8)=Sal
Alias EXO(9)=TSS
Alias EXO(10)=VerticalPosition
Alias EXO(11)=Depth
Alias EXO(12)=D_OX2
Alias EXO(13)=SpCond
Alias EXO(14)=WiperPosition
Alias EXO(15)=BPower
Alias EXO(16)=fDOM
Alias EXO(17)=D_OX3
Alias EXO(18)=Phycoerythrin
Alias EXO(19)=pH
Alias EXO(20)=CablePower
Alias EXO(21)=fDOM2
Alias EXO(22)=ORP
Alias EXO(23)=TDS
Alias EXO(24)=pH2

Units Chlorophyll=RFU
Units nLFCond=microSimens/cm
Units Pressure=psia
Units Turbidity=FNU
Units Temp=C
Units Cond=microSimens/cm
Units D_OX=%Sat
Units Sal=PSU
Units TSS=mg/L
Units VerticalPosition=m
Units Depth=m
Units D_OX2=%Local
Units SpCond=microSimens/cm
Units WiperPosition=volt
Units BPower=volt
Units fDOM=QSU
Units D_OX3=mg/L
Units Phycoerythrin=RFU
Units pH=pH
Units CablePower=volt
Units fDOM2=RFU
Units ORP=mV
Units TDS=mg/L
Units pH2=mV
'Units Cond_Temp=microSimens/cm
'Units fDOM=QSU,ppb
'Units D_OX3=mg/L
'Units Turb=NTU

DataTable (EXO,1,-1)
DataInterval (0,5,Sec,1)
Average (1,EXO(1),Float,0)
Average (1,EXO(2),Float,0)
Average (1,EXO(3),Float,0)
Average (1,EXO(4),Float,0)
Average (1,EXO(5),Float,0)
Average (1,EXO(6),Float,0)
Average (1,EXO(7),Float,0)
Average (1,EXO(8),Float,0)
Average (1,EXO(9),Float,0)
Average (1,EXO(10),Float,0)
Average (1,EXO(11),Float,0)
Average (1,EXO(12),Float,0)
Average (1,EXO(13),Float,0)
Average (1,EXO(14),Float,0)
Average (1,EXO(15),Float,0)
Average (1,EXO(16),Float,0)
Average (1,EXO(17),Float,0)
Average (1,EXO(18),Float,0)
Average (1,EXO(19),Float,0)
Average (1,EXO(20),Float,0)
Average (1,EXO(21),Float,0)
Average (1,EXO(22),Float,0)
Average (1,EXO(23),Float,0)
Average (1,EXO(24),Float,0)
EndTable

BeginProg


SerialOpen(32,9600,16,0,80)
Scan(5,sec,0,0)

SerialInRecord(32,EXO(24),0,80,,&H0D0A,NBytesReturned,01)

CallTable EXO

NextScan
EndProg


Jay Aldrich May 2, 2022 10:02 PM

Dim EXO_Data As String * 256
Public EXO(24)
'24 variables measured by EXO2 sonde
Alias EXO(1)=Chlorophyll

BeginProg
Scan(10,sec,0,0)
SerialOpen (32,9600,0,0,256)
SerialOut (32,"#" + CHR(13),"#",3,10)
Delay (1,500,mSec)
SerialOut (32,"run" + CHR(13) + CHR(10),"run",1,0)
Delay (1,500,mSec)
SerialIn (EXO_Data,32,100,&H0D0A,256)
SplitStr (EXO,EXO_Data,",",24,0)
CallTable EXO
NextScan
EndProg

I made a few changes: added a seperate String to for the 'SplitStr'. Increased the buffer size as the data was being chopped. I haven't had much sucess with the 'SerialInRecord' command, but the 'SerialOut', 'SerialIn' and 'SplitStr' works well. Using a baud rate of 9600 needs delays in the program, and the SDM also requires delays. Using 9600 with the SDM-SIO1A sometimes the timing goes wrong and data gets cut and I use a baud rate of 34800 with my SDM-SIO1A stations but this program seems to be working.

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