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
新对话如下:
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.
新对话如下:
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
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.