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.

unable to read data from com1


vk May 13, 2015 11:05 AM

Hi,

I would like to read data string coming out from a data acquisition system and store to a file. I have connected my system to com1 port of CR3000. system sends data every 10sec and I would like to record all the data as it is as send by the system. But unable to see any data on laggernet(Table monitor). It displays NAN in the data Table columns. I however can see data string updating on the Hyper terminal as displayed below.


$1036 1281.8 14801.3 2304.3 3409.7 1234.0 2690.4 47.1/ 48.4 5259.5/5231.4

$1147 1361.5 16402.7 2502.9 3407.3 1524.0 3650.6 58.2/ 58.9 2234.3/2141.5
...........

part of the cr3 code is listed bellow:
--
Dim data_1 As String *100
Public data(12)As String
'
PipeLineMode
'
'Define Data Tables
DataTable (Table_data,1,-1)
DataInterval (0,10,Sec,10)
CardOut(1,-1)
Sample(12,data (1),IEEE4)

EndTable
BeginProg
SerialOpen(Com1,9600,0,0,10000)
Scan(10,Sec,3,0)
SerialFlush(Com1)
SerialInRecord(Com1,data_1,36,0,1310," ",01)
SplitStr(data(1),data_1,"",12,0)
CallTable(Table_data)
NextScan
EndProg
--

Thanks for help.

* Last updated by: vk on 5/13/2015 @ 6:12 AM *


aps May 13, 2015 11:18 AM

As a starter remove the serialflush command as it is clearing the input buffer immediately before Serialinrecord processes the buffer, so there will never be any data found. With the right parameters Serialinrecord will pull out the last valid record from the buffer so the serialflush is not needed.

(Also reduced the input buffer size from 10000 to a few records space, say 200, as it is a waste of memory and may take a long time for the logger to scan through.)


vk May 13, 2015 12:52 PM

Thanks Andrew, I removed "SerialFlush(Com1)" and made buf size to 200. I can see some digits but a not valid one for example"-2147583648". I am not sure if SplitStr and char"/" is giving some problems. Please advise.
Thanks

* Last updated by: vk on 5/14/2015 @ 9:07 AM *


aps May 13, 2015 01:17 PM

