LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert digital signal to hexadecimal string?

Solved!
Go to solution

Hi!

 

My problem seemed to be very easy but I cannot find a simple solution. Namely, I have to make a simple project that acquires bits from a single digital line (not that it is important but I use one channel of a PXI 6552) and stores a certain number of bits (let’s say 1000 bits) from the channel in a txt file in hexadecimal format. I can convert it to a binary array of unsigned integers and make a loop that reads every 4 bits and calculate hexadecimal value but is it possible that there is no simpler way?!

 

Thank you!

0 Kudos
Message 1 of 8
(6,086 Views)

@salomiva wrote:

I can convert it to a binary array of unsigned integers and make a loop that reads every 4 bits and calculate hexadecimal value but is it possible that there is no simpler way?!


This description is not clear at all, but I guarantee you that there is a simpler way.

 

What is the datatype of the input? (U8, U16, U32, U64). Earlier you said that you are starting with a hexadecimal string... so what is it?.

What is the datatype of your output? (string?) 

What is a "hexadecimal value"? Hexadecimal is a type of formatting that translates bit pattern into the letters 0..F that can be read by humans. For example, you can take a numeric indicator and display it in decimal, octal, binary, or hexadecimal. It does not change the value, just the cosmetics.

 

Why don't you show us your code, some typical inputs, and corresponding desired output so we can tell what you are trying to do... Thanks!

0 Kudos
Message 2 of 8
(6,082 Views)

Thank you for your prompt reply! I understand that hexadecimal is just a format of presenting data but I have a problem to write digital data in that format to a txt file.  

 

To make it easier for understanding and for testing purposes as well, I have made a test program that reads hexadecimal values from a txt file (the structure of this file is the structure I need to get at the end), transforms it in a digital stream as I get from the pxi 6552 (I had to change a bit the VI DTbl Binary U8 to Digital Stream.vi), and write it back to a txt file. This test program still needs some fixing to make input and output file exactly the same, but for the start output file is a txt file with hexadecimal values of my digital stream. I was wondering if there is a simpler solution for the while loop in this example.

 

I hope this example made it clearer a bit.

0 Kudos
Message 3 of 8
(6,047 Views)

Your text file is weird. This looks like \-codes format. Is this really the raw string you get or did you set the string display to \-codes, for example?

 

You should set the datatype of the default value input of "hexadecimal string to number" to U8. You are currenty creating a U32 array that is coerced back to U8 at the subVI.

0 Kudos
Message 4 of 8
(6,027 Views)

Do you need the blue array at all or are you only concerned about the input and output file? In the latter case, you could do as in the attached VI.

 

 

(making the blue array would not add much code either ;))

Download All
Message 5 of 8
(6,016 Views)
Solution
Accepted by salomiva

And here's what you could do going via the blue array. No express VIs needed.

 

 

See if it works for you....

 

Download All
Message 6 of 8
(6,009 Views)

Note that the above code uses an 8bit lookup table (LUT) to improve performance.

 

Here's how it could be made:

 

 

0 Kudos
Message 7 of 8
(6,000 Views)

Thanks a lot! Your examples were of great help!

 

My real project is actually more complex than this, but I tried to make it as simple as possible to make it easier for understanding what my problem was. Namely, I have to acquire bits from a single digital line (2Mbps), searching for a certain 88bit pattern (BARKER) and after finding it I have to store 8000 bits from the channel in a txt file. This file has to be compared to an output file from a simulation so the file format is a request to me. It actually has to be in a form of 32 two-digit hexadecimal numbers (i.e. bytes) per row delimited by a tab (or space). Here is how I incorporated one of your solutions in my project.

0 Kudos
Message 8 of 8
(5,968 Views)