LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Raw hexadecimal string to real number with 2's complement

Solved!
Go to solution

@altenbach wrote:

Maybe you should configure your serial I/O to use defined termination characters instead of fixed size reads. I am not a "serial" expert, so others might have more specific advice here.


Not when the data is hex/raw/binary.  The termination character can easily be found in the data.  But there is typically a set protocol for the messages.  So follow the protocol.  In this case, you can read 1 byte at a time until you find the first start byte, then read another byte and verify it matches the second byte.  From there, read the rest of the 18 bytes in the message.

For more details: VIWeek 2020/Proper way to communicate over serial


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
Message 11 of 20
(961 Views)

Thanks a lot Altenbach, that's really helpful and informative.

 

So as far as I understood of the documentation for now, there is no end character as the device is in trigger mode:

You send anything (in my example I just send "1" as a string and the device answer with those 20bytes. 

In my example I just happened to miss one 😄

It's an interesting idea to get this error handling possibility, but then it shouldn't appear.

However, while it is not meant to work at high speed (technically a trigger every half a second or even every seconds should be enough) I did notice that if I trigger it too fast (20ms or so), it tends to sometimes send more than 20 bytes. I haven't investigated it yet, but my guess is that one message didn't have the time to get created by the device, the answer was then empty ans so the next message is then the answer of the previous trigger + the new one.

When I noticed this, I was reading one byte at a time in a while loop and exiting on timeout.

 

 

 

 

 

0 Kudos
Message 12 of 20
(948 Views)

After coming back to it, here is what I believe would be a good working solution for me.

RawString_to_angle.png

As I still need to analyse the status of each axis (1byte for each), I came up with the idea of simply "shrinking" the i32 into a U8 to get only the LSB.

 

I "just" need to analyze those status bytes now.

Thanks again, have a great day and weekend.

0 Kudos
Message 13 of 20
(943 Views)

@VinnyAstro wrote:

After coming back to it, here is what I believe would be a good working solution for me.

.


Have you even tried that? This will not work because the fields in the string don't correspond to the cluster order.

 

To look at the LSB, simply AND with 255 and convert to U8. Wrap the entire thing into a subVI that receives the string and outputs the scaled values and an error status.

0 Kudos
Message 14 of 20
(934 Views)

@altenbach  a écrit :

 

Have you even tried that? This will not work because the fields in the string don't correspond to the cluster order.

 

To look at the LSB, simply AND with 255 and convert to U8. Wrap the entire thing into a subVI that receives the string and outputs the scaled values and an error status.


I did, and I was getting the expected results. here is a try with an example frame easily identifiable

VinnyLaTaupe_0-1610959039155.png

The fields in the string are:

Identifier (2B) | X data (4B - MSB:DATA1 | DATA2 | DATA3 | LSB:Status) | Y Data (4B) | Z data (4B) | Gyro Status (2B) | Counter (2B) | CRC (2B)
 0000 | AA|AA|AA|11 | BBBB BB22 | CCCC CC33 | DDDD | EEEE | FFFF

Now I don't really need the identifier in my setup (only one device) thus reading only from the 3byte on.

So it should be fine that way no? But I've tried as well with the AND with 255, it gives me the same results 🙂

 

 conversion

EDIT: I forgot that in between I also inserted a U8 conversion as I don't like leaving the automatic conversion to labview 🙂

0 Kudos
Message 15 of 20
(917 Views)

A picture of the front panel is not helpful. Attach your latest Vi containing useful default data in all controls).

 

I did not notice that you now remove the first two bytes from the string first instead of parsing them. Shouldn't they be part of the data structure?

0 Kudos
Message 16 of 20
(911 Views)

@altenbach  a écrit :

I did not notice that you now remove the first two bytes from the string first instead of parsing them. Shouldn't they be part of the data structure?


Not really, at least for now. The identifier is just if I'm communicating with multiple devices, which for now isn't the case. I am just running a few tests to see if it is performant enough.... and also to prepare/train for a bigger code.

Here is my VI. I still need to process the Status values. I'm reading a log file 20B by 20B for now, so my input is an array of 20B string. I've run a 10min test with a 1s triggertime (1 measurement every seconds.)

 

0 Kudos
Message 17 of 20
(906 Views)

@VinnyAstro wrote:

@altenbach  a écrit :

I did not notice that you now remove the first two bytes from the string first instead of parsing them. Shouldn't they be part of the data structure?


Not really, at least for now. The identifier is just if I'm communicating with multiple devices, which for now isn't the case. I am just running a few tests to see if it is performant enough.... and also to prepare/train for a bigger code.

Here is my VI. I still need to process the Status values. I'm reading a log file 20B by 20B for now, so my input is an array of 20B string. I've run a 10min test with a 1s triggertime (1 measurement every seconds.)

 


This is a decidedly anti-scalable, anti-maintainable path you are going down here.  Better to decode it correctly and not do anything with a few fields now, than try to add them in later.  Especially if you are "preparing/training for a bigger code".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 18 of 20
(897 Views)

I agree that your data structures are not very intuitive, but it really depends on how they are used later.

 

Note that placing your error indicator inside a fast  loop will make you miss most errors. For example you string at index 32 will give you an error (It's too short!), but you'll never know about it in the current code!

 

altenbach_0-1611002537997.png

 

 

Message 19 of 20
(880 Views)

Ah yes I'm aware that this is definitely not the most scalabale way to deal with it, especially I will still need to deal with all status and errors.

But it was a perf test on this device to see if we're going with it or not, and then I got intrigued into understanding and learning this whole 2's complement thingy.

The FOR loop will not even exist if we go for it, I was given some log files acquired by a terminal software and had to analyze them 🙂

 

Thanks again for all the help and advices, really appreciate it.

0 Kudos
Message 20 of 20
(871 Views)