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: 

CRC16 error with several entries

Solved!
Go to solution

Hello,

I was trying to create a VI that:

1-Reads data from Serial Port. This data are strings containing several information and arrives each 500ms. On the end of each string, CRC is appended. I use % to separate CRC from other data.

2- For each string, my VI must, first, find % and remove the incoming CRC.

3- Then I have to check if the CRC of the string received is equal to CRC appended.

Please see this example:

CRC_fpanel.png

In this example, the incoming string is:

ETS3#1984;18,93;1030,36;44,85;57,87;0;ON;5,00;USB;0,69;3,20;16,62;-0,51;0,16;9,89;ON;0.000000;0.000000%4785

The CRC is 4785(hex) and was appended at the origin of the communication link.

Then, if I compute the CRC of the data (incoming string without the CRC) I should get the same value. But I get a wrong value (DBDB).

The interesting is that if I use this VI found here:

http://forums.ni.com/t5/Example-Program-Drafts/Inline-CRC-Reference-Library-CRC-32-CRC-16-and-CRC-8/...

the value of the CRC is correct (option CRC-16-CCITT-xMODEM).

So if I am not wrong, the problem can be the fact that I am using the subVI in a loop since there is a First Call function included.

Can anyone help me with this?

Bellow there is a snippet of my VI

crc_check.png

 

Thanks a lot in advance.

 

Duarte

 

0 Kudos
Message 1 of 7
(3,724 Views)
Solution
Accepted by topic author DuarteCota

Digging into that library, you should not be using the First Call.  Instead, use the i terminal and Equal To Zero function.  This way you reset the calculation with each message instead of each time you start the program.

 

Another issue I am seeing with your code is the possibility of getting a partial message.  Does the message end with a termination character, such as a Line Feed or a Carriage Return?  If not, is the message length always the same?  What I am getting at is the Bytes At Port is rarely the way to tell VISA Read how many bytes to read.  If the termination character is used, tell the VISA Read to read more bytes than you ever expect in a message.  If no termination character but message is the same length, just tell the VISA Read to read the message length of bytes.


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 7
(3,705 Views)

Hello,

I did what you suggested and it’s working fine now. Thank you!

 About the question, my message comes with a line feed at the end. Yes, it’s a good idea to use byte count to make sure that incomplete messages are not processed. In my case I expect > 100 byte messages.

Now I was wondering if you or anyone else can help me implementing a counter to be incremented each time I get different CRC. I think I must implement shift register.

Can you help me?

 Thank you again for previous solution.

Best.

0 Kudos
Message 3 of 7
(3,668 Views)
Solution
Accepted by topic author DuarteCota

@DuarteCota wrote:

 About the question, my message comes with a line feed at the end. Yes, it’s a good idea to NOT use byte count to make sure that incomplete messages are not processed. In my case I expect > 100 byte messages.


I added an important missing word.  Just tell the VISA Read to read 1000 bytes and you should be fine.

 


@DuarteCota wrote:

Now I was wondering if you or anyone else can help me implementing a counter to be incremented each time I get different CRC. I think I must implement shift register.


As you said, store it in a shift register.  In the case where no data comes in, make sure you wire the count straight through.  In the case where you read a message, use the Increment function when you have a new message.


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

Thank you.

I was trying to test this solution but when I press the button to increment the value goes up to a few thousands...

Any help?

incr.png

0 Kudos
Message 5 of 7
(3,645 Views)
Solution
Accepted by topic author DuarteCota

This seems like a new question completely unrelated to the original thread.

 

But to answer it, you have a button that is set to Switch Until Released which means is is True for as long as you hold it down.

 

Your loop runs infinitely fast, and certainly much fast than how quick you can let go of that button.

 

Your button should be Latch When Released.  (lower middle option on the mechanical action.)  And if you do that, you really should just delete that button to put in an OK button instead.

0 Kudos
Message 6 of 7
(3,638 Views)

Done!

I am sorry for the confusion on the questions.

Thank you.

Duarte

0 Kudos
Message 7 of 7
(3,632 Views)