LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial binary data with signed bytes

Situation:
 
RS-232 serial connection.
Receiving GPS Navagation binary data with some signed bytes.
 
For this question, just considering altitude.
This is in two particular bytes of the data.
 
The first byte is the LSB and the second byte (signed) is the MSB.
The two bytes are first concatenated
 
Then run through "Format Into String" and "Scan From String"
 
All's well as long as there aren't any values that are signed in the MSB.
 
Then I fail to get the correct answer.
 
Is there a better mouse trap here?
 
 
0 Kudos
Message 1 of 5
(5,170 Views)

Let's backup a bit. If you simply have a two byte string of binary data that represents a signed integer, you should simply type cast is as I16.

Unfortunately, you seem to complicate things quite a bit even though most of the early code is not visible in your image. You seem to create a binary formatted string with 16 digits, but then you read it as a binary string with 32 digits, meaning it'll swallow the sign bit as part of the 32 bit number. I also don't understand why you would use a DBL indicator to display a signed integer.

Can you attach a simple VI that contains your raw string as a diagram constant and tell us what altitude value you expect from it.

Most likely, the entire parsing of all values in the entire raw binary string can be done in very few simple steps. 🙂

0 Kudos
Message 2 of 5
(5,153 Views)
It seems that you are trying to get a signed 16-bit number from 2 unsigned 8-bit numbers, correct?  You join them by using Format To String and then which is clever, but is far from optimal.  And then using Scan From String and outputting a double from that is just plain confusing.  Furthermore, you tell it to scan for 32 bits, but you data is only 16 bits.  So I don't think you would ever see a negative number on the output from that.

You shouldn't be using strings at all to do this though.  You can form larger integers with Join Numbers or with Type Cast.  I'd recommend you stick with Join Numbers for now since it makes it clear what you are trying to do.  Type Casting requires that you know the data is represented in memory, but it is more powerful, in that you can convert data to and from arbitrary types, as long as they are the right size.  The attached VI shows both methods.

Also, if you want to input/display data in binary, or hex, or octal, even scientific notation, you can change the format that the numeric control/indicator by getting properties on it.  Much more convenient than converting to and from strings. 😉

Hope this helps,

John

Edit: It looks like you are using LV 7? Perhaps someone would be so kind as to convert the VI for me? 😕  The image should explain a bit, anyhow.


Message Edited by jbutera on 02-05-2007 12:01 PM

Download All
Message 3 of 5
(5,149 Views)

Using LV 8.2.

I just tried some suggestions from off the discussions groups regarding handling serial inputs.

Your suggestions appear to have great merit and are much simplier.

I'll give them a go.

Thanks.

0 Kudos
Message 4 of 5
(5,136 Views)

I still have the feeling that you are doing this way too complicated. Why do you even go through the detour of converting the original data string into a byte array, then slice out the segments and cast everything seperately.

If you have fixed fields in your string, all this can be done much easier and you get all data contained in the string with one simple operation.

The attached VI (LabVIEW 8.0) shows a simple demo. On the left, we synthetically and explicitely create a binary string from three integer numbers (I16, U8, I32) and reverse the byte order for little endian if desired.

The string display (hex display) shows the raw data.

To get all data back out in one operation, we can simply define a cluster that contains the names and correct datatype in the correct order and use it as type input for the unflatten operation. (sorry, the diagram has some typos, I only spend a few minutes on this ;))

Message Edited by altenbach on 02-05-2007 02:12 PM

Download All
Message 5 of 5
(5,122 Views)