From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Post processing the received serial data

Solved!
Go to solution

 

Hello,

I want to process the data received by comport in labview where the transmitter device sends 22 bytes of data in this format 0x01 0x02 <18 bytes of information data with LSB first> 0x03 0x0D through the comport which should be read using Labview. I want to process the received 22 bytes in labview as below

1)      Leave the first 2 bytes and last two bytes

2)      From the left 18bytes each consecutive set of 3 bytes should be reversed (because the transmitter sends the LSB first) and stored in a text file.

Can anyone suggest me the steps to implement this.

Thanks.

0 Kudos
Message 1 of 15
(3,075 Views)

I'd probably do something like this.  Use a String Subset to get just the data part of the stream.  Change that string into a byte array and use Decimate Array to break up the array into 3 parts, each containing every third element.  Then use some Join Numbers to combine the bytes into a U32 and format your data into a string with Array To Spreadsheet String.  I didn't show it, but you can then take that data and write it to a text file.


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
0 Kudos
Message 2 of 15
(3,061 Views)
What have you done so far? The basic functions to use would be to use the String to Byte Array and then the Index Array. You have not mentioned whether you want to convert the 3 bytes to a floating point number or not.

You have several options to write to a text file. Write to Measurement File or Write to Spreadsheet File, etc. Look through the examples that come with LabVIEW.
0 Kudos
Message 3 of 15
(3,054 Views)

Hello,

Now, I am able to get the data format(which follows this format:0x01 0x02 <18 bytes of information data> 0x03 0x0D) from microntroller as shown in the attached image.

When first 2bytes are skipped and remaining 18 bytes are divided such that consecuitve 3 bytes are rearranged then it is considering 030D0102(which is rearranged as in spreadsheet2 of the attached image) which should not be.

But I want to 1)skip the first two bytes(0x01 0x02) and last two bytes(0x03 0x0D).

2)From the left 18bytes each consecutive set of 3 bytes should be reversed (because the transmitter sends the LSB first)

3) arranged 3bytes value should be converted into 2's complement and want to plot the data (2's complement of arranged 3bytes) continuously such that there will 6 continous plots.(each consisting 2's complement of the rearranged 3bytes)

 

Can someone help me out with the required processing of received data.

thanks.

0 Kudos
Message 4 of 15
(2,998 Views)

@PatanGova wrote:

When first 2bytes are skipped and remaining 18 bytes are divided such that consecuitve 3 bytes are rearranged then it is considering 030D0102(which is rearranged as in spreadsheet2 of the attached image) which should not be.


It is ignoring the first two bytes.  That's what the String Subset is doing.  You are taking starting on the thrid byte and up to 18 bytes.  If you put your Recieved Data on the output of the VISA Read, you would see that.

 

 


@PatanGova wrote:

But I want to 1)skip the first two bytes(0x01 0x02) and last two bytes(0x03 0x0D).

2)From the left 18bytes each consecutive set of 3 bytes should be reversed (because the transmitter sends the LSB first)


Your code is already doing that.

 

 


PatanGova wrote:

3) arranged 3bytes value should be converted into 2's complement and want to plot the data (2's complement of arranged 3bytes) continuously such that there will 6 continous plots.(each consisting 2's complement of the rearranged 3bytes)


Now that is a little more difficult.  A three byte Two's Compliment will take a little work.


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
0 Kudos
Message 5 of 15
(2,981 Views)

Hi crossrulz,

I dont understand how it will skip the last 2bytes as well from 22 bytes of Received Data.

why it is showing 030D0102(which is rearranged as in spreadsheet2) and also we are nt mentioning anthing to skip last 2 bytes

If possible can I get some clarification for these.

thnks.

0 Kudos
Message 6 of 15
(2,964 Views)

@PatanGova wrote:

Hi crossrulz,

I dont understand how it will skip the last 2bytes as well from 22 bytes of Received Data.

why it is showing 030D0102(which is rearranged as in spreadsheet2) and also we are nt mentioning anthing to skip last 2 bytes

If possible can I get some clarification for these.

thnks.


Read the help of the String Subset.

 

So we pass 22 bytes of data into the String Subset.  We give it an index of 2.  So the substring starts at the third element of the passed in string.  But we also pass in a length of 18.  The last 3 elements will be an index of 20, 21, and 22.  But we are only taking elements 2 through 19, inclusively.  So the last three elemetns are not included in the substring.


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
0 Kudos
Message 7 of 15
(2,951 Views)

Hi crossrulz,

The String indexing starts from 0.So, if the length of the bytes needed is 22bytes then will be having index from 0 to 21(for 22bytes).If it is correct then from 2 to 19 will be 18 bytes and the remaning be will elements in 20,21 indexes.How come you are saying the last 3 elements will be an index of 20, 21, and 22 are not included.

Also can I know why it is showing 030D0102(which is rearranged as in spreadsheet2).

Thanks.

0 Kudos
Message 8 of 15
(2,929 Views)

Hello,

I observed that the first 2 bytes and last 2 bytes are being skipped (not considered).

But the incoming data stream is following these two patterns continuously: Pattern1 as shown in Received_Data1 image which is being followed by pattern2 as shown in in Received_Data1 image.

This pattern seems to be a problem for extracting the correct information data.

Is there any other method to properly skip the first two bytes if the received are exactly 0x01 0x02 then taking the next 18 bytes which will be followed by  0x03 0x0D.

Also from 18bytes I only need to get 7, 8,9th bytes (3bytes data).

Can someone help me with these corrections.

 

Download All
0 Kudos
Message 9 of 15
(2,920 Views)
Solution
Accepted by topic author GoviRe

You should probably actually disable the termination character because you are recieving binary data.  So for the Configure Serial Port, you need to wire in a FALSE to the Termination Character Enable.  Then for your VISA Read, just try to read 22 bytes.  This should keep you in sync since it is a command-response setup.


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
0 Kudos
Message 10 of 15
(2,910 Views)