From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Data (XBee, String) to Graph in LabVIEW - Help?

So it appears that the code reads the seial data (which is comma separated strings of numerical values e.g. 3802 , 3867, 3761), but it's not able to split this up into an array of elements, which could then be used to plot a graph. 

 

Instead it periodically 'chops'(?) a value, and places it int he first element of the array. Hopefully this is demonstarted in the screenshot which shows 55, clearly not of in the same set of ~3000 values.

 

I know the data is successfully received at the comms port (illustrated by using XCTU), but LabVIEW appears not to be configured correctly. The serial configuration matches that of other's I've seen online using XBee. 

 

Any ideas? Much appreaciated!

Download All
0 Kudos
Message 1 of 11
(4,141 Views)

I ran your VI and it worked just fine. I don't have your hardware, so I just manually entered your raw data. There must be someething in your actual data stream that is causing the "spreadsheet string to array" to chop(?). Right click your "read buffer" indicator and select '\' Code Display, re-run your VI and make sure there is nothing the the read buffer that you don't expect.

0 Kudos
Message 2 of 11
(4,125 Views)

The other thing that you can try is to make your BYTE COUNT number very (larger than the amount of data you expect) and terminate the VISA read on the termination character. typically 0xA

0 Kudos
Message 3 of 11
(4,117 Views)

Hey thanks for the reply!

 

So on code display I'm getting:

 

3007\00,\003006\00,\003007\00,\003004\00,\003005\00,\003006\00,\003006\00,\003

 

I'm guessing \00 is a null character or something? Could this be thorwing it off? Not sure how to recitfy as I'm not placing the \00 there...

0 Kudos
Message 4 of 11
(4,096 Views)

The \00 is definitely your problem. Try using the search and replace pattern.vi in the "Strings>>additional String Functions" Pallet. Just remember to set Boolean to TRUE to delete all instances and leave replace string as default "".

 

Delete_Null_snippet.png

0 Kudos
Message 5 of 11
(4,086 Views)

Oh I forgot. Be careful how you create the Regular Expression. Right click the regular expression and set it with  '\' Display Codes BEFORE you enter the \00 in the string.

0 Kudos
Message 6 of 11
(4,081 Views)

I haven't benchmarked it to the search and replace method, but this works too. Just set the delimeter to include the NULL character

 

 

Alt_Delete_Null_snippet.png

0 Kudos
Message 7 of 11
(4,077 Views)

Yes this works! Thank you!

 

However, it's 100% there...

 

I think this should be simple to fix, but I'm not competent enough with LabVIEW to figure out the solution. So you'll notice in my program there's a 'byte count' control (limits the no of bytes to read).

 

If this is say 50, the program will aquire 7 array cells worth of informaiton, load them to the array, and plot the graph, all simultaniously (i.e. it waits until 50 bytes have been received before displaying anything). It will then run this process again, overriding the first 7 cells and the graph. 

 

The desired operation is: read 1 value (i think 4 bytes value 1 byte comma 2 byes null chars), place in array, display on graph, read another value, add to array,  add to graph, ... (frequency of values is around 1 per seccond)

 

I'm guessing the solution to this is in while loops... but no idea how. Essentially the array and graph shouldn't be overwritten which they are sitting in the main while loop, but not sure how data can be added once they're outside the loop. 

 

Any thoughts?

0 Kudos
Message 8 of 11
(4,042 Views)

Does your device send a special character stating that the message is complete?  Typically it is a Line Feed (0xA).  If it does, what you really want to do is set the Byte Count to something really large so that you get the entire message with 1 read.

 

And you actually want a Chart instead of a graph since a chart keeps a history.


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
0 Kudos
Message 9 of 11
(4,027 Views)

Hey thanks for your reply!

 

So there's no special character sent to say the 'message' is complete. The purpose of the proram however is to display the data as the data is being transmitted, this then stops when the sender says so.

 

Thanks for the tip on the chart, that has helped! 

 

However the 'byte count' is chopping the data after a fixed no. of bytes. The data values being sent are of variable number of bytes so this inevitably means the first and last of each set are usually 'chopped' (not the full value). Each value is separatd by a comma (,), is it possible to somehow replace the bytle limit with a requirement based on the comma separation?

 

Any help appreciated!

0 Kudos
Message 10 of 11
(3,964 Views)