LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert 3 Bytes to 16 Bit Decimal Number

Solved!
Go to solution

@mattespotter wrote:

Hello, I have the following problem:
From a RS-232 I recieve three Bytes (each consists of 8 bits and the first one is a Start Byte, it will be repeated) per second:


1. Byte (Start Byte):  01000000
2. Byte (Random): B8 B9 B10 B11 B12 B13 B14 B15
3. Byte: (Random): B0 B1 B2 B3 B4 B5 B6 B7


Thank you, Regards mattes


 

I think this will work (using altenbach's VI) to change the bit order for bytes 2 & 3. It's a little cleaner than what you did. Right click the "Boolean Array To Number" and under "Properties" you can change the Output properties to U16 without adding two U8 Conversions and joining them.

 

NOTE: It's been a while, but I ran a benchmark on the various ways to change the bit order for a CRC algorithm. I found this method to be the fastest.

 

data conversion.png

Object Properties.png

0 Kudos
Message 11 of 17
(1,639 Views)

@jamiva wrote:

 

NOTE: It's been a while, but I ran a benchmark on the various ways to change the bit order for a CRC algorithm. I found this method to be the fastest.

 


I would bet that a lookup table would be faster. It can be hardwired as diagram constant and all you need is an "index array". No green stuff. 😮

 

@jamiva wrote:

I think this will work (using altenbach's VI) to change the bit order for bytes 2 & 3. It's a little cleaner than what you did. 

 If you would unflatten as little endian, you could omit the byte swap. 😄

Message 12 of 17
(1,632 Views)

You are absolutely correct. A lookup table is much faster (less than 7nS per iteration). I also ran a benchmark for the other method and it was more than 110nS, factor of >15x slower.

 

I probably did not try to use a lookup table because I was using 32bit intergers at the time. The lookup table would have had over 4 million elements if I used all 32 bits at once. But you made me rethink my algorithm. Instead, split the number, do a byte by byte reversal, then build up the 32 integer.

 

My goal is to learn something new every day. I just did. Kudos

 

Chart.JPG

 

Benchmark.png

0 Kudos
Message 13 of 17
(1,618 Views)

You could just cast to a U8 array with two elements, iterate over it using the lookup table, and cast the result back to U16.

 

(You do know that "index array" is resizeable? You only need one instance in your code.)

0 Kudos
Message 14 of 17
(1,611 Views)

Also please note that we cannot use any LabVIEW snippets that are inserted as images here (instead of included as attachments).

 

See here for details.

0 Kudos
Message 15 of 17
(1,596 Views)

@altenbach wrote:

Also please note that we cannot use any LabVIEW snippets that are inserted as images here (instead of included as attachments).

 


altenbach

 

Am I missing something? I agree that you can't directly drag the snippet into the block diagram. But if I click on my (or any other) image, I get the following pop-up. I can then click on the "download" button" (top red arrow). Another prompt comes up to "Save" the png file to disk (bottom red arrow). I can then drag that saved snippet to my block diagram.

 

I use IE 11 and this works with my browser. Why can you (and others) not use the snippet inserted as images??

 

Pup-Up Window.png

0 Kudos
Message 16 of 17
(1,572 Views)

@jamiva wrote:

@altenbach wrote:

Also please note that we cannot use any LabVIEW snippets that are inserted as images here (instead of included as attachments).

 


altenbach

 

I use IE 11 and this works with my browser. Why can you (and others) not use the snippet inserted as images??

 

 


I'm going to post a link to Snippets are broken? that goes into more details.

 

Basically, the forums did an "upgrade" to the way images were handled.  Long time members are used to the way images and snippets used to work.  You could just drag the image from the browser directly to the block diagram, (or browser to desktop to block diagram in the case of Firefox, maybe other browsers).  It worked.

 

Now if you do that, you don't get valid code, but just a picture on the block diagram.  You have found the one way that does seem to work.  It took several days for that method to be discovered because no one really had ever seen the new image viewer popup.  Unfortunately, while the image viewer does work, it is not a great solution.  What used to take only 1 or 2 steps to get a snipped into LabVIEW has now devolved down to about 4 or 5 steps to clear all the popup dialogs and "Are you sure?" dialogs, and find the download folder and drag and drop and drag and drop again.

 

I believe if the snippet is attached to the message, then that location is inserted into the message, the old drag and drop method works.  But if you use the new image uploader to insert the image, it somehow breaks the snippet if you use the old method, but using the viewer popup to get the snippet and going through all the extra steps does not break the snippet.

 

 

0 Kudos
Message 17 of 17
(1,566 Views)