LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number to binary

i want to send 8 bit nos. 0-255 to serial in binary form. When i tried to type "250" to the write buffer of VISA write, the vi seems to treat the no. 250 as three no. 2,5 and 0.
All i want is when i send "250" to VISA write, the vi will convert it as 11111010 to serial port (1 byte)
Please help.
Thank you very much
0 Kudos
Message 1 of 5
(3,726 Views)
There are two ways. Set the string control to Hex Display and enter your number in hex and write that value, or use a numeric control of U8 data type, type cast that to a string, and write that out the port.
0 Kudos
Message 2 of 5
(3,726 Views)
Dennis Knutson wrote in news:506500000005000000E8850100-
1079395200000@exchange.ni.com:

> your number in hex and write that value, or use a numeric control of
> U8 data type, type cast that to a string, and write that out the port.

or
Create an array of U8 and connect it to the function "Byte Array to String"
(the "String -> String/Array/Path Conversion" palette)

--
Rolf
0 Kudos
Message 3 of 5
(3,726 Views)
Dennis and Rolf,
Thank.
The input signals are single 32 bit real number "SGL", as you said, i tried to covert them to hex display or U8, here are my problems
(i)i can't covert them into hex display but hex string only.(ii) type cast seems to display the correct ASCII string from 0-127 only, from 128-255, it don't work (iii) how to further covert the data into binary codes? i tried "number to boolean array' and boolean to (0,1) function. is there any example? i search in the forum but i can't one. Maybe i overlooked them.
i attach my vi, please point out where i did wrong, thank you very much for your help
Best Regards
nick
Download All
0 Kudos
Message 4 of 5
(3,726 Views)
Hi Nick,
You might need to explain what you are trying to do a little more clearly. Are you trying to send 8 bit numbers between 0 and 255 (unsigned 8-bit integers) or are you trying to send 32 bit real numbers (singles)? For the first option, all you need to do is wire the numbers to a string type cast, and then wire the output of it into your Serial Write. The string being written won't make sense if you display it because the display will map the integer numbers to their ASCII character values (will show up as garbage most likely), but the output to your serial port will be the raw integer numbers. If you are using floating point numbers (singles) then you should probably check to make sure that your instrument doesn't expect strin
gs instead of the binary representation of the floating point number. You can convert a floating point number to it's IEEE floating point representation, but it's rare for instruments to want this. If this is what you are looking for then this example might be of use:
http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B123AE0CBCC2111EE034080020E74861&p_node=DZ53046
0 Kudos
Message 5 of 5
(3,726 Views)