LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing binary representation of hex to serial port

I am trying to write hexadecimal numbers to the serial port. I have mistakenly sending the ascii string for the hex character instead of a binary representation of a hex character. Apparently a 00 should be represented on the serial port as two NUL characters instead of 30 30, etc (http://www.asciitable.com/).

 

StephenB

 

0 Kudos
Message 1 of 14
(4,329 Views)

Where is this data coming from?  What do you currently have?  What have you tried?

 

Assuming you have an array of bytes, you just need to use the Byte Array To String and write that to your serial port.


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
0 Kudos
Message 2 of 14
(4,316 Views)

My starting point is a 40 element boolean array. Here is the start I have made. I think, if I have understood correctly, then this output of the byte to string array will do the job as you suggested.

0 Kudos
Message 3 of 14
(4,306 Views)

00 is most likely a single nul character. You code does not look right. Change the output string to hex display and change the code so it looks right. I think you have 90% too much code.

0 Kudos
Message 4 of 14
(4,284 Views)

There are a few questions about byte order and where the LSB bit is, for example.

What is the output you are expecting from your 40 bit boolean array?

 

(e.g. x00000F0F29 or x0000F0F094 or something else)

0 Kudos
Message 5 of 14
(4,274 Views)

Can you post an example 40-byte array?  I wonder if this is supposed to be the binary representation of 5 bytes (5 * 8 = 40).  If so, you should be able to do the "translation" using (I think) two or three functions ...  [If you also know what the 40 bits might represent, even if not the exact value, that would really help ...]

 

Bob Schor

0 Kudos
Message 6 of 14
(4,241 Views)

His example program has a boolean array with 40 elements, so that's the default data.

 

00000000 00000000 00001111 00001111 00101001

 

Depending on how we define LSB and MSB for each byte, the result I get is either

 

00000F0F29 or

0000F0F094

 

However the (somewhat scrambled) default value of the indicator before running the VI is  (in regular format)  is:

 

0x000x000x0F0x0F0x29

 

Which (after some cleanup) seems to correspond th the upper version (???).

 

0 Kudos
Message 7 of 14
(4,231 Views)

Here are a few ways that would get you a 5 character string of "00000F0F29" (indicator set to hex display). There are many more ways.

 

Where does that boolean array come from? Did you convert that from a possibly much more conevenient original format?

 

(typically the lower array index contains the LSB, so I wonder if the original data already got processed incorrectly into the boolean array? Can you comment?

 

 

 

 

 

0 Kudos
Message 8 of 14
(4,224 Views)

I did reverse the binary array before conversion so that the MSB came first (not shown in the trimmed code sample). Instead of sending asciii formatted as hex for the 5 bytes, it needs to be in binary for an FPGA to read it. My understanding is that we are talking about binary as in binary file, not as in base 2.

0 Kudos
Message 9 of 14
(4,180 Views)

@stephenb2 wrote:

 My understanding is that we are talking about binary as in binary file, not as in base 2.


That statement make no sense whatsoever. Please explain what you mean.

0 Kudos
Message 10 of 14
(4,160 Views)