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: 

How to easily convert Hex string to Binary string?

Solved!
Go to solution

Hi,

I want to write a microcontroller by using LabVIEW 2015. I need to convert a Hex string to a Binary string. In the attached vi, it does the job. However, I have to create a file. After the binary file is read, I have to delete the file. It slows down the process. I am just wondering whether there is a easy and fast way to do that? I am using LabVIEW 2015. An example hex file (Program Memory.bak) is attached. After running the attached vi, a binary file is created automatically.

Any help will be appreciated.

Steve

0 Kudos
Message 1 of 12
(3,183 Views)

Is it not really different to operate on a string in memory or from a string from a file. Not sure where you have problems.

 

(Also, none of your local variables are needed and could even give rise to race conditions. You can set the execution option to "clear indicators when called".)

0 Kudos
Message 2 of 12
(3,170 Views)

Thank you for the reply. I want to convert Hex string to Binary string directly to write to a microcontroller, instead of to create a binary file, read the binary file and in application program to delete the binary file after the binary file is read. All the other staff in the vi are just for troubleshooting the vi.

Regards,

Steve

 

0 Kudos
Message 3 of 12
(3,156 Views)

How do you communicate with the microcontroller?

0 Kudos
Message 4 of 12
(3,149 Views)

All the other staff in the vi are just for troubleshooting the vi temporarily.

0 Kudos
Message 5 of 12
(3,148 Views)

I write the binary file to the microcontroller by a RS232 port.

0 Kudos
Message 6 of 12
(3,146 Views)

@Shijie wrote:

I write the binary file to the microcontroller by a RS232 port.


But how? Using LabVIEW?

 

You seem to have a communication problem, not a conversion problem. Maybe you can have a moderator fix the subject line.

0 Kudos
Message 7 of 12
(3,139 Views)

I am sorry for the confusion. I only posted the Hex to Bin part, not the whole program.

Regards,

Steve

0 Kudos
Message 8 of 12
(3,130 Views)

The attached vi works. I am just wondering whether there is a easy and fast way to do it?

Regards,

Steve

0 Kudos
Message 9 of 12
(3,116 Views)
Solution
Accepted by topic author Shijie

Allow the FOR loop to build an array of U8 and then use Byte Array To String to convert to your string.  You should also use the "offset" on the Scan From String so you can avoid a lot of string memory allocations.


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
Download All
Message 10 of 12
(3,100 Views)