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.

polling a RS232 sensor, timing problem?


uta Apr 7, 2010 08:09 AM

Hi,
I use a Aanderaa sensor in polling mode. I get correct data but only in every second scan.
The NBytesReturned goes to zero every second scan and the data goes to NAN.
What is the problem?
Thanks for your help.
Greetings from Norway, Uta

Part of my code:

BeginProg
SerialOpen (COM3,9600,0,0,10000)

Scan(10,sec,1,0)

'Default Datalogger Battery Voltage measurement Batt_Volt:
Battery(Batt_Volt)
'Datalogger Panel Temperature measurement:
PanelTemp(PTemp,250)

OutString= "Do_Sample" & CHR(13) & CHR(10)

SerialOut (COM3,OutString,"",0,100)

'take 225 bytes in front of CR LF
SerialInRecord (COM3,CondInString,0,225,&H0D0A,NBytesReturnedCond,01) '&H0D0 is CR LF
SplitStr (CondInStringSplit(),CondInString,"",12,0) ' split and take numeric data only
SplitStr (CondInStringSplitText(),CondInString,"",12,1) ' split and take non numeric data only

'Call Data Tables and Store Data
CallTable(TableOxi1)
CallTable(TableCond)
CallTable(TableTemp)

NextScan

EndProg


aps Apr 7, 2010 10:13 AM

Without seeing details of the exact sensor you are using I would look at these possible problems:

a) you are not allowing enough time after sending the command to when you call Serialinrecord. Looking on the net I can see that for some sensors the Do_sample instruction can take some seconds before a response comes back.

b) that the response is less the 225 characters long (the CRLF should not be included in the total).

There is also a risk of problems if the sensor is also outputting data on a timed basis - make sure this is turned off. I also see some of these Aanderra sensors will acknowledge the command with a response, followed by CRLF, which, if the timing is wrong, might result in shorter strings being captured than expected.


uta Apr 8, 2010 07:51 AM

Hi
I got a bit further.
I get a correct and complete string now. But I am still not satisfied with the timestamp the data get in the datatable. When I have a value change some seconds before the scan this value appears in the data table with a timestamp 1 interval later (scan and table interval between 10 and 30sec).
Is there a possiblility to get the timestamp in the datatable closer to the real measurement?

I have three RS232 sensors in the same scan loop and programmed like this:
...
SerialOpen (COM1,9600,0,0,10000)
SerialOpen (COM2,9600,0,0,10000)
SerialOpen (COM3,9600,0,0,10000)

Scan(10,sec,1,0)

'Default Datalogger Battery Voltage measurement Batt_Volt:
Battery(Batt_Volt)
'Datalogger Panel Temperature measurement:
PanelTemp(PTemp,250)

OutString= "Do_Sample" & CHR(13) & CHR(10)

SerialOut (COM1,OutString,"",0,100)
Delay (...)
SerialInRecord(COM1,InString,0,225,&H0D0A,NBytesRet,01)SplitStr (InStringSplit(),InString,"",12,0)
SplitStr (InStringSplitText(),InString,"",12,1)

SerialOut (COM2,OutString,"",0,100)
Delay (...)
SerialInRecord(COM2,InString2,0,225,&H0D0A,NBytesRet,01)SplitStr (InStringSplit2(),InString2,"",12,0)
SplitStr (InStringSplitText2(),InString2,"",12,1)

SerialOut (COM3,OutString,"",0,100)
Delay (...)
SerialInRecord(COM3,InString3,0,225,&H0D0A,NBytesRet,01)SplitStr (InStringSplit3(),InString3,"",12,0)
SplitStr (InStringSplitText3(),InString3,"",12,1)


'Call Data Tables and Store Data
CallTable(TableOxy1)
CallTable(TableCond)
CallTable(TableTemp)

...

Thanks and regards, Uta


aps Apr 8, 2010 01:07 PM

Providing you are not having skipped scans, the timestamp in the data record will always be the time at the start of the scan that called it.

If your data is from more than one scan before this I would take the extra precaution of including a serialflush command before each serialout to make sure there is no old data in the buffer and also make sure your delays are not so long that you are skipping scans.


Phenotrait Jul 25, 2019 01:40 PM

Hi

I have same problem like uta, here is my program:

'Main Program
BeginProg
Scan(3,Sec,2,0)
Battery (batt_volt)

SerialOutString_1 = "01data" & CHR(13) 'send out "data"
SerialOutString_2 = "02data" & CHR(13) 'send out "data"
SerialOpen(Com4,19200,0,0,50)
SerialOut(Com4,SerialOutString_1,"",0,0)
SerialInRecord(Com4,No_1,78,0,59,"",101)
SerialInRecord(Com4,Temp_raw_1,84,0,59,"",11)
SerialInRecord(Com4,O2_raw_1,79,0,59,"",01)


CallTable Presense_Sensor_1
NextScan


EndProg

data can back from sensor to cr1000 very quick (less than 100ms) but in data of cr1000, there is 1 scan time delay. 

For exp:

0s: cr1000 send command to sensor

0+0.1s: sensor responds to cr1000

cr1000 shows NAN in data table

3s: cr1000 send new command to sensor

3+0.1s:sensor responds to cr1000

then at this moment, in cr1000's data table, 0+0.1s data shows up. 

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