Professional Documents
Culture Documents
ModbusMemoryMap Inglês
ModbusMemoryMap Inglês
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
PROGRAMVARA-TRL/2-SPEC
+ GKT, GRT, GLM, GLM-TO, GLM-AA, GLM-
EW
GLM-HCM, GLP, GLP-AC, GLP-MR, GLP-JA
GLP-AW, GLP-PE, GLP-RM,
GPP, GPB, GPR, GPS, GKP-EE, GKP-VK
Document reviewed 1992-02-20
Review group members:
GD, GLS-RH, GKS-SJ, GRE-LL
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
1 GENERAL
1.1 Identification
This document specifies the protocol for communication between a HOST computer and Saab
TankRadar L/2 units, except OPI, using the MODBUS standard protocol defined in document
GOULD MODICON MODBUS PROTOCOL Reference Guide.
Issue 1
Issue 2 92/05/05
Added RTG analog inputs to FCU/OPI database.
Added more explanations to value order.
Changed "level status" to "RTG status".
Added CRC-16 code.
Issue 3 92/09/10
RTG status changed.
Issue 4 92/10/27
Added additional registernumbers for FC02,
FC03 and FC04.
Modified chapter addresses and examples.
DAU NMI approval.
Issue 5 94/07/04
OPI interface moved to TRL/2-93.156
Calibration error and system error bits in DAU
status added.
Added general description of values in protocol.
Issue 6 96/05/20
Corrected CRC in examples.
RTG status changed.
Issue 7 98/02/06
FCU diagnostic register is available to host
computers. See chapter 5.2.1 FCU Diagnostic
register.(FCU program version 3.B0 or later is
required for this functionality.)
Added the other applicable devices.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
1.3 Definitions
AI Analog inputs
COS Configuration Software , DOS based program (Saab Tank Control)
DAU Data Acquisition Unit
DC Diagnostic
FB FCU Fieldbus
FBM Field Bus Modem
FCU Field Connection Unit
GB FCU Groupbus
HOST Host Computer
NMI Nederlands MeetInstituut.
OPI Operators Interface program, used in TRL2 on a PC (Saab Tank Control)
RTG Radar Tank Gauge
TBD To Be Defined
TRL2 SAAB TankRadar L/2
TRL2 Units DAU, FCU, OPI, RTG
1.4 Reference
1. Modicon Modbus Protocol Reference Guide PI-MBUS-300 Rev G.
Nov 1994 MODICON, Inc.
2. The Modbus Protocol applied to the TRL2 Communication TRL2-89.28 Issue 2
System
3. Protocol specification-TRL/2 OPI Modbus host protocol TRL/2-93.156
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
2 MODBUS PROTOCOL
2.1 Introduction
The communication between the HOST and the OPI or FCU is done on a standard RS-232C serial
link. Connecting the Host’s serial link to the FBM and the TRL2 bus makes connection to RTG and
DAU.
The Modbus protocol transmission mode is RTU (Remote Terminal Unit) which means that all
transferred data will be in binary.
The HOST computer will be the MASTER in the communication, which requests data from the
SLAVE (the TRL2 units).
Error checking is done by adding a CRC (Cyclic Redundancy Check) word at the end of each
message.
The FCU supports different devices connected as slaves to the Field busses:
RTG, DAU, LABKO2000 and Echowave.
When a sensor failure or communication failure has occurred, then the value is unchanged. The
HOST MUST ask for sensor status. This means that if the status of the level is set to error or to
communication failure the value will not be changed to 0 or 0FFFFH or similar.
2.2 Framing
The general format of one message is:
FUNCTION code:
The function code in the message defines what actions are to be performed or what data is to be
transmitted.
There are a number of different Modbus function codes, each one assigned to a specific function.
In the HOST - FCU communication function codes: 02, 03, 04 and 08 are used.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
In the HOST - DAU and RTG communication function codes: 04 and 08 are used.
The RTG, DAU and FCU may answer on other function code, but the HOST should not use them.
The rest of the functions will be answered by exception code 1 (see chapter 7).
DATA field:
Contains query information from HOST to TRL2 units or response data from TRL2 units in
response to the query from HOST.
CRC-16:
Contains the CRC-16 word, the high order byte is sent first. The high order byte is defined as the
MSB of the CRC calculation but is the lower part of the CRC-16 word. See also chapter 2.7.
2.3 Unit
The units of the parameters are the same as defined in the system.
Level device position Modbus FC03 register for Tank level (HEX)
1 680
2 681
5 684
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Temperature transmitter position Modbus FC03 register for Average temperature (HEX)
1 680
3 682
2.5 Addresses
Every TRL/2 unit in a system has a unique address. This address could range from 1 to 247.
2.6 Values
The format of the values is always in 2-complement except for registers mentioned as bit-register or
status where each bit must be decoded.
2 complement:
Explanation 1: Means that the value can be negative and is defined as a 2-complemet value.
Explanation 2: 2-complement means that the most significant digit is decoded as the sign (+/-) on
the value, i.e. if the value >= 8000H it is negative. To extract the sign from the value apply the
following formula (but don't forget the "-" character):
value EXOR FFFFH + 1 .
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
3 DATA FUNCTIONS
3.2.1 Description
Reads the alarm status (ON/OFF) of discrete inputs (1XXXX references) in the slave.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
n: last data
n+1: High order CRC-16
n+2: Low order CRC-16
Data will be packed with one bit for each sensor input. The lower order bit of the first character
contains the addressed input, and the remainder follows. For input quantities that are not even
multiples of eight, the last character will be filled in with zeros at high order end.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
The FCU will set all corresponding bits to 1 in case of subsystem communication failure.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Compare with chapter 3.2.3. It’s the same values but different data addresses.
The FCU will set all corresponding bits to 1 in case of subsystem communication failure.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
3.3.1 Description
Reads the binary contents of holding registers (4XXXX references) in the slave.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Compare with chapter 3.3.3. It’s the same values but different data addresses.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
3.4.1 Description
Reads the binary contents of input registers (3XXXX references) in the slave.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Compare with chapter 3.4.5. It’s the same values but different data addresses.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
4 DIAGNOSTIC FUNCTIONS
4.1 Function 08
Query message is returned unchanged. The query data field may contain any data.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
The RTG, DAU and FCU may answer on other diagnostic functions than DC1, DC2 and DC4, but
the HOST should not use them. The other diagnostic functions will be answered by exception code
7 (see chapter 7).
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
5 DEVICE DESCRIPTONS
This chapter describes the devices, which can be connected to the host via Modbus protocol directly
or indirect via connection to the FCU device.
Note: FCU program version 3.B0 or later is required for this functionality.
The FCU diagnostic register is available in FC03 and FC04 in data address 85FF (hex) or 5FF (hex)
in mirror data addresses.
If any of the bits 0-2 are set, all devices connected to the FCU will be flagged as communication
failure.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
RTG status: (NOTE ! When using later flash software than 4.A1 check with SAAB Tank Control
for current layout or consult the input specification for that RTG version)
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Temperature in liquid:
Bit 0 = 1 Temp 1 in liquid
Bit 1 = 1 Temp 2 in liquid
Bit 2 = 1 Temp 3 in liquid
Bit 3 = 1 Temp 4 in liquid
Bit 4 = 1 Temp 5 in liquid
Bit 5 = 1 Temp 6 in liquid
Bit 6 = 1 Temp 7 in liquid
Bit 7 = 1 Temp 8 in liquid
Bit 8 = 1 Temp 9 in liquid
Bit 9 = 1 Temp 10 in liquid
Bit 10= 1 Temp 11 in liquid
Bit 11= 1 Temp 12 in liquid
Bit 12= 1 Temp 13 in liquid
Bit 13= 1 Temp 14 in liquid
Bit 14= 1 System error
Bit 15= 1 Temp calibration error. (PTB)
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
If DAU does not answer then FCU, will set the status =FFFFH.
Current Status:
Bit 0 = 1 Sensor 1 error
Bit 1 = 1 Spare
Bit 2 = 1 Sensor 2 error
Bit 3 = 1 Spare
Bit 4 = 1 Sensor 3 error
Bit 5 = 1 Spare
Bit 6 = 1 Sensor 4 error
Bit 7-13 Spare
Bit 14= 1 Master, FCU set to 1 if DAU does not answer
Bit 15= 1 Calibration error
If DAU does not answer then FCU, OPI will set the status =4055H.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Frequency status:
Bit 0 = 1 Sensor 1 error
Bit 1 = 1 Sensor 2 error
Bit 2 = 1 Sensor 3 error
Bit 3 = 1 Sensor 4 error
Bit 4 = 1 Sensor 5 error
Bit 5 = 1 Sensor 6 error
Bit 6 = 1 Sensor 7 error
Bit 7 = 1 Sensor 8 error
Bit 8-13 Spare
Bit 14= 1 Master, FCU, set to 1 if DAU does not answer
Bit 15 System error
If DAU does not answer then FCU will set the status =40FFH.
Relay status:
Bit 0 = 1 Relay 1 on
Bit 1 = 1 Relay 1 off
Bit 2 = 1 Relay 2 on
Bit 3 = 1 Relay 2 off
Bit 4 = 1 Relay 3 on
Bit 5 = 1 Relay 3 off
Bit 6 = 1 Relay 4 on
Bit 7 = 1 Relay 4 off
Bit 8 = 1 Relay 1 failure
Bit 9 = 1 Relay 2 failure
Bit 10= 1 Relay 3 failure
Bit 11= 1 Relay 4 failure
Bit 12,13 Spare
Bit 14= 1 Master, FCU set to 1 if DAU does not answer
Bit 15 Spare
If DAU does not answer then FCU will set the status =4FxxH.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
If DAU does not answer then FCU will set the status =40xxH.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
Below you will find different examples of how requests to FCU and responses from the FCU will
look like.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
7 EXCEPTION RESPONSES
If TRL2 units detect an operation error the response will be an exception code.
The Exception response from TRL2 to HOST has the following format:
If not all of the requested memory addresses are valid, only the valid words are returned. If no
address is valid, exception code 2 is returned.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998
Dokumenttyp/Document type Infoklass/Info class
Specification P
Reg, nr/Reg. No.
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
8 CRC GENERATION
The CRC-16 error check sequence is implemented as follows:
The message (data bits only, disregarding start/stop and parity bits) is considered as one continuous
binary number, which most significant bit (MSB) is transmitted first. The message is pre-multiplied
by x**16 (shifted left 16 steps), then divided by x**16 + x**15 + x**2 + 1 expressed as a binary
number (11000000000000101). The integer quotient digits are ignored and the 16-bit remainder
(initialized to all ones at the start to avoid the case of all zeroes being an accepted message) is
appended to the message (MSB first) as the two CRC check bytes. The resulting message including
CRC, when divided by the same polynomial at the receiver will give a zero remainder if no errors
have occurred. The receiving unit recalculates the CRC and compares it to the transmitted CRC. All
arithmetic is performed modulo two (no carry). An example of the CRC-16 error check is found in
the Modicon Modbus Protocol reference guide on pages 1-4 to 1-6.
Input
BUF - Pointer to message buffer.
BYTE_NUM - Number of bytes in message (exclusive CRC bytes)
/* declarations */
BUF_IDX word,
IDX byte,
FLAG byte,
CRC word;
/* code: */
GKS-91.06
Godkänd/Approved by Lagringsdata/Stored at
GKT c:\meus documentos\andré\saab\modbus std question.doc
Utfärdare/Issued by Datum/Date Utgåva/Issue Sida/Page
end;
BYTE_NUM = BYTE_NUM - 1;
BUF_IDX = BUF_IDX + 1;
end;
return CRC;
/* declarations: */
LENGTH BYTE; /* Length of message , inclusive CRC bytes
*/
MESSAGE (LENGHT) BYTE; /* message buffer */
CRC word;
/* code: */
CRC = CRC_CALC (MESSAGE, LENGHT - 2);
Note: The CRC_CALC function can also swap l.o. and h.o. of CRC word before returning but such
code will be less sufficient than the above example.
COYRIGHT S SAAB Marine Electronics AB, Sweden, 1991, 1992, 1994, 1996 and 1998