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.

Serail String Splits


pah Sep 1, 2021 10:56 PM

Hello All,

This is my 1st post as I'm trying to learn more CRBasic programming.  Thank you for looking. I have an issue with an Optical Scientific ORG-815 optical precipitation sensor and spliting its serial string.  The sensor responds to the "A" command with an array of 3 variables and works great.  I wrote the following code for its response to the "A" command.

'ORG815 Variables

Public ORG(3) As String * 16
Alias ORG(1) = WeatherStatusCode
Alias ORG(2) = InstantaneousRainRate
Alias ORG(3) = TotalAccumulation

Public numBytesRet
Dim inString As String * 16

'Main Program

SerialOpen (Com2,1200,0,100,24)

SerialOut (Com2,"A"," ",1,200)

SerialInRecord (Com2,inString,0,16,0,numBytesRet,01)
SplitStr (ORG,inString," ",3,7)

The ORG also responds to a "D" command which returns an array of 7 variables.  I figured I could just increase the string size, the buffer, and the number of splits.  However nothing is showing up in the public tables when I do this.  The following is the code for the "D" command.

'ORG815 Variables


Public ORG(7) As String * 40
Alias ORG(1) = WeatherStatusCode
Alias ORG(2) = InstantaneousRainRate
Alias ORG(3) = TotalAccumulation
Alias ORG(4) = LensHeaterStatus
Alias ORG(5) = Diag1
Alias ORG(6) = Diag2
Alias ORG(7) = Diag3

Public numBytesRet
Dim inString As String * 40

'Main Program

SerialOpen (Com2,1200,0,100,90)

SerialOut (Com2,"D"," ",1,200)

SerialInRecord (Com2,inString,0,40,0,numBytesRet,01)
SplitStr (ORG,inString," ",7,7)

Any ideas on why I can't get the string split into 7 variables but 3 works?  Any help would be greatly appreicated.  Thank you.


Nico Sep 21, 2021 05:42 AM

You sure that the inString (40 chars) contains all of the fields separated by a 'space'?

What does numBytesRet contain?

Why do you size the target strings with 40 chars EACH as well, when 16 had been good enough before?
Or asked the other way around.. if you need 40 for each there, your incoming string will be much larger than 40 chars.. something doesn't add up here.


pah Sep 27, 2021 08:14 PM

The incomming string should be 40 characters long with the D command, according to the manual.  It's 16 characters long when issuing the A command. I tried increasing the string size for inString and the buffer but it still doesn't work.

The program that works when issuing the A command has numBytesRet of 16.  But when I run the program for the D command numBytesRet is 0.  

I can watch the sensor's response in the Terminal Emulator so I know its working and returning data when the commands are issues.  I just can't seem to get the serial string split correctly into the 7 variables.  Thanks for your help. 

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