26.12.2012 Views

Serial Communications Protocol Specifications - Swissvacuum.com

Serial Communications Protocol Specifications - Swissvacuum.com

Serial Communications Protocol Specifications - Swissvacuum.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CODE EXAMPLES<br />

- 14 -<br />

In this section we show how to <strong>com</strong>pute the CRC according to the Modbus protocol requirements. Note that the CRC<br />

must be added to the packet to be sent to the controller and also must be <strong>com</strong>puted on the received packet to verify<br />

its integrity.<br />

Also some little programs are reported on how to prepare a query packet to talk to the controller using C language<br />

and Visual Basic.<br />

QUERY<br />

ANSWER<br />

Prepare data packet<br />

CRC calculation<br />

Add CRC at the end of<br />

data packet<br />

Get the answer from the<br />

serial port buffer<br />

CRC calculation on the<br />

received packet<br />

Compare the <strong>com</strong>puted<br />

CRC calcolato with the<br />

CRC in the data packet<br />

No match: data packet<br />

corrupted: do not use it!<br />

Fig. 6 – CRC calculation<br />

Send packet<br />

Receiving a data packet<br />

CRCs match: data packet<br />

correct: decode it!<br />

Warning! All examples are only suggestions and indications of a possible program organization.<br />

ANGELANTONI Industrie declaims all responsibility for the use (correct or not correct) of this<br />

code.<br />

It is up to the software engineer to modify, <strong>com</strong>plete and test the examples for his own purposes.<br />

<strong>Serial</strong> <strong>com</strong>munications protocol vers. 2.02 Angelantoni Industrie Spa Massa Martana (PG) Italy

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!