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.

Queries on Program Coding for Serial Sensors in CR1000X


Balaji Ravikumar Feb 7, 2019 07:44 AM

Dear Users,
I have Written the programming in CR Basic for Interfacing 2 No's of Serial sensor and 1no of SD12 Protocol Sensor, for the Datalogger CR1000X. Our requirement is the serial sensors, what we are interfacing will giving output at different interval one at 10 min and another at 20min. The Programming made was found OK with No error while compiling in CRBasic.
Since I am new to this programming in CRBasic, anybody can correct and give this programming code for proceeding further. Even anybody can guide me write the coding to have serial output at CS I/O port at every 60Mins once for Real Transmission at External Modem.

Data String for Serial Sensor as follow as 

1. Wave Sensor in  ASCII Format:  $PSVSW,0.020,7.273,7.273,180.487,0.026,4.102,-0.074,0.148,9.835,-0.562,-0.812,2019-02-04 08:35:19,2048*5A

2. Current meter Sensor in ASCII format:     1 30 2019 17 12 41 0 181 0.432 0.268 0.605 119 94 78 14.6 1530.9 51.8 -37.2 -0.9 0.406 23.63 0 0 0.508 58.2

Here below the Program as below,

Dim Wave_Data As String * 29
Dim Currentmeter As String * 29
Public BattV
Public PTemp_C
Public SDI12(6)
Public SDI12_2(6)
Public SDI12_3(4)
Public SDI12_4(8)
Public SDI12_5(8)
Public Wave_Str (20)
Public Nmea
Public Hs
Public Ts
Public Dominant_wave_direction
Public Mean_wave_direction
Public Max_wave_height
Public Fourier_Coefficient_a1
Public Fourier_Coefficient_b1
Public Fourier_Coefficient_a2
Public Fourier_Coefficient_b2
Public TimeandDate
Public Samplenumber
Public Current_meter(40)
Public C_month
Public C_Day
Public C_Year
Public C_Hour
Public C_Min
Public C_Sec
Public C_Errorcode
Public C_Status_Code
Public C_Velocity_East
Public C_Velocity_North
Public C_Velocity_up
Public C_Amplitude_Beam1
Public C_Amplitude_Beam2
Public C_Amplitude_Beam3
Public C_Battery
Public C_Soundspeed
Public C_Heading
Public C_Pitch
Public C_Roll
Public C_Pressure
Public C_Temperature
Public C_Analoginputs1
Public C_Analoginputs2
Public C_CurrentSpeed
Public C_CurrentDirection

Alias SDI12(1)=Address
Alias SDI12(2)=RealativeWindDirection
Alias SDI12(3)=RelativeWindSpeed
Alias SDI12(4)=CorrectedWindDirection
Alias SDI12(5)=CorrectedWindSpeed
Alias SDI12(6)=Status
Alias SDI12_2(1)=Address1
Alias SDI12_2(2)=Temperature
Alias SDI12_2(3)=RelativeHumidity
Alias SDI12_2(4)=Dewpoint
Alias SDI12_2(5)=Pressure
Alias SDI12_2(6)=Status1
Alias SDI12_3(1)=Address2
Alias SDI12_3(2)=SolarRadiation
Alias SDI12_3(3)=SunshineHours
Alias SDI12_3(4)=Status2
Alias SDI12_4(1)=Address3
Alias SDI12_4(2)=signedLatitudeintegerpart
Alias SDI12_4(3)=signedLatitudefractionalpart
Alias SDI12_4(4)=signedLongitudeintegerpart
Alias SDI12_4(5)=signedLongitudefractionalpart
Alias SDI12_4(6)=Heightabovemeansealevel
Alias SDI12_4(7)=Status3
Alias SDI12_4(8)=CRC
Alias SDI12_5(1)=Address4
Alias SDI12_5(2)=Year
Alias SDI12_5(3)=Month
Alias SDI12_5(4)=Date
Alias SDI12_5(5)=Hour
Alias SDI12_5(6)=Minute
Alias SDI12_5(7)=Second
Alias SDI12_5(8)=Status4