That indicates no data was received. Looking at you code the termination character in serialinrecord is entered incorrectly (it would need to be entered in hex for two bytes, also the variable for the number of characters received is the wrong data type. You should be able to get away with this:

Public Nchars As Long

...
SerialInRecord(Com1,data_1,36,0,13,Nchars,01)

Where there us a single start character which is "$" and the end character carriage return. (The characters entered as the decimal ASCII equivalents)

You have also defined the variable to receive the data as an array of strings but then asked Splitstr to split the data as numeric values which may not work as expected.

I suggest you change the name of the variable "data" (which is a reserved word) to something else and the type to be float and see what happens. I believe Splitstr should then ignore the "/". If not you will need some more advanced programming.

* Last updated by: aps on 5/13/2015 @ 7:39 AM *


vk May 14, 2015 07:49 AM

Thanks Andrew, I tried those suggestions you had mentioned but it did not work. I also don't see any bite in Nchars, Nchars is showing zero. Actually there are 11 data columns not 12, including "$" it is 12 columns. so I changed splitstr(NumSplit) to 11 but this also didn't help. Another point, manual says in serialInRecord "If the number of bytes received is too large to fit into Dest(Nchars), a negative value will be returned in this parameter" and in my case I am getting"-2.147484E009" whither this is a problem. please help

* Last updated by: vk on 5/14/2015 @ 5:46 AM *


aps May 14, 2015 11:57 AM

IF Nchars is zero then it doesn't matter what SplitStr is doing it will have nothing to process.

Can I suggest that read up in the manual about using the W ("Sniffer") command in terminal mode. Use this command to sniff the data coming in on COM1. Try this both in ASCII and Hex mode, to see the data in both modes and check you can see the data you are expecting coming into the port, along with the "$" start character and the carriage return at the end of the data.

If you do not see the data coming in we need to check the baud rate and wiring etc.


jra May 14, 2015 12:12 PM

This video tutorial https://www.campbellsci.com/videos?video=26 demonstrates the Watch or sniffer mode. The example shows an SDI-12 sensor, you'll choose COM1 as the communications port.


vk May 14, 2015 12:21 PM

Thanks Andew, baud rate is correct 9600, and system BD9 pin 3(Tx) is connected to Rx of com1 (i.e C2) of loggercr3000. more over I can see recordNum update every 10sec although NaN only or -2.147484E009. so baud rate & wiring appears to be okay. I however will check out on W terminal also.


vk May 14, 2015 12:56 PM

Andew, Even I don't see data using sniffer mode. I checked out video also. I however can see data on hyper terminal with BR 9600. So whether SerialInRecord is doing the job, not sure.

* Last updated by: vk on 5/14/2015 @ 7:27 AM *


aps May 14, 2015 01:55 PM

If you cannot see data in the sniffer mode then the program won't see the data. Can I check you have you have a ground connection between the sensor and logger, you could also try swapping the wires to the two control ports on the logger as TX/RX naming conventions can sometimes be confusing.


vk May 14, 2015 03:06 PM

Thanks Andew.After swapping Rx& Tx, I can now see data in sniffer mode.But single string is being displayed in three strings preceding with time stamps, Time stamps is preceded with R (i.e., string is breaking). "$" also I can see. However in Table monitor except (first columns) immediate after "$" all data columns are zero.

* Last updated by: vk on 5/14/2015 @ 9:07 AM *


aps May 14, 2015 03:15 PM

What you are seeing is probably normal and you are getting closer. The logger puts the R to indicate received data and adds a timestamp. The received data from the sensor may get spread across several lines especially if there are pauses in the transmission from the sensor.

Can you run the W command in hex mode and capture the data returned over a period of at least two transmissions and post it to the forum. Also post your latest program.


vk May 14, 2015 03:54 PM

Thanks a lot Andrew its working now. Below is hex in sniffer mode followed by program.

R 21:41:13.19 24 20 34 36 34 20 39 38 38 34 2E 37 20 39 38 30 34 2E 32 20
R 21:41:13.19 20 39 32 36
R 21:41:13.21 30 2E 38 20 38 34 31 30 2E 36 20 31 30 33 32 2E 34 20 32 34
R 21:41:13.21 35 33 2E 30
-------------------------------
Dim hyd_k As String *100
Public hyd(11) As Float
PipeLineMode
Alias hyd(1) = indx
Alias hyd(2) = hyd1
Alias hyd(3) = hyd2
Alias hyd(4) = hyd3
Alias hyd(5) = hyd4
Alias hyd(6) = hyd5
Alias hyd(7) = hyd6
Alias hyd(8) = hyd7
Alias hyd(9) = hyd8
Alias hyd(10) = hyd9
Alias hyd(11) = hyd10

'
'Define Data Tables
DataTable (Table_hyd,1,-1)
DataInterval (0,10,Sec,10)
CardOut(1,-1)
Sample(11,hyd(1) ,IEEE4)
EndTable
'Main Program
BeginProg

SerialOpen(Com1,9600,0,0,200)
Scan(10,Sec,3,0)
SerialInRecord (Com1,hyd_k,&H24,0,&H0D0A,hyd,01)
SplitStr(hyd(1),hyd_k,"",11,0)
CallTable(Table_hyd)
NextScan
EndProg
-------

* Last updated by: vk on 5/14/2015 @ 9:57 AM *


aps May 14, 2015 04:58 PM

I can see no trace of the &H0D0A (carriage return, linefeed) in the hex string? If the sensor is not outputting those characters then serialinrecord will never detect a full record. If the sensor does not output &H0D0A but outputs a fixed number of characters you could remove the endword and change the Nbytes parameter to the expected length of the message.

Incidentally the Nbytesreturned parameter (the one after the endword) should be a different new variable as in your program it is entered as the array into which SplitStr is writing data.


vk May 15, 2015 07:03 AM

Thanks Andrew: I think while cut & paste I missed few lines. here is new hex.
R 10:03:47.85 24 38 30 33 39 20 39 38 37 38 2E 35 20 39 37 39 36 2E 35 20
R 10:03:47.85 20 39 32 35
R 10:03:47.87 31 2E 38 20 38 33 38 33 2E 39 20 31 30 33 31 2E 34 20 32 34
R 10:03:47.87 34 36 2E 39
R 10:03:47.90 20 20 32 39 2E 32 2F 20 33 30 2E 39 20 33 32 35 38 2E 35 2F
R 10:03:47.90 33 32 33 30
R 10:03:47.93 2E 36 0D 0A

And also I change the variables in SerialInRecord to Nchars as you had suggested. Thanks for help.


aps May 15, 2015 07:37 AM

Did you then manage to start to read the data into the program variables?


vk May 15, 2015 10:44 AM

Yes Andrew, I am getting now. Thanks for all the help.

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