LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a packet structure

Hi,

 

I have this following vi with couple of buttons and a text indicator. I simulate the states of this Boolean indicator from another vi using UDP protocol and pass it on to the main vi so that the status and the text gets displayed. I am being told to form a packet structure out of this. Could I know how this can be achieved?

Diaspora_0-1577688424034.png

0 Kudos
Message 1 of 6
(3,826 Views)

@Diaspora wrote:

I am being told to form a packet structure out of this.


Who is telling you vague things like that?

 

A "packet" is at a much lower level of network communication and you don't need to worry about them. All you need to know is that the network communicates via (binary) strings, so all you need to do is flatten the data before sending and unflatten it at the receiving end.

have you looked at some of the shipping examples?

0 Kudos
Message 2 of 6
(3,813 Views)

@altenbach wrote:

@Diaspora wrote:

I am being told to form a packet structure out of this.


Who is telling you vague things like that?

 

A "packet" is at a much lower level of network communication and you don't need to worry about them. All you need to know is that the network communicates via (binary) strings, so all you need to do is flatten the data before sending and unflatten it at the receiving end.

have you looked at some of the shipping examples?


What is the correct designation if you want to describe data packed in a structure on a higher level. And why can't a packet structure be used for designating how data can be assembled on a higher level?

0 Kudos
Message 3 of 6
(3,661 Views)

@Diaspora wrote:

Hi,

 

I have this following vi with couple of buttons and a text indicator. I simulate the states of this Boolean indicator from another vi using UDP protocol and pass it on to the main vi so that the status and the text gets displayed. I am being told to form a packet structure out of this. Could I know how this can be achieved?

 


You wrote that "I simulate the states of this Boolean indicator from another vi using UDP protocol". Is it only booleans or booleans and text which shall be sent?

Who have told you to create a packet structure? Your teacher? In that case i assume that you should have learnt something about what may be needed when collecting into a structure. A little more information about purpose of task could be helpful, is is to learn LabVIEW, programming, or problems which may be present if you need to send different datatypes in one packet between two computers.

I have not used the flatten/unflatten functonality in LabVIEW, but i think you could collect the data in a cluster and flatten it before sending and unflatten at receiver as altenbach suggest.

Or you could collect the data into a string at the transmitter, and just split it in the other end. If you collects three booleans first and then the text string at the end it should be possible to easily decode at the end. But if there is an expansion and two strings need to be sent later on you need something to tell the end of each string.

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

If I was guessing, I'd wonder if the aforementioned "packet structure" referred to a hypothetical message protocol or system.

 

Certainly, one possible method for communicating a data package between two VIs running on separate computers would be via defining a type definition of a cluster of your data elements, then using something like Flatten to String and Unflatten from String to pass that to the TCP or UDP functions. Use of these functions requires some planning or close coupling between two (in-principle) unrelated VIs, because you'll need to know when to read or write, what the typedef is, and how long your messages are (and so on).

 

You can include some of this data in your message "packets" (not packets in the internet communication sense, as was already highlighted) by for example always putting a number of bytes to read as part of a hypothetical "header". The TCP examples shipping with LabVIEW provide a demonstration of this technique to communicate data between a "server" and "client" with the first 4 bytes being an I32 length value for the "message".

 

A potentially simpler method might involve Network Streams. These can be configured to send more complicated data types (although not any datatype, so some things might still require e.g. flattening to/from strings). Clusters of simple data types are possible/allowed. However, this limits you to a single direction per stream, so for 2-way communication you'd need two streams set up. For 1:N or N:1 communication they also require a bit more legwork - I just rewrote some of my code on cRIO to dynamically spawn Network Streams via a TCP server interface (which is why I was checking out the examples!)

 

What are you trying to do, and what do you really need help with? If you can upload a VI or two that demonstrate what you're working on/with, it will be easier to give good tips or suggestions.


GCentral
0 Kudos
Message 5 of 6
(3,584 Views)

@RolfO wrote:
What is the correct designation if you want to describe data packed in a structure on a higher level. And why can't a packet structure be used for designating how data can be assembled on a higher level?

Well, TCP/IP is a packet based network and I would not use the term for higher level structures to avoid confusion. Depending on the MTU, you data might be fragmented into many packets during transport. How about just "data", "flattened data" or "message"? I am sure there are other terms. 😉

 

The take home message us that you can only transmit plain strings (i.e. a linear sequence of bytes), but as long as both sides agree on what they mean, you can transmit anything you want.

 

Here's a cartoon version how you would send three booleans and a string of any length. Of course you would need to substitute the real UDP functions and wire he correct number of bytes to read (first four, then N). As I already suggested, look at the examples that ship with LabVIEW.

 

altenbach_0-1577755696612.png

 

 

0 Kudos
Message 6 of 6
(3,544 Views)