11-30-2018 12:38 PM
#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?
Solved! Go to Solution.
11-30-2018 12:55 PM - edited 11-30-2018 12:56 PM
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.
11-30-2018 01:15 PM
Thank you crossrulz for quick reply. 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
11-30-2018 02:09 PM
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.
11-30-2018 04:11 PM - edited 11-30-2018 04:13 PM
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.
11-30-2018 05:45 PM
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