LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parse bytes to array

Hello,

 

I am working with LabVIEW 2013. I am receiving a set of raw bytes 10 times a second that contain ASCII characters:

*Time:09:05:01*Position:[-63.71,-73.581,-117.519]*Quaternions:[0.999102,-0.0025507,-0.041212,-0.00952388]*Euler:[-0.247893,-4.726448,-1.082074]

And so on. What I am trying to do is parse these bytes into an array. Essentially I need it to look for a "*" and parse the data in between each asterick. Something like this for the array:

 

Time: 09:05:01

Position: [-63.71,-73.581,-117.519]

Quaternions: [0.999102,-0.0025507,-0.041212,-0.00952388]

Euler: [-0.247893,-4.726448,-1.082074]

 

Can anyone point me in the right direction to get this started? I will also eventually need to plot this data, but one step at a time...

 

Thanks,

SM

 

0 Kudos
Message 1 of 13
(3,811 Views)

Hi SteMob,

 

put these bytes into an array of U8, then convert the array to a string.

 

Then use SpreadsheetStringtoArray with the asterisk as separator to convert the string into an array of strings, separated at the asterisks.

Then use ScanFromString to get your values from each string…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(3,806 Views)

Hi Gerd,

 

So I am fairly new to LabVIEW, and it's been a little while since I have done any of this stuff. Could you maybe show me an example of this? I'm having trouble just going from array to string...

Thanks

SM

0 Kudos
Message 3 of 13
(3,801 Views)

Well it's kind of a "hack" but you could use spreadsheet string to array.

 

Parse.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 13
(3,799 Views)

RTSLVU,

 

How did you make the "array type" and the output array to be strings instead of doubles?

 

Thanks,

SM

0 Kudos
Message 5 of 13
(3,793 Views)

Oh, I also failed to mention, these incoming bytes are like an infinite loop, so somehow after it receives bytes for a second or so, I need to delete the old data out so my array doesn't just keep filling up with data for all eternity.


Thanks,

SM

0 Kudos
Message 6 of 13
(3,787 Views)

@SteMob wrote:

RTSLVU,

 

How did you make the "array type" and the output array to be strings instead of doubles?

 

Thanks,

SM


Yes the Spreadsheet String to Array defaults to a double numeric.

 

By connecting an empty string array constant to the Array Type input it changes it to a string array output.

 

To make an array constant you need to grab the empty array constant put it on your block diagram then grab the string constant and place it inside the array constant.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 13
(3,785 Views)

Hi SteMob,

 

So I am fairly new to LabVIEW, and it's been a little while since I have done any of this stuff.

You're posting here since a month or so.

That's why I assume you had the time to go through all those FREE online resources offered by NI for LabVIEW beginners. It seems you failed in doing so…

(Atleast you should know how to create constants in LabVIEW as this is very basic stuff!)

 

these incoming bytes are like an infinite loop, so somehow after it receives bytes for a second or so, I need to delete the old data out so my array doesn't just keep filling up with data for all eternity.

Yes.

I hope you receive those strings (aka byte arrays) with a proper termination char (like LF or CR)?

Do you receive them using a serial COM port (even a virtual one over USB connection is fine)? You use VISA functions to receive the data? Then use the termchar to receive full message strings!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 13
(3,780 Views)

I receive them from a robot via TCP/IP Sockets via Ethernet. LV is the client.

0 Kudos
Message 9 of 13
(3,759 Views)

@SteMob wrote:

I receive them from a robot via TCP/IP Sockets via Ethernet. LV is the client.


I would use the "*" as the termination character on the TCP Read.  Then you can just compare the first few characters to figure out what your data is and send that off to whoever is storing the data (shift registers work well as well).  So you can have a location for the time that you overwrite each time you recieve the time data.


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 10 of 13
(3,750 Views)