Guida Tecnica:
Protocollo di Comunicazione
Regolatori Digitali
Technical Guide:
Digital Regulators
Communication Protocol
E309573
INTRODUZIONE INTRODUCTION
Il sistema implementa un sottoinsieme del protocollo The system implements a subgroup of the Modbus
Modbus ed in particolare implementa due comandi: 3 protocol and in particular two commands: 3 (read hol-
(read holding register) e 6 (preset single register). A ding register) and 6 (preset single register). Another one
questi due ne è aggiunto uno (non standard, che impiega (32, not standard, but using a “free” code) which returns
un codice inutilizzato anche se non “libero”): 32, chia- N word (currently 4) has been added to these two, and
mato “get status”, che restituisce N word (attualmente 4) can be used for the machine state. This command gives
che possono essere utilizzate per lo stato della mac- greater flexibility in cyclic exchange data, and lets to be
china. Il motivo della presenza di questo comando è per not bound to specific addresses which may not be
avere maggiore flessibilità nei dati da scambiare ciclica- contiguous.
mente e per non essere legati ad indirizzi specifici che There is also another exception to the standard which
possono non essere contigui. is due to the limits set by the digital regulator hardware:
Esiste anche un’altra eccezione allo standard che è an EEPROM operation is necessary for reading the
dovuta ai limiti imposti dall’hardware dei regolatori digi- contents of the alarm area registers (because these
tali: per leggere il contenuto dei registri della zona allarmi registers are not copied in RAM), therefore the read
è necessaria un’operazione in EEPROM (non essendo command should be limited to one single word at a
questi registri ricopiati in RAM), quindi il comando di time.
lettura deve essere limitato ad una sola word per volta.
Fig. 1 - Struttura del protocollo MODBUS / Structure of the MODBUS protocol
Il protocollo Modbus prevede due possibili modalità per The Modbus protocol uses two possible modes for
ricavare il sincronismo (e quindi riconoscere l’inizio e la finding the synchronism (therefore recognising the be-
fine dei pacchetti): ginning and end of the packets):
- Modalità ASCII e utilizzo di caratteri di controllo - ASCII mode and use of control characters
(modo ASCII) (ASCII mode)
- Modalità binaria e utilizzo di pause, in cui la linea - binary mode and use of pauses, in which the line
rimane inutilizzata per almeno il tempo di 3,5 remains unused for at least 3.5 characters (RTU
caratteri (modo RTU) mode)
Il protocollo utilizzato nei regolatori digitali Mecc Alte è The Mecc Alte digital regulator uses RTU protocol.
uno “pseudo” RTU.
The regulators have an internal table of registers, which
I regolatori implementano al loro interno una tabella di can be used to access all the board control, drive or
registri, tramite i quali è possibile accedere alle funzioni measure functions. The registers are all 16 bit and take
di controllo, comando o misura della scheda. I registri on different functions and meanings only when interpre-
sono tutti a 16bit e assumono funzioni e significati diversi ted by the digital regulator program. This means they do
solo quando sono interpretati dal programma del regola not have particular meanings at a communication
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
2
tore digitale, non hanno cioè significati particolari a livello protocol level, which is only used for transporting words
di protocollo di comunicazione, il quale è utilizzato solo at 16 bits.
per il trasporto di word a 16 bit.
Il protocollo è di tipo master/slave e prevede un master The protocol is of the master/slave type, made up of one
ed un certo numero di slave. Anche se il campo indirizzo master and a certain number of slaves. Even if the
è un byte, è opportuno limitare comunque il numero di address field is one byte, it is a good idea to limit the
slave ad un numero massimo di 32, o anche minore. Il number of slaves to 32 or less. The maximum number
numero massimo può dipendere da molti fattori: tipo di can depend on many factors: the type of line driver, the
driver di linea, baudrate, lunghezza dei collegamenti. baud rate, the length of the connections.
Il regolatore implementa uno slave il cui indirizzo è The regulator implements a slave with programmable
programmabile. Per realizzare una rete, e quindi neces- address. To create a network, each slave should be
sario programmare ogni slave con un indirizzo diverso. programmed with a different address.
Le impostazioni della linea seriale sono fisse (non sono The serial line settings are fixed (they can therefore not
cioè programmabili) i valori sono 9600baud, 8bit, parità be programmed) – the values are 9600baud, 8bit, parity
esclusa, 1 stop bit. excluded, 1 stop bit.
Errori Errors
Vi sono varie cause di errore, o più in generale, di There are various causes of error or, more in general, of
condizione di non perfetta comunicazione. imperfect communication conditions.
− La prima possibilità è che lo slave non sia connesso o - The first possibility is that the slave is not connected or
sia guasto; in questo caso il master ritrasmette la is faulty. In this case the master retransmits the
richiesta dopo un timeout che normalmente è dell’or- request after a timeout, which is normally set in hun-
dine delle centinaia di millisecondi. Se gli slave hanno dredths of a millisecond. If the slaves have a low
un tempo di latenza basso, il timeout può essere latency time, the timeout can be reduced as a result.
ridotto di conseguenza.
- The slave receives a message with errors. In this case
− Lo slave riceve un messaggio con errori; in questo the CRC fails and the slave does not respond. The
caso il CRC fallisce e lo slave non risponde. Il master master behaves as described above.
si comporta come nel caso precedente.
- The slave receives the message correctly, but the
− Lo slave riceve il messaggio correttamente, ma la request from the master cannot be served. In this case
richiesta del master non può essere servita. In questo the slave returns a reply in which 128 (practically the
caso lo slave restituisce una risposta in cui al campo most important bit of the byte is set) and the data field
funzione viene sommato 128 (praticamente si imposta which does not hold data but a byte that specifies the
il bit più significativo del byte) ed il campo dati non type of error are summed at the function field.
contiene dati ma un byte che specifica il tipo di errore.
I codici di errore sono i seguenti: The error codes are as follows:
1 Illegal FUNCTION 1 Illegal FUNCTION
2 Illegal data address 2 Illegal data address
3 Illegal data value 3 Illegal data value
4 Slave device failure 4 Slave device failure
5 Acknowledge 5 Acknowledge
6 Slave busy 6 Slave busy
7 Negative Acknowledge 7 Negative Acknowledge
8 Memory parity error 8 Memory parity error
Nei regolatori digitali Mecc Alte, al momento sono utiliz- Only codes 2, 3 and 6 are used in the Mecc Alte digital
zati solo i codici ModBus 2, 3 e 6 regulators.
NOTA IMPORTANTE IMPORTANT NOTE
Allo scopo di ridurre il carico computazio- In order to reduce the computational load,
nale al regolatore, dovuto alla comunica- caused by to communication, to the regula-
zione, il CSUM dei parametri calcolati in tor, the CSUM of the parameters calculated
EEPROM è calcolato dal master. in EEPROM is calculated by the master.
Più in particolare, quando il master deve effettuare una More in detail, when the master carries out a writing in
scrittura nella zona parametri conservata in EEPROM, the parameter area saved in EEPROM, it immediately
subito dopo, deve ricalcolare il CSUM e scriverlo nell’ap- recalculates the CSUM and writes it in the correct posi-
posita locazione. Similmente, quando si fa l’upload del- tion. Similarly, when the whole parameter list is uploa-
l’intera lista di parametri, il CSUM deve essere calcolato ded, the CSUM is written only once.
e scritto alla fine (una sola volta). Il regolatore stesso The regulator recalculates and saves the CSUM only if it
ricalcola e salva il CSUM solo nel caso, dopo il RESET, does not correspond after resetting;in this case the
questo non corrisponda; in tal caso viene generato l’al- alarm “CheckSum Error” is generated.
larme “CheckSum Error”.
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
3
CONTENUTO DEI PACCHETTI MASTER/SLAVE CONTENTS OF THE MASTER/SLAVE PACKETS
Comando 03: lettura di N words Command 03: the reading of N words
MASTER
Field Name (Hex) Note
Slave Address 11 Indirizzo del destinatario del comando / Address of the command receiver
Function 03 Codice del comando: 03 = lettura / Command code: 03 = reading
Starting Address Hi 00 Indirizzo di partenza delle word da leggere: h006B = d107
Starting Address Lo 6B Starting address of the word to be read: h006B = d107
No. of words 00 Numero di word da leggere: h0003 = d3
No. of words 03 Number of word to be read: h0003 = d3
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità master trasmette quindi il pacchetto: 11 03 00 6B 00 The master unit therefore transmits the packet: 11 03 00 6B
03 xx xx 00 03 xx xx
Se ha correttamente ricevuto il comando, l’unità slave ri- If it has correctly received the command, the slave unit
sponde ritrasmettendo “Slave Address” e “Function” come replies by retransmitting “Slave Address” and “Function”
conferma del comando ricevuto, di seguito il numero di bytes to confirm the received command. The number of bytes
e i dati richiesti.
and the requested data is given below.
SLAVE
Field Name (Hex) Note
Slave Address 11 Ritrasmette “Slave Address” e “Function” = risposta corretta al comando
Function 03 Retransmits “Slave Address” and “Function” = correct reply to command
Byte Count 06 Numero di bytes che verranno trasmessi: h06 = d6
Number of bytes that will be transmitted: h06 = d6
Data Hi (Register 107) 02 1a word all’indirizzo h006B (d107): h020B
Data Lo (Register 107) 2B 1st word at the h006B (d107) address: h020B
Data Hi (Register 108) 00 2a word all’indirizzo h006C (d108): h0000
Data Lo (Register 108) 00 2nd word at the h006C (d108) address: h0000
Data Hi (Register 109) 00 3a word all’indirizzo h006D (d109): h00064
Data Lo (Register 109) 64 3rd word at the h006D (d109) address: h00064
CRC H xx 3a word all’indirizzo h006D (d109): h00064
CRC L xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
Control code for data correctness, refer to “Calculating the CRC”
L’unità slave trasmette quindi il pacchetto: 11 03 06 02 The slave unit therefore transmits the following packet:
2B 00 00 00 64 xx xx 11 03 06 02 2B 00 00 00 64 xx xx
Se il comando non è stato correttamente ricevuto, l’unità If the command is not received correctly, the slave
slave risponde replies
SLAVE
Field Name (Hex) Note
Slave Address 11 Ritrasmette “Slave Address” come risposta al comando
Retransmits “Slave Address” in reply to the command
Function with error 83 Viene sommato h80 = d128 al comando ricevuto (h03 + h80 = h83)
h80 = d128 is summed to the received command (h03 + h80 = h83)
Error code nn Codice errore (v. pag. 3) / Error code (see page 3)
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità slave trasmette quindi il pacchetto: 11 83 nn xx The slave unit therefore transmits the following packet: 11 83
xx nn xx xx
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
4
Comando 06: Scrittura di una word Command 06: Writing a word
MASTER
Field Name (Hex) Note
Slave Address 11 Indirizzo del destinatario del comando / Address of the command receiver
Function 06 Codice del comando: 06 = scrittura / Command code: 06 = writing
Register Address Hi 00 Indirizzo della word da scrivere: h0001 = d1
Register Address Lo 01 Address of the word to be written: h0001 = d1
Preset Data Hi 00 Dato da scrivere: h0003 = d3
Preset Data Lo 03 Datum to be written: h0003 = d3
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità master trasmette quindi il pacchetto: 11 06 00 01 00 The master unit therefore transmits the following packet: 11
03 xx xx 06 00 01 00 03 xx xx
Se ha correttamente ricevuto il comando, l’unità slave If it receives the command correctly, the slave unit
risponde ritrasmettendo l’intero pacchetto replies by retransmitting the whole packet
SLAVE
Field Name (Hex) Note
Slave Address 11 Indirizzo del destinatario del comando / Address of the command receiver
Function 06 Codice del comando: 06 = scrittura / Command code: 06 = writing
Register Address Hi 00 Indirizzo della word da scrivere: h0001 = d1
Register Address Lo 01 Address of the word to be written: h0001 = d1
Preset Data Hi 00 Dato da scrivere: h0003 = d3
Preset Data Lo 03 Datum to be written: h0003 = d3
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità slave trasmette quindi il pacchetto: 11 06 00 01 00 03 The slave unit therefore transmits the following packet: 11 06
xx xx 00 01 00 03 xx xx
Comando 32: get status Command 32: get status
MASTER
Field Name (Hex) Note
Slave Address 11 Indirizzo del destinatario del comando / Address of the command receiver
Function 20 Codice del comando: 20 = scrittura (h20 = d32)
Command code: 20 = writing (h20 = d32)
Starting Address Hi 00 Senza significato
Starting Address Lo 00 Without meaning
No. of words 00 Numero fisso (4) di word di stato da leggere: h0004 = d4
No. of words 04 Fixed number (4) of state words to be read: h0004 = d4
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità master trasmette quindi il pacchetto: 11 20 00 00 00 The master unit therefore transmits the following packet: 11
04 xx xx 20 00 00 00 04 xx xx
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
5
Se ha correttamente ricevuto il comando, l’unità slave If it receives the command correctly, the slave unit re-
risponde ritrasmettendo “Slave Address” e “Function” plies by transmitting “Slave Address” and “Function” to
come conferma del comando ricevuto, di seguito il nu- confirm command reception, followed by the number of
mero di bytes e le 4 word di stato bytes and the 4 state words.
SLAVE
Field Name (Hex) Note
Slave Address 11 Ritrasmette “Slave Address” e “Function” = risposta corretta al comando
Function 20 Restransmits “Slave Address” and “Function” = correct reply to command
Byte Count 08 Numero di bytes che verranno trasmessi: h08 = d8, 8 bytes = 4 words
Number of bytes that will be transmitted: h08 = d8, 8 bytes = 4 words
Data Hi (W0) 02 1a word: h020B
Data Lo (W0) 2B
Data Hi (W1) 00 2a word: h0000
Data Lo (W1) 00
Data Hi (W2) 00 3a word: h00064
Data Lo (W2) 64
Data Hi (W3) 00 3a word: h00064
Data Lo (W3) 64
CRC H xx Codice di controllo per la correttezza dei dati, v. “Calcolo del CRC”
CRC L xx Control code for data correctness, refer to “Calculating the CRC”
L’unità slave trasmette quindi il pacchetto: 11 20 08 02 2B 00 The slave unit therefore transmits the following packet: 11 20
00 00 64 00 64 xx xx 08 02 2B 00 00 00 64 00 64 xx xx
Calcolo del CRC Calculating the CRC
Dettagli relativi al tipo di CRC utilizzato possono essere Details regarding the type of CRC used can be found in
reperiti nel documento che descrive lo standard Modbus the document that describes the standard Modbus (this
(scaricabile dal sito). Di seguito è riportato il codice C del document can be downloaded from the site). The calcu-
calcolo. lation C code is given below.
/* ----------------------------- */ /* ----------------------------- */
#define GENERATORE (0xA001) #define GENERATORE (0xA001)
/* Il crc ha i byte invertiti; dovrebbe essere /* The crc has swapped bytes; this should be correct
giusto così */ */
WORD get_crc16 (unsigned int * msg, WORD size ) WORD get_crc16 (unsigned int * msg, WORD size )
{ WORD crc = 0xFFFF, nshift, fai; { WORD crc = 0xFFFF, nshift, fai;
for ( ; size--; ) for ( ; size--; )
{ crc ^= (WORD) *msg++; { crc ^= (WORD) *msg++;
for (nshift = 8; nshift--;) for (nshift = 8; nshift--;)
{ fai = crc & 0x0001; { fai = crc & 0x0001;
crc >>= 1; crc >>= 1;
if (fai) if (fai)
crc ^= GENERATORE; crc ^= GENERATORE;
} }
} }
fai = ( crc << 8) & 0xFF00; fai = ( crc << 8) & 0xFF00;
fai = fai + (( crc >> 8) & 0x00FF) ; fai = fai + (( crc >> 8) & 0x00FF) ;
return (fai); return (fai);
} }
/* ----------------------------- */ /* ----------------------------- */
La routine è utilizzata sia dal master sia dallo slave.
The routine is used by both the master and the slave.
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
6
RIFERIMENTI / REFERENCES
Internet address Description
[Link] Modbus-IDA is a group of independent users and suppliers of auto-
mation devices that seeks to drive the adoption of the Modbus
communication protocol suite and the evolution to address architec-
tures for distributed automation systems across multiple market
segments. Modbus-IDA will also provide the infrastructure to obtain
and share information about the protocols, their application and
certification to simplify implementation by users resulting in reduced
costs.
[Link] This is the site of the original inventors of the MODBUS protocol,
Modicon, now known as Schneider Automation. You' ll find useful
MODBUS product-related information.
[Link] This site contains software solutions industry links, and a library of
industrial information.
[Link] Very useful site - a mine of information on using Ethernet in industrial
[Link] applications.
[Link] Modbus serial RTU simulator. Compiles with Visual C++ 6.0, and
mod_rssim.html runs on Windows 2000 and probably 95/98.
[Link] The web-site of the newly formed Association of Industrial Vendors
and Users that use Ethernet in an industrial environment. The site is
still under development, but is worth keeping an eye on.
[Link] Example C code for linux modbus rtu comms
[Link] LibModbus is a simple modbus toolbox for Linux. This library con-
tents master, slave and serial port configuration routines.
[Link] Java Modbus Library. This library was implemented by Dieter Wim-
berger
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
7
INDICE DELLA REVISIONE / REVISION HISTORY
Rev. Data / Date Descrizione / Description
rev.00 07/11 Initial release
DIGITAL REGULATOR COMMUNICATION PROTOCOL - rev. 00
8
Mecc Alte SpA Spain India China
Via Roma Mecc Alte España S.A. Mecc Alte India PVT LT D Mecc Alte Alternator Haimen LTD
20 – 36051 Creazzo C/ Rio Taibilla, 2 Plot NO: 1, Sanaswadi 755 Nanhai East Rd
Vicenza – ITALY Polig. Ind. Los Valeros Talegaon Jiangsu HEDZ 226100 PRC
T: +39 0444 396111 03178 Benijofar (Alicante) Dhamdhere Roa d T: +86 (0) 513 82325758
F: +39 0444 396166 T: +34 (0) 96 6702152 Taluka: Shirur, District: F: +86 (0)513 82325768
F: +34 (0) 96 6700103 Pune - 41220 8
E: info@[Link] E: info@[Link]
Maharashtra, India
aftersales@[Link] E: info@[Link] aftersales@[Link]
T: +91 2137 619600
aftersales@[Link]
F: +91 2137 619699
United Kingdom Australia
E: info@[Link]
Mecc Alte U.K. LTD Germany Mecc Alte Alternators PTY LTD
6 Lands’ End Way Mecc Alte Generatoren GmbH aftersales@[Link] 10 Duncan Road, PO Box
Oakham Ensener Weg 21 1046
Rutland D-51149 Köln U.S.A. and Canada Dry Creek, 5094, South
T: +44 (0) 1572 771160 T: +49 (0) 2203 503810 Mecc Alte Inc. Australia
F: +44 (0) 1572 771161 F: +49 (0) 2203 503796 1229 Adam Drive T: +61 (0)8 8349 8422
McHenry, IL, 60051 F: +61 (0)8 8349 8455
E: info@[Link] E: info@[Link]
T: +1 815 344 0530 E: info@[Link]
aftersales@[Link] aftersales@[Link]
F: +1 815 344 0535 aftersales@[Link]
E: info@[Link]
France Far East
Mecc Alte International S.A. Mecc Alte (F.E.) PTE LTD aftersales@[Link]
[Link] Gagnerie 19 Kian Teck Drive
16330 [Link] De Boixe Singapore 628836
T: +33 (0) 545 397562 T: +65 62 657122
F: +33 (0) 545 398820 F: +65 62 653991
E: info@[Link]
E: info@[Link]
aftersales@[Link]
aftersales@[Link] [Link]