LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to I create cluster in Lab view and send it to VISA port?

Solved!
Go to solution

#pragma pack(push, 1)
typedef struct
{
uint8_t command;
uint8_t channelNum;
uint16_t dataLength;
}FramelessComPacketHeader_t;

 

#pragma pack(push, 4)

struct CommandPacket {
       uint16_t frame;
       FramelessComPacketHeader_t hdr;
      char data[];
};

 

 

I would like to send CommandPacket structure to the visa port. I know i need to create the cluster and convert in to the byte array, then Byte array convert in to the String. It is not working in my case. 
few question regrading cluster Creation?

1) How can I create the cluster elements with pointer of char array (pointer to first element in array)?

2) why cluster to array give error?


 

Download All
0 Kudos
Message 1 of 6
(2,935 Views)
Solution
Accepted by topic author Y@sh001

Flatten To String is your friend.

 

What I would do is have a VI with inputs for the Frame (U16), Command (U8), Channel Number (U8), and the data (string).  You can use String Length to get the dataLength value.  Bundle the Frame, Command, Channel Number, and data length into a cluster and use Flatten To String.  You can now use Concatenate String to add the data to this flattened data.  You now have the data to write through the VISA Write.


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
(2,925 Views)

Thank you I completely understand your approach.I have little doubt. You make Pack of  one byte for Frame (U16), Command (U8), Channel Number (U8), and the data (string). 

If I will make pack of 4 byte then which change require in  Frame and data. 

 

#pragma pack(push, 4)

struct CommandPacket {
uint16_t frame;
FramelessComPacketHeader_t hdr;
char data[0];
};

 

1) do I need to take Frame (U32)? if I am writing hex value then I  need to make change data type "Hexadecimal". am  I right? 

2) which change do I need make in Data for making PACK OF 4 Bytes?

 

Thank you,

Yash

0 Kudos
Message 3 of 6
(2,912 Views)
Solution
Accepted by topic author Y@sh001

Y@sh001 wrote:

1) do I need to take Frame (U32)? if I am writing hex value then I  need to make change data type "Hexadecimal". am  I right? 

2) which change do I need make in Data for making PACK OF 4 Bytes?


1. Frame is listed as a U16 in your C++ code.

2. You are not really send "Hex" values.  I say that since it can be interpreted a few different ways.  You are sending the raw data as a computer understands it.  I tend to show my data strings in Hex format to make it easier to see what data is in it.

3. For a pack of 4 bytes, you will have no data and therefore no data length.  Just bundle your Frame (U16 = 2 bytes), Command (U8 = 1 byte), and Channel (U8 = 1 byte) and then flatten that into a string.


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 4 of 6
(2,888 Views)

When you refer to pack, are you referring to how the data is stored That is, does pack 4 mean that the data is aligned along 4 byte boundaries? If that is the case you will need to include pads to force the alignment. So, you may need to have your frame be a U32. Then you will need to take into consideration if the receiving device is using big endian or little endian.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 6
(2,866 Views)

Thank you Mark for giving me guidance regrading padding. I was thinking due to prgma-pack, structure will take padding,  but in reality strict type in structure member, It is no taking extra bytes of padding. Currently I am able to send correct databytes to the Visa Port. 

Thank you for inform me about adding padding on Labview.  

 

-Yash

0 Kudos
Message 6 of 6
(2,852 Views)