Units BattV=Volts
Units PTemp_C=Deg C
Units RealativeWindDirection=Degrees
Units RelativeWindSpeed=m/s
Units CorrectedWindDirection=Degrees
Units CorrectedWindSpeed=m/s
Units Temperature=Degrees C
Units RelativeHumidity=%
Units Dewpoint=Degrees C
Units Pressure=hPa
Units SolarRadiation=W/m^2
Units SunshineHours=h
Units signedLatitudeintegerpart=Deg
Units signedLatitudefractionalpart=DDeg
Units signedLongitudeintegerpart=Deg
Units signedLongitudefractionalpart=DDeg
Units Heightabovemeansealevel=m
Units Address4=unit
Units Year=YY
Units Month=Mon
Units Date=DD
Units Hour=Hr
Units Minute=Min
Units Second=Sec
Units Hs=m
Units Ts=sec
Units Dominant_wave_direction=Degrees
Units Mean_wave_direction= Degrees
Units Max_wave_height=m
Units Fourier_Coefficient_a1= constant
Units Fourier_Coefficient_a2= constant
Units Fourier_Coefficient_b1= constant
Units Fourier_Coefficient_b2= constant
Units TimeandDate=Date&Time
Units Samplenumber= No of Samples
Units C_month=mm
Units C_Day=DD
Units C_Year=YY
Units C_Hour=HH
Units C_Min=Min
Units C_Sec=Sec
Units C_Errorcode=Code
Units C_Status_Code=code
Units C_Velocity_East=m/s
Units C_Velocity_North=m/s
Units C_Velocity_up=m/s
Units C_Amplitude_Beam1=Beam1
Units C_Amplitude_Beam2=Beam2
Units C_Amplitude_Beam3=Beam3
Units C_Battery =Volt
Units C_Soundspeed=m/s
Units C_Heading=Degrees
Units C_Roll=Degree
Units C_Pressure=dBar
Units C_Temperature=Degree
Units C_Analoginputs1=Unit
Units C_Analoginputs2=Unit
Units C_CurrentSpeed=m/s
Units C_CurrentDirection=Degrees

'Define Data Tables
DataTable(Meterological_Sensor,True,-1)
DataInterval(0,10,Min,10)
Average(1,CorrectedWindSpeed,FP2,False)
Average(1,CorrectedWindDirection,FP2,False)
Average(1,Temperature,FP2,False)
Average(1,RelativeHumidity,FP2,False)
Average(1,Pressure,FP2,False)
Average(1,SolarRadiation,FP2,False)
Average(1,signedLatitudeintegerpart,FP2,False)
Average(1,signedLatitudefractionalpart,FP2,False)
Average(1,signedLongitudeintegerpart,FP2,False)
Average(1,signedLongitudefractionalpart,FP2,False)
Average(1,Year,FP2,False)
Average(1,Month,FP2,False)
Average(1,Date,FP2,False)
Average(1,Hour,FP2,False)
Average(1,Minute,FP2,False)
Average(1,Second,FP2,False)
EndTable

