LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring LabVIEW loops to return to beginning conditionally from CRC calculation

Solved!
Go to solution

Hey LabVIEW gurus,

 
In the attached .vi, I am trying to read 30 byte packets from a board that is spitting out data. Each 30 byte packet follows the format: (26 bytes of data) (2 bytes for a 16-bit CRC) (1-byte carriage return) (1-byte line feed). I have only been using LabVIEW for a few weeks so the code isn't pretty, but with lots of help from this forum I have successfully read in 28-byte packets without the CRC - everything fuctions as I expect. Adding the CRC calculation has been pretty easy (thanks to some very helpful code from crossrulz), but I am missing one major part... If the CRC calculation returns "0" then the data should be analyzed, graphed, and saved in a spreadsheet. But if the CRC does not return "0" then a transmission error has occured and I want to throw away that data packet without writing anything to the graphs or the spreadsheet (not even straight zeros). I just want the next packet of data to take the error's place. Due to my lacking programming vocabulary and skill, it seems like I want to return to the beginning of the while loop conditionally after a non-zero CRC calculation to grab the next 30-byte packet of data. I also need to figure out how to get rid of the carriage return and line feed, which doesn't seem to work the way I currently have my .vi wired.
 
Thank you for taking the time to read this. Any direction would be greatly appreciated!
 
I am working in LabVIEW 12. I am also using a x^16+x^15+x^2+1 polynomial for the CRC.
 
Many thanks,
Leif
0 Kudos
Message 1 of 5
(3,439 Views)

First of all, you reallly should learn to make some subVIs.  They will clean up your diagram a lot.

 

Secondly, your CRC calculation is incorrect.  The inner loop should only iterate 8 times (once per bit in the array element, which is a U8).  And you should use Array Subset to reduce the elements you are performing the calculation over.

 

Thirdly, whatever you do not want to be performed with an invalid CRC should be inside of the FALSE case of your case structure.


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 2 of 5
(3,425 Views)

Thank you crossrulz. I understand my loop error, and used Delete From Array to get rid of the 2 unwanted bytes. I left the FALSE case intentionally blank because I do not know how to tell LabVIEW to throw away data containing a transmission error and retrieve the next packet. I cannot read zeros in place of bad data. I'm sure there is a simple way to do this in LabVIEW - any ideas?

0 Kudos
Message 3 of 5
(3,416 Views)
Solution
Accepted by topic author Leif_A

Well, I would also recommend moving your file writing to be inside of the loop, specifically inside of the TRUE case (I might have told you wrong before).  If the CRC comes out to 0, you do all of the processing, else do nothing.  Then next iteration.  By moving the File IO to inside of the loop, you are avoiding building up huge arrays (ie lots of memory).


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 4 of 5
(3,401 Views)

Understood. I was trying to think of ways to do all the processing within the TRUE case structure, but couldn't figure it out because I put the file IO outside the loop. Should have reconsidered that decision. Thanks!

0 Kudos
Message 5 of 5
(3,396 Views)