LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Receiving the correct byte order using Visa read

Hey guys.

I have a data sending program which sents to my serial port a package with the following format:

1XXXXXXX 1XXXXXXX 0XXXXXXX 0XXXXXXX

Meaning that I receive 4 bytes - first and second begin with 1, third and fourth with 0.

Besides that identification, there is no start byte or stop byte.

I am now building a labview program to receive this data and process it, but I can't get those bytes in the right order.

As we know, serial communication is asynchrounous with the Visa Read function in Labview.

As far as I have discovered, I need to read 4 bytes at a time and search my byte array for the right order.

The problem is that I am unfamiliar with the labview interface, so I don't know how to build a structure that check my byte array and order the bytes in the right sequence (or show me an error message in case they're corrupted).

Can anyone help me to interface a solution?

I'm attaching a print-screen-preview of what I'm trying to do and the VI itself. What i'm missing is between the String to Byte Array and the Shift Register, or at least I think so.

I'd be grateful with any help.

Thanks,

 

Download All
0 Kudos
Message 1 of 6
(3,462 Views)

You can AND your 4 byte array with a number in binary as 1000 0000   That will mask off all 7 data bits and leave you with the mot significant bit as either 1 or 0.  Do a >0 on that array and now you have Trues where your most significant bit is a 1.  Now you'll have either TTFF (what you want) so you can read 4 bytes on every loop iteration after tha.  TFFT.  Read 3 more bytes to realign your data.  FFTT.

 

Now inside the loop you can read 4 bytes every time and your data will be aligned.

 

Message 2 of 6
(3,425 Views)

Assuming your data always arrives as the 4-byte pattern you describe, I like RavensFan suggestion for how to synchronize the byte stream so you will get 4-byte sequences in the correct order.

 

In the VI you posted, you used the following code to ask the question "Is the most significant bit set?" --

MSB Set 1.png

 

This seems to me to be simpler (and probably faster):

MSB Set 2.png

Bob Schor

Message 3 of 6
(3,392 Views)

Hey guys.

I'm sorry for taking so long to answer.

Bob, thank you for your solution. I tested it and will upgrade the program later.

Ravensfan, thanks for your help, but I believe my problem is still on.

When I run the test with Highlight Execution off, my boolean light is always off.

When I turn it on, I see only zeros in my shift registers.

So I tried to change the byte count on the visa read inside the while loop to 1.

This way, with highlight off, my boolean light is always on.

But still, with highlight on, I receive the bytes out of order (because i'm reading 1 at a time).

It turns out to:

- why am I receiving only zeros in the first case?

- why the program works without highlight in the second case?

Thanks for any help.

 

0 Kudos
Message 4 of 6
(3,314 Views)

1. Make sure the termination character is turned OFF.  That could potentially cause you to not read enough bytes.

2. You are throwing away data you need to verify in your loop.  Do the shifting and the check directly on the 4 byte array that you read.


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 5 of 6
(3,301 Views)

Crossrulz had a good point of disabling the termination character that I hadn't noticed.  Is in loop check confirming the synchronization is a nice addition as well

 

I don't know why you tried  to take what I did and blend it in with what the code you had before.  If I thought the crazy loop with a 4 layer shift register was a good idea, I wouldn't have taken it out.

Message 6 of 6
(3,274 Views)