LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting ASCII Hex into raw hex bit level code

Folks,
 
I'm trying to convert a ASCII Hex Text String to raw bit level code.   The resultant is generally unprintable ASCII code that is sent to a serial interface.  I can manually input text using the '/s' option or I can pass known constants doing the same.  However, I have been unsuccessful in GENERATING code that outputs this format.   Any help is appreciated.
 
 
Thanks,
 
 
 
Rick H.
0 Kudos
Message 1 of 32
(10,295 Views)
Have a look at the Byte Array to String function. It converts an array of bytes (U8) into an ASCII string and should be the easiest way to do this.

___________________
Try to take over the world!
Message 2 of 32
(10,284 Views)

Nope,  that isn't what I need.  I generate an array of ASCII HEX, that Ineed to convert to raw '/s' format.  ALTHOUGH BINARY,THIS IS NOT 0s and 1s! It produces the raw form/NON-PRINTABLE ASCII.

Thanks for your help

 

Rick H 

0 Kudos
Message 3 of 32
(10,280 Views)
I'm a little confused on what you are asking for. What is '/s' format and where are you specifying that? Do you have a string such as 'A' )normal display) and want to do a VISA Write of '10' (hex display)? Or do you want to convert the string to a numeric?
0 Kudos
Message 4 of 32
(10,262 Views)

/s is a format specifier.  This is a clip from the help file:

For functions that produce a string as an output, such as Format Into String and Array To Spreadsheet String, a format specifier uses the following syntax elements. Double brackets ( [] ) enclose optional elements.

%[-][+][#][^][0][Width][.Precision || _SignificantDigits][{Unit}][<Embedded information>]Conversion Code

where Width must be a number greater than zero and .Precision and _SignificantDigits must be a number greater than or equal to zero.

For functions that scan a string, such as Scan From String and Spreadsheet String to Array, a format specifier uses the following simplified syntax elements.

%[Width]Conversion Code

The Format Into String, Format Into File, Scan From String, and Scan From File functions can use multiple format specifiers in the format string parameter, one for each input or output of the expandable function.

You use format specifiers to format strings, convert a number into a string, and insert non-displayable characters in strings. Refer to the examples of format specifiers for more information.

 

Now if I could only convert this data into this /s format, I could finally get on with my job. 

 

Rick H.

 

 

 

0 Kudos
Message 5 of 32
(10,259 Views)

I assume you mean that you enter the values manually into the string control by changing its display to the backslash codes display (note - \ is backslash, / is forward slash), so that if you enter "\41" it is converted into "A". If you did the same thing with the function I mentioned, it would produce the same result with any ASCII character.

Since the only interface you have to the serial port is the string type, you have to represent the binary data as a string. The data is still binary, even if it is represented as ASCII.

If what you want is to be able to write "41" into a string and convert that into your binary string, then simply use the Hex String to Number function on the different pieces of your string and wire the result into the BATS function.

If all this still doesn't help, I suggest you upload a VI with a sample of your source data and your target data so that we can understand exactly what you want. If you are putting data into controls, remember to set their value to default before saving.


___________________
Try to take over the world!
0 Kudos
Message 6 of 32
(10,248 Views)

'/s' is not a format specifier. Format specifiers are '%' something. For example, if you use %x with Scan From String, it will convert the string input to a hex number.

You still haven't explained exactly what you want to convert from and to. In your other post (and you should keep posting to the original question instead of starting a new thread), it looks like you want to convert a number to a string. Besides the byte array to string already mentioned, you can use the typecast function.

0 Kudos
Message 7 of 32
(10,244 Views)

Dennis, correct you are!  Thanks for pointing that out.  As for my conversion program.  I am generating a two byte(high and low) hex value (E.g, FFFF) that is placed into a serial port that interfaces an FPGA state machine.   The data to the serial port/state machine is raw ascii, NOT INTELLEGENT STANDARD ASCII CHARACTERS.  CONSEQUENTLY, IT PRODUCES CHARACTERS THAT REQUIRE THE HEX OPTION TO VIEW AND SEND.   I CAN'T SEEM  TO CONVERT MY NEWLY CREATED STRING INTO THIS DATA FORMAT. 

I'm sorry to share my frustration, but this is the third time I have presented this problem to the NI group or tech support and have not recieved a remedy. 

Rixk H

0 Kudos
Message 8 of 32
(10,240 Views)

BTW here is my communication tool I'm using to talk to the device manually.

 

regards,

 

Rick H

0 Kudos
Message 9 of 32
(10,229 Views)
Every character is ASCII. It might not be printable, but it is ASCII. An ASCII character is made up of 8 bits, so any 8 bits you will put together will produce an ASCII character. "\FF" is simply 11111111.
 
I can't look at your code, but the attached should demonstrate this (I hope). If you want to start with a string, then you need to go over the string 2 characters at a time and convert it to an array of bytes. 

___________________
Try to take over the world!
Message 10 of 32
(10,223 Views)