DataTable (Wave_Datas,True,-1)
DataInterval(1,20,Min,20)
Sample(1,Nmea,String)
Sample(1,Hs,FP2)
Sample(1,Dominant_wave_direction,FP2)
Sample(1,Mean_wave_direction,FP2)
Sample(1,Max_wave_height,FP2)
Sample(1,Fourier_Coefficient_a1,IEEE4)
Sample(1,Fourier_Coefficient_b1,IEEE4)
Sample(1,Fourier_Coefficient_a2,IEEE4)
Sample(1,Fourier_Coefficient_b2,IEEE4)
Sample(1,TimeandDate,String)
Sample(1,Samplenumber,String)
EndTable
DataTable (Currentmeter_Data,True,-1)
DataInterval(1,10,Min,10)
Sample(1,C_month,UINT2)
Sample(1,C_Day,UINT2)
Sample(1,C_Year,UINT2)
Sample(1,C_Hour,UINT2)
Sample(1,C_Min,UINT2)
Sample(1,C_Sec,UINT2)
Sample(1,C_Errorcode,UINT2)
Sample(1,C_Status_Code,UINT2)
Sample(1,C_Velocity_East,FP2)
Sample(1,C_Velocity_North,FP2)
Sample(1,C_Velocity_up,FP2)
Sample(1,C_Amplitude_Beam1,UINT4)
Sample(1,C_Amplitude_Beam2,UINT4)
Sample(1,C_Amplitude_Beam3,UINT4)
Sample(1,C_Battery,FP2)
Sample(1,C_Soundspeed,IEEE4)
Sample(1,C_Heading,FP2)
Sample(1,C_Roll,FP2)
Sample(1,C_Pitch,FP2)
Sample(1,C_Pressure,FP2)
Sample(1,C_Temperature,FP2)
Sample(1,C_Analoginputs1,UINT2)
Sample(1,C_Analoginputs2,UINT2)
Sample(1,C_CurrentSpeed,FP2)
Sample(1,C_CurrentDirection,FP2)
EndTable
DataTable(Table2,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
EndTable

'Main Program
BeginProg
SerialOpen(ComC5,9600,0,0,121)
SerialOpen(ComC7,9600,0,0,121)
Scan(20,Min,1,0)
SerialIn (Wave_Data,ComC5,100,65,200)
'delimiting the current meter data comma character'
SplitStr(Wave_Str(),Wave_Data,",",20,2)
Nmea=Wave_Str(1)
Hs= Wave_Str(2)
Ts=Wave_Str(3)
Dominant_wave_direction=Wave_Str(4)
Mean_wave_direction=Wave_Str(5)
Max_wave_height=Wave_Str(6)
Fourier_Coefficient_a1=Wave_Str(7)
Fourier_Coefficient_b1=Wave_Str(8)
Fourier_Coefficient_a2=Wave_Str(9)
Fourier_Coefficient_b2=Wave_Str(10)
TimeandDate=Wave_Str(11)
Samplenumber=Wave_Str(12)
SerialClose (ComC5)
Nextscan
'Main Scan
Scan(10,Min,1,0)
'Default CR1000X Datalogger Battery Voltage measurement 'BattV'
Battery(BattV)
'Default CR1000X Datalogger Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp_C,50)
'Generic SDI-12 Sensor measurements 'Address', 'RealativeWindDirection', 'RelativeWindSpeed',
'CorrectedWindDirection', 'CorrectedWindSpeed', and 'Status'
SDI12Recorder(SDI12(),C1,"0","M!",1,0,-1)
'Generic SDI-12 Sensor measurements 'Address1', 'Temperature', 'RelativeHumidity',
'Dewpoint', 'Pressure', and 'Status1'
SDI12Recorder(SDI12_2(),C1,"0","M1!",1,0,-1)
'Generic SDI-12 Sensor measurements 'Address2', 'SolarRadiation', 'SunshineHours', and 'Status2'
SDI12Recorder(SDI12_3(),C1,"0","M4!",1,0,-1)
'Generic SDI-12 Sensor measurements 'Address3', 'signedLatitudeintegerpart', 'signedLatitudefractionalpart',
'signedLongitudeintegerpart', 'signedLongitudefractionalpart', 'Heightabovemeansealevel', 'Status3', and 'CRC'
SDI12Recorder(SDI12_4(),C1,"0","M5!",1,0,-1)
'Generic SDI-12 Sensor measurements 'Address4', 'Year', 'Month',
'Date', 'Hour', 'Minute', 'Second', and 'Status4'
SDI12Recorder(SDI12_5(),C1,"0","M6!",1,0,-1)
'Call Data Tables and Store Data
SerialIn (Currentmeter,ComC7,100,00,200)
'delimiting the current meter data space character'
SplitStr(Current_meter(),Currentmeter,32,25,2)
C_month=Current_meter(1)
C_Day=Current_meter(2)
C_Year=Current_meter(3)
C_Hour=Current_meter(3)
C_Min=Current_meter(4)
C_Sec=Current_meter(5)
C_Errorcode=Current_meter(6)
C_Status_Code=Current_meter(7)
C_Velocity_East=Current_meter(8)
C_Velocity_North=Current_meter(9)
C_Velocity_up=Current_meter(10)
C_Amplitude_Beam1=Current_meter(11)
C_Amplitude_Beam2=Current_meter(12)
C_Amplitude_Beam3=Current_meter(13)
C_Battery =Current_meter(14)
C_Soundspeed=Current_meter(15)
C_Heading=Current_meter(16)
C_Pitch=Current_meter(17)
C_Roll=Current_meter(18)
C_Pressure=Current_meter(19)
C_Temperature=Current_meter(20)
C_Analoginputs1=Current_meter(21)
C_Analoginputs2=Current_meter(22)
C_CurrentSpeed=Current_meter(23)
C_CurrentDirection=Current_meter(24)
SerialClose (ComC7)
CallTable Meterological_Sensor
CallTable Wave_Datas
CallTable Currentmeter_Data
CallTable Table2
NextScan
EndProg

Kindly provide me  the solution for this.

Iam will be so helpful once it is correctd for any error init and so that i uploaded to daalogger for data collection.

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