LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing from binary to ascii for pda

Hi all,
I am currently using a tilt sensor which is used to measure an angle. The output from the tilt sensor is in binary format and i want to change this to ASCII format in order to read the output. The program will be run from a pda so it will have to be compatible with this. I would really appreciate any help with this.
Thanks in advance,
Lil
0 Kudos
Message 1 of 11
(4,860 Views)


Lil a écrit: ... The output from the tilt sensor is in binary format and i want to change this to ASCII format in order to read the output...
What do you mean with "binary format" ? Can you provide an example ?
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 11
(4,854 Views)

This is the example that was provided with the spec sheet. i dont know if this is any help. i am currently using software called vxHPC on the pda which is similar to hyperterminal for the pc. At the moment this is not showing any info coming from the tilt sensor but i am told this is due to the fact that the tilt sensor is ouputting in binary but vxhpc will only accept ASCII. i have previously written a simple read and write program in labview to communicate with a programmable psu and when i run the program connected to the tilt i get a load of -well waffle- in the reponse section which i presume is the tilt communicating but that it is not being recognised.

I hope this gives a bit more background but if you need more info please ask.

Data format:

The MSByte is sent first.

9600baud rate

1 start bit

1 stop bit

Parity Even

Start,b0,b1,b2,b3,b4,b5,b6,b7,Stop

Examples

Byte 1001 0110 and 0101 0101

A/D converter

Hex 195 Dec 405 -56.27 Deg

Byte 1101 1110 and 0011 0011

AD converter

Hex 3B3 Dec 947 -37.71 Deg

Cheers Lil

0 Kudos
Message 3 of 11
(4,831 Views)


Lil a écrit: ... Examples

Byte 1001 0110 and 0101 0101

E466

A/D converter

Hex 195 Dec 405 -56.27 Deg


The binary to HEX conversion does not make much sense to me. The bit pattern correspond to $9655. Even using Gray code, this gives $E466. The fact that the last nibble is repeated twice (0101 0101) while there is not char repetition in the corresponding Hex string is unexpected.

Nor can I translate 195 into -56.27


The communication seems to flollow a simple and standard  serial protocol, but the information coding is not simple. Seems that you'll need to provide more details...

Chilly Charly    (aka CC)
0 Kudos
Message 4 of 11
(4,820 Views)
I did some progress. Your converter is a 12 bit converter, coding the tilt angle from -70° to +70° ($000 to $FFF). 0° is 2048 ($800). Now I have to figure out what the bit coding is... 😉
Chilly Charly    (aka CC)
0 Kudos
Message 5 of 11
(4,807 Views)
i have figured out the coding. The first two bits of each byte have to be stripped out which leaves the remaining six bits of each byte. The twelve remaining bits then have to be put together to form the result. For example Byte 1000 1110 and 0011 0011 will give when the frist two bits are removed ( which represent the msb and parity in first byte and lsb and parity in second byte) 00 1110 11 0011, which when converted to decimal will give 947.
What i have reading in to my program at the moment is what i am presuming is the ASCII equivalent (series of brackets and dashes and the like) so i need to convert this to the binary first and then into decimal and then to a number. At the moment the program is reading in continously but i will need it to read in just the first two bytes and then hold, all of which i am at a loss how to do at the moment.
I am very grateful for the help so far!
Lil
0 Kudos
Message 6 of 11
(4,800 Views)

The two-bits stripping was not at all evident to me. Did you discovered it, or was it explained somewhere ?

When applied to the other bit string provided as example, it yields a different result ($595 - dec 1429) instead of $195 (dec 405). Are byou sure of your code ?

Chilly Charly    (aka CC)
0 Kudos
Message 7 of 11
(4,795 Views)

Well the spec sheet pointed me in the right direction but it was very unclear and did take me some time to figure out. If you use the same theory for the other example then the binary of 00 1110 11 0011 will yeild 947 dec.

i am providing my first attempt at the program which is very simply recieving the data from the tilt and displaying what i presume is the ascii equivalent as the response is currently reading in a string. What i need the program to do is to take the two bytes of info (msb&lsb) and strip out the first two bits of each byte. Then the 12 bits remaining have to be put together and converted to decimal. I am very new to this language and all of this is way beyond me so any help that you could provide however small would be great!

Cheers,

Lil 

0 Kudos
Message 8 of 11
(4,785 Views)
Just after realising that what my program is actually reading in is just symbols which will have to be converted into ascii(decimal) values. I know i am not being very clear but im just trying to muddle my way through at the moment.
Lil
 
0 Kudos
Message 9 of 11
(4,778 Views)
Here is a quick solution, that takes a string, converts it to binary, strips the 2 high bits, displays the Hex, Dec and Bin results, then calculates the tilt. Yet I still have a problem with the second example...
Chilly Charly    (aka CC)
0 Kudos
Message 10 of 11
(4,776 Views)