LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to hex

I am having trouble converting a 8 bit string (ie 11111111) to hex (ie FF)....
 
Anybody have some pointers? As you may understand, i am not an expert in LabVIEW, yet...
 
0 Kudos
Message 1 of 9
(10,902 Views)
Hello vatoloco,

I changed your vi a little bit 🙂

For conversion between different representations you can use the "scan from string" and "format into string" with different format codes (see LabView help!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(10,898 Views)
Thank you GerdW!
 
This did exactly what i wanted!
 
I am trying to send this value to a microcontroller (AVR Mega128) for further processing, but it seems like the "VISA Write" function needs more consideration.... The microcontroller does noet seem to recieve the correct value...
 
Here is what i have done so far, any comments to this would be greatly appreciated! (Disregard the VISA Read part, as i used this only to test my program using a RS232 Loopback connector).
 
0 Kudos
Message 3 of 9
(10,885 Views)
Hello vatoloco,

without looking at your vi:
do you really know that your µcontroller needs strings with hex formatted numbers? Or does it take just plain bytes?

Explanation:
If you send a string "FD" to your device it receives two bytes containing 0x46 0x44 (hexadecimal representation of ASCII code 70 for F and 68 for D). But you can also just send a byte containing 0xFD to your device...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 9
(10,866 Views)

Thanks again GerdW,

 

You are right, i need to send my 8 bit string as a byte to the µcontroller. But i am having trouble converting my string to a byte... "String To Byte Array" seemed applicable, but "VISA Write" does not accept array as input....

 

Any inputs on this?

0 Kudos
Message 5 of 9
(10,855 Views)
Hello vatoloco,

easiest could be to use "Index array" after conversion of string to array of U8. If you want to index the first array element you don't need to wire a "0" to the index input...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 9
(10,842 Views)
Hello vatoloco,

and what do you think about the change in the vi?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(10,837 Views)


@vatoloco wrote:

Thanks again GerdW,

 

You are right, i need to send my 8 bit string as a byte to the µcontroller. But i am having trouble converting my string to a byte... "String To Byte Array" seemed applicable, but "VISA Write" does not accept array as input....


You took the wrong one of the two functions. A string in LabVIEW is really the same as a Byte Array. It is just a different wire color and uses different controls that can display the data in different ways.

So you can create an array of Bytes (Build Array with one single input of your 8bit integer) and then convert it to a string and pass it to VISA Write. Alternatively you can also Typecast the number into a string which will basically do exactly the same as afor mentioned two functions together. If you have multiple bytes to send you will get an array of bytes already and then using Byte Array To String will convert the array into the string that is required by VISA Write. Typecast in that context is then doing exactly the same as
Byte Array To String, but in your case I would use Byte Array To String as that is a little bit more intuitive.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 8 of 9
(10,829 Views)

Thanks guys! It seems like i was trying to do this in a very complicated manner, the true/false option with build array seems like a better solution.

The issue of sending a byte to the microcontroller is still unsolved though, and is the "topic of the day" for me:)

Thanks again for all your help!

 

 

Message Edited by vatoloco on 02-06-2006 03:39 AM

0 Kudos
Message 9 of 9
(10,794 Views)