From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

what is the best way to parse TCP data packets?

But if you want to make a TYPEDEF out of it (which is where I was going), you need the CONTROL, not a constant.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 21 of 50
(1,950 Views)

No.  You can make a typedef out of a constant directly.  In newer LabVIEW versions, just right click on it and pick Make Typedef.

 

And if it is already a TD'ed control on the front panel, you can go to the block diagram and right click on the terminal and pick Change to Control.

 

Either way, you eliminate the confusion of having a control on the front panel that serves no purpose (other than providing a datatype wire.)

 

 

0 Kudos
Message 22 of 50
(1,945 Views)

Thanks Steve-

 

I got called out of town and am just getting back to this now...

 

I was able to fix the unit that I am connected with and I get an error 74 when I try to unflatten the string

(right after the breakpoint).   Not sure what that means...

 

error74.jpg

0 Kudos
Message 23 of 50
(1,897 Views)

Error 74 means that it cannot unflatten the string into the structure you are using as the Data Type.

 

How many bytes are in the string ("Start Sample Response") vs. how many bytes are in the structure ("TCP Data Packet") ?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 24 of 50
(1,893 Views)

Hopefully, it's 27, and you're OK for now, but the FRAGILE argument says that you shouldn't use the constant "27", you should measure the size of the structure (FLATTEN TO STRING, and then STRING LENGTH, outside the loop) to get that number. 

 

If you counted right, it's 27 either way, but you don't have to change TWO things if that structure changes.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 25 of 50
(1,891 Views)

Thanks Steve-

 

I saw this in the fragile article but was wondering what that symbol (String Length) was...

 

How is it  supposed to be connected?

stringlen.jpg

0 Kudos
Message 26 of 50
(1,885 Views)

You need to use the FLATTEN function, not the UNFLATTEN.

 

Think about it - you have a structure that you want to know the size of.

You need to convert it to a string, so you can measure it.

 

Which is better for that: UNFLATTEN FROM STRING, or FLATTEN INTO STRING?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 27 of 50
(1,876 Views)

Thanks, that makes sense to flatten into a string...

 

Because the remainder of the packet sent is dependent on the length in bytes, how do I capture the remainder of the packet in the stream in

individual bytes, is this done by setting up another another cluster of individual bytes or as an array?

 

remainder of packet.jpg

0 Kudos
Message 28 of 50
(1,863 Views)

That depends on what the data represents.

 

Understand that you can UNFLATTEN that string into any structure you want.

 

It's up to YOU to define the structure that matches what the data represents.

 

If it's really variable, then you can't have a fixed structure that matches all cases.

 

If you have two choices (for instance), then you want to use the LENGTH to do something like this:

 

Case PayLoad.Length of

14:  MySmall Structure = UnflattenFromString(Payload, MySmallStructureType)

22: MyLargeStructure = UnflattenFromString(Payload,MyLargeStructureType).

else:  Error

 

If it's NOT two distinct choices, if it's a variable number of U16s for example, then unflatten it as an array of U16s and be done.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 29 of 50
(1,854 Views)

Thanks for the explanation Steve.

 

What  I am attempting to dump into a string is a variable number of bytes (U8) and I am getting a little bit confused...

 

In order to then unflatten it as an array of U8s do I need to define the size (number of array elements) as a typedef

(of U8 controls) similar to what you had me do for the other type def?

 

 How do I unflatten it as an array of U8s?

 

I tried making an indicator array on the front panel to use as a typedef to the unflatten but this gave me a connection error.

What I am trying to accomplish it to take the rest of the data from the TCP packet (which varies in length) into an array where I

can use the data of each byte...

 

 

 

 

 

0 Kudos
Message 30 of 50
(1,840 Views)