I am currently connecting a oil sensor to the CR1000.
But when I compiled it and tried to see the data, it shows that there are " variable RawString out of bound" error.
I have tried a few days but I still couldn't find out the reason..
the code are as followed:
------------CODE-----------------
'CR1000 Series Datalogger
Public RawString As String * 100
Public SplitData(8)
Public TimeStr As String *20
Public SpaceAT
Public NbytesReturned
'Define Data Tables
DataTable (C6,1,-1)
Sample (1,TimeStr,String)
Sample (8,SplitData(),IEEE4)
EndTable
'Main Program
BeginProg
SerialOpen (ComRS232,9600,0,0,200)
Scan (1,Sec,0,0)
' SerialInRecord (ComRS232,RawString,0,92,&H0D0A,NbytesReturned,01)
SerialInRecord (COMRS232,RawString,10,0,13,NbytesReturned,01)
SpaceAT=InStr (1,RawString," ",2)
TimeStr= Mid (RawString,1,SpaceAT-1)
SplitStr (SplitData(),RawString(1,1,SpaceAT)," ",8,0)
CallTable C6
NextScan
EndProg
---------------------------------------
Appreciate if someone could help me on this, thank you
You don't seem to be checking that any message has in fact been received in the SerialInRecord, that is the purpose of the parameter NBytesReturned. If this is zero there is no point in searching for a space.
You should also check the return value from Instr() function for the case where no space was found - from the CRBasic help
"This function returns the integer position of the first occurrence of the FilterString parameter. If the FilterString is not found, the function returns 0."
That would cause both the Mid() function and the ref to Rawstring(1,1,0) to give the error you have seen.