LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two ASCII characters into decimal value

Hello,

I have a problem with Doppler radar via RS232. I get data from radar as ASCII chars. Protocol consists of 13 bytes. Bytes 2 and 3 in this protocol are responsible for measured speed value. Now is the question: how to convert that two ASCII characters into decimal value of speed? First I use String to Byte Array block and from two ASCII chars I get two decimal values. What should I do next to get one decimal value? From manual for radar I only know that: 

2nd and 3rd data byte:
v, real speed with 16 bit resolution,
(1 LSB = (600 km/h)/216 = 0.009155 km/h)
value range: 0 km/h to 600 km/h

 

I will be very thankful for help

0 Kudos
Message 1 of 23
(3,798 Views)

Little confused by the formula there provided.  But I think it would look like this:

http://www.medicollector.com
Message 2 of 23
(3,787 Views)

Heh heh ... just realized that image looks bad.  But I think you get the picture.  You need to use a "Join Number" function to turn two 8 bit numerics into one 16 bit numeric.

 

Also a little unsure about the byte order.  But if that doesn't work, try switching the order of Byte 2 and Byte 3.

http://www.medicollector.com
0 Kudos
Message 3 of 23
(3,785 Views)

Take the two-byte substring and use unflatten from string with a type of U16 or I16. Adjust the byte order if needed.

 

(For more detailed help. can you attach a simple VI containing a raw example string as received as a diagram constant? Also indicate what the speed is supposed to be. Also indicate youtr LabVIEW version.)

Message 4 of 23
(3,775 Views)

Than You very much for help. Join Numbers works good and the speed values are OK. I have also the same problem with data bits responsible for distance value. According to manual:

 

4th and 5th data s1, path counter 1: 16 bit, 1 LSB = 0.1 m, value range: 0 m to 999.9 m
6th and 7th data S2, path counter 2: 16 Bit, 1 LSB = 0.1 km, value range: 0 km to 999.9 km
First I take two bits of S1 and join them, multiply x0,1 and I have meters counter
Second I take two bits of S2 and join them, multiply x0,1 and I have km counter, divided by 1000 I have distance in meters
The I sum S1 and S2 and I should have distance in meters, but something is wrong, graph looks like "stairs", not straight line.
Protocols one after another are in this file:

 

https://docs.google.com/leaf?id=0B8dlp0EyY6VPYTAzYzUyM2YtNTQxNC00NGYxLWEwMDEtMTRlMjg0MDJhZjU2&hl=en&...

One protocol consists of 13 bytes.

Bytes 3,4 - speed value

Bytes 5,6 - distance value (S1 according to manual)

bytes 7,8 - distance value (S2 according to manual)

Top speed on graph should be about 100kmph.

Thank You very much for help

0 Kudos
Message 5 of 23
(3,721 Views)

I forgot, bytes 3,4,5,6,7,8 are correct if counted from 0.

0 Kudos
Message 6 of 23
(3,701 Views)

Please attach your VI directly here.

 

(I recommend to get all fields at once using a type cluster. Can you give a quick table of the meaning of all bytes?

Is the first byte called "byte 0" or "byte 1")

0 Kudos
Message 7 of 23
(3,700 Views)

Code in attachment

0 Kudos
Message 8 of 23
(3,694 Views)

VI in attachment (LV7.0)

0 Kudos
Message 9 of 23
(3,693 Views)

Hi ,

 

Could you explain what you mean by a "type cluster"?

 

I am writing a lot of code where I need to extract data from an incoming RS232 stream.  I spend a lot of time decoding bytes and joining/splitting bytes.  I am wondering if your technique could save me some time.

http://www.medicollector.com
0 Kudos
Message 10 of 23
(3,685 Views)