Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to separate the serial data corresponding to their ID

Hi ,

     I have recently started using labview for school and for personal projects. I have couple accelerometers connected to arduino board and I am reading the data serial port using labview. Since I have couple sensor of same kind I have assigned ID to each sensor, so when I read data from each sensor I can recognize which data is from which sensor. Now when I read in serial I am reading the message as shown below (using Labview VISA)

 

29X:\s12\sY:\s24\sZ:\s-10

83X:\s12\sY:\s24\sZ:\s-10

 

where 29 and 83 is the decimal value of hex adress 0x1D and 0x53. X:, Y:, Z: are the data from my accelerometer. I would like to look to separate the data corresponding to their device address. Can any one please tell me how I can separate the data corresponding to their device ID please.

 

Thank you!

0 Kudos
Message 1 of 6
(4,601 Views)

Since it looks like you are using all ASCII, are you using a termination character (like 0x0A)?  If you use a termination character, then tell your VISA Read to read something like 100 bytes (way more than should be in a line) and it will return the line of read data up to that termination character.  From there, it is easy enough to parse your line to get the ID, X, Y, and Z values.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(4,596 Views)

Hi crossrulz,

                  Thanks for the response. I have the termination characters but I am intersted in isolating the data drom two sensors and save them or plot them separately Like

If ID = 29

Read x, y and Z and keep plotting them in plot 1(X, Y Z separate plots) when ever it reads the data from that address

 

If ID = 83

Read x, y and Z and keep plotting them in plot 2(X, Y Z separate plots) when ever it reads the data from that address

 

Currently I have another issue too, while reading the real time serial data(using labview) I am reading some unexpected character, but while reading the stored data using labview or using anyother serial read program I am reding fine (no unexpected characters). PLease let me know what am I missing.

 

I would even like to log the data in two excellsheet for my future reference.

 

 

0 Kudos
Message 3 of 6
(4,572 Views)

Here is what I read under normal condition 

83x:\s118\sy:\s-39\sz:\s-55\r\n

 

and here is what I read in uncertainities 

29x:\s-26\sy\8A\92\C2\02\D2\E9\s1\r\n

0 Kudos
Message 4 of 6
(4,571 Views)

Since you have included the identifier in the string of data, you can use the VIs on the String Palette of the Programming Palette such as the Match Pattern VI, to identify which accelerometer you are receiving data from. You can view the different string functions available here.

 

Regards,

Anjelica W.
National Instruments
Product Marketing Manager
FlexLogger and TestStand
0 Kudos
Message 5 of 6
(4,550 Views)

How are you using that VI? You configure the serial port to use line feed as the termination character, read from the port, process the received string and exit.  You do not close the port. I think that a read using termination character does not return the termination character in the read string.

 

Are you using Continuous Run? If so, STOP. That is not the way to run a program. Repeated opening and configuring the port might be a problem, especially since you never close it.  Wrap a while loop around the portions of the code which need to be repeated.

 

Consider using Spreadsheet String to Array with "%s" as the format string and the space character as the delimiter.  Then you get an array of strings {83x:, 118, y:, -39, z:, -55} from the string you reported as "normal conditions". Using Index array and the string to number conversion funcitions you can easily extract the data for the various IDs.

 

Lynn

0 Kudos
Message 6 of 6
(4,541 Views)