05-01-2015 08:07 PM
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
05-01-2015 08:23 PM
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.
05-01-2015 08:46 PM
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.
05-02-2015 12:26 AM - edited 05-02-2015 12:49 AM
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.
05-02-2015 12:55 AM - edited 05-02-2015 01:01 AM
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)
05-02-2015 01:59 PM
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
05-02-2015 03:44 PM - edited 05-02-2015 04:04 PM
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 (???).
05-02-2015 04:02 PM - edited 05-02-2015 04:05 PM
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?
05-03-2015 07:26 PM
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.
05-03-2015 10:33 PM
@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.