From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

hints on creating a hex byte array

Solved!
Go to solution

i'm communicating with a plc by sending serial data commands as hex bytes. for example 

02 30 31 34 32 33 59 30 30 34 31 31 41 03 

i've implemented the communication protocol and everything works fine. i send my commands and i get the right response.

 

the problem: i need to insert in my vi 3x55 = 165 at least of these commands in that format. obviously i could copy-paste them in a string variable and do my job. but i need to find a more practical way as they could change in future. thought of creating a txt with the commads and then create 3 string arrays in my vi but i still need to send HEX data.

 

i can have my commands in almost any form i want as i generate them in python. 

e.g. 

02 30 31 34 32 33 59 30 30 30 30 31 35 03 (HEX) or

2 48 49 52 50 51 89 48 48 48 48 49 53 3 (DEC) or 

0x02 0x30 0x31 0x34 0x32 0x33 0x59 0x30 0x30 0x30 0x30 0x31 0x35 0x03

 

this works almost fine but converts me 02 -> 0 to 30 and 2 to 32.

and this is what i get (Display as HEX in array properties). i just need the line string of the txt to be interpreted as a hex and build an array. 

 

any help will be appreciated. thanks in advance.

 

 

 

 

0 Kudos
Message 1 of 4
(3,787 Views)

Hi afetsis,

 

replace the ConvertToHexString by a TypeCast function (in the innermost loop)…

 

General recommendation:

When you want quick help you should attach a "real" VI (or atleast a snippet) instead of pictures. Images are hard to debug with LabVIEW!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(3,778 Views)
Solution
Accepted by topic author afetsis

Your code is too complicated.  First of all, there is a right-click option for the Read Text File to read the lines.  Then you can autoindex on the lines, eliminating one of your loops.  Secondly, you can do all of the parsing and conversion of your line of data with just the Spreadsheet String To Array function.

 

Spoiler
I'm starting to feel like Altenbach right now...

 


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 3 of 4
(3,755 Views)

eh. thanks for that but been using labview for about a month and im a bit noob. 

0 Kudos
Message 4 of 4
(3,733 Views)