Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:software:devices:modbus [2016/12/23 16:06] – [5.10.2. Parameters] qem103 | en:software:devices:modbus [2020/07/13 14:58] (current) – qem103 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== DEVICE MODBUS ====== | ====== DEVICE MODBUS ====== | ||
- | ===== - Introduction ===== | + | ====== - Introduction |
The MODBUS< | The MODBUS< | ||
Line 387: | Line 387: | ||
- | === - Variabili | + | === - Variables |
- | ^ Nome ^ D ^ R ^ A ^ Condizioni | + | |
- | | err | B | 0 | R | - | **Errors**\\ Indica se sono stati riscontrati errori nel protocollo.\\ In modalità master il parametro viene aggiornato in coincidenza dell’attivazione dello stato // | + | |
- | | serr | B | 0 | R/W | - | **Serial Errors**\\ Indica se sono stati riscontrati errori nella comunicazione seriale. Il parametro viene aggiornato ad ogni errore rilevato. Il valore permane fino:\\ - ad un successivo errore;\\ - alla scrittura di uno dei seguenti parametri: mode, prot, wider, brate, stopb, par;\\ - ad una scrittura sullo stesso (qualsiasi valore lo azzera).\\ **0** = nessun errore,\\ **1** = parity error,\\ **2** = framing error,\\ **3** = overrun error. | + | |
- | | stype | W | 0 | R | - | **Slave type**\\ Indica il tipo di slave connesso. Il parametro viene aggiornato quando il parametro // | + | |
+ | ^ Name ^ D ^ R ^ A ^ Conditions | ||
+ | | err | B | 0 | R | - | **Errors**\\ Indicates if errors occurred in the protocol.\\ In master mode the parameter is updated to coincide the activation of the // | ||
+ | | serr | B | 0 | R/W | - | **Serial Errors**\\ Indicates if errors occurred in serial communication. The parameter is updated for each error encountered. The value persists until:\\ - under a subsequent error;\\ - the writing of one of the following parameters: mode, prot, wider, brate, stopb, par;\\ - writing about himself (any value will reset).\\ **0** = no errors,\\ **1** = parity error,\\ **2** = framing error,\\ **3** = overrun error. | ||
+ | | stype | W | 0 | R | - | **Slave type**\\ Indicates the type of slave connected. The parameter is updated when the // | ||
- | === - Stati === | ||
- | ^Nome^D^R^A^Condizioni^Descrizione^ | ||
- | |st_sended|F|0|R|-|**Sended**\\ Stato utilizzato solo in modalità master. L’attivazione indica il completamento della trasmissione di un messaggio. Lo stato viene resettato con i comandi SEND o SENDSYC.| | ||
- | |st_opencom|F|0|R|-|**Open communication port**\\ L' | ||
- | |wdata|F|0|R|-|**Warning Data**\\ Questo bit segnala che è stato tentato un inserimento di un valore non valido in un parametro.| | ||
- | |wcmd|F|0|R|-|**Warning Command**\\ Questo bit segnala che è non è stato eseguito un comando perché mancano le condizioni necessarie.| | ||
- | === - Comandi | + | === - States |
- | I comandi a disposizione per gestire il device sono elencati sotto in ordine di priorità decrescente.\\ | + | |
- | Il device esegue tutti i comandi ricevuti entro lo stesso tempo di campionamento iniziando da quello con la priorità maggiore.\\ | + | |
- | Per esempio se il device riceve nello stesso tempo di campionamento i comandi CLOSECOM e OPENCOM, per primo esegue il comando OPENCOM e poi quello di CLOSECOM lasciando perciò la porta di comunicazione chiusa. | + | |
- | ^Nome^D^R^A^Condizioni^Descrizione^ | + | ^Name^D^R^A^Conditions^Description^ |
- | |SEND|-|-|-|mode = 0\\ 0 < num <= 128\\ st_sended = 1\\ st_opencom = 1|**Sended**\\ Determina la trasmissione del messaggio verso lo slave selezionato.| | + | |st_sended|F|0|R|-|**Sended**\\ State only been used in master |
- | |SENDSYC|-|-|-|mode = 0\\ 0 < num <= 128\\ st_sended = 1\\ st_opencom = 1|**Send synchronize**\\ Utilizzabile solo in modo master | + | |st_opencom|F|0|R|-|**Open communication port**\\ Activation indicates that the device is working the serial communications port. To set this state use the OPENCOM command, to reset CLOSECOM.| |
- | |READSTYPE|-|-|-|mode = 0\\ st_sended = 1\\ st_opencom = 1|**Read slave type**\\ Richiesta lettura informazione type sullo slave specificato in idcard. La risposta verrá segnalata sul parametro stype quando lo stato st_sended diventa 1.| | + | |wdata|F|0|R|-|**Warning Data**\\ |
- | |CLRWDATA|-|-|-|-|**Clear Warning Data**\\ | + | |wcmd|F|0|R|-|**Warning Command**\\ |
- | |CLRWCMD|-|-|-|-|**Clear Warning Command**\\ | + | |
- | |OPENCOM|-|-|-|st_opencom = 0|**Open Serial communication**\ Apre la comunicazione seriale (il device quindi impegna la porta di comunicazione ). Lo stato st_opencom diventa 1.| | + | |
- | |CLOSECOM|-|-|-|-|**Close Serial communication**\\ Chiude la comunicazione seriale (il device quindi non impegna piú la porta di comunicazione ). Lo stato st_opencom diventa 0.| | + | |
+ | === - Commands === | ||
- | ===== - Descrizione funzionamento come slave ===== | + | The available commands to manage the device are listed below in descending order of priority.\\ |
- | ==== - Modo di funzionamento SLAVE ==== | + | The device executes all commands received within the same sampling time starting from the one with the highest priority.\\ |
+ | For example if the device receives the same sampling time CLOSECOM and OPENCOM commands, first run the OPENCOM command and then to CLOSECOM leaving therefore the communication port closed. | ||
- | La modalità slave viene impostata con il parametro | + | ^Name^D^R^A^Conditions^Description^ |
+ | |SEND|-|-|-|mode = 0\\ 0 < num <= 128\\ st_sended | ||
+ | |SENDSYC|-|-|-|mode = 0\\ 0 < num <= 128\\ st_sended = 1\\ st_opencom = 1|**Send synchronize**\\ Usable only in master mode determines the message transmission towards a slave QEM with synchronisation.| | ||
+ | |READSTYPE|-|-|-|mode = 0\\ st_sended = 1\\ st_opencom = 1|**Read | ||
+ | |CLRWDATA|-|-|-|-|**Clear Warning Data**\\ Reset the wdata parameter reporting.| | ||
+ | |CLRWCMD|-|-|-|-|**Clear Warning Command**\\ Reset the wcmd parameter reporting.| | ||
+ | |OPENCOM|-|-|-|st_opencom = 0|**Open Serial communication**\ Open the serial communication (the device then committed the communications port ). The st_opencom status becomes 1.| | ||
+ | |CLOSECOM|-|-|-|-|**Close Serial communication**\\ Close the serial communication (the device then does not committted the communications port ). The st_opencom status becomes 0.| | ||
- | **Impostazioni modbus e apertura del canale di comunicazione di tipo seriale** | + | |
+ | ===== - Slave operation description ===== | ||
+ | ==== - Slave mode operation ==== | ||
+ | |||
+ | Slave mode is set with the mode = 1 or mode = 2 parameter. You must to introduce in the parameters the slave ID code through the idcard parameter. | ||
+ | |||
+ | **Modbus settings and opening channel of serial communication** | ||
<code QCL> | <code QCL> | ||
modbus.mode = 1 ; modbus slave | modbus.mode = 1 ; modbus slave | ||
Line 437: | Line 440: | ||
ENDIF | ENDIF | ||
</ | </ | ||
- | **Impostazioni modbus e apertura del canale di comunicazione di tipo TCPIP** | + | **Modbus settings and open of the communication channel of TCPIP type** |
<code QCL> | <code QCL> | ||
modbus.mode = 1 ; modbus slave | modbus.mode = 1 ; modbus slave | ||
Line 454: | Line 457: | ||
</ | </ | ||
- | Le operazioni che spettano all’applicativo | + | The operations that should execute the QCL are essentially two: |
- | * aggiornare i parametri tipo owordNN, olongNN (che verranno poi letti dal master) | + | * update the parameters |
- | * processare i parametri tipo iwordNN, ilongNN (che sono stati scritti dal master) | + | * process the parameters |
- | === - Aggiornamento dei parametri tipo owordNN === | + | === - Updating |
- | Per aggiornare i parametri tipo owordNN il QCL deve scrivere i valori nei parametri quindi inviare il comando VALIDATE. | + | |
- | L’utilizzo del comando si rende necessario per rendere disponibili alle letture del master i nuovi dati nello stesso istante, | + | |
- | evitando così che possano venire letti solamente parte dei parametri aggiornati. Quindi l’assegnazione di un valore ad un | + | |
- | parametro device NON SIGNIFICA che esso sia immediatamente disponibile per le letture del master. Sarà disponibile | + | |
- | solamente dopo il comando VALIDATE. | + | |
- | **Esempio** | + | To update the owordNN parameters type the QCL must write values in the parameters then send the VALIDATE command. The use of the command is necessary to make available on the readings of the master the new data at the same time, so that they can be read only part of updated parameters. So assigning a value to a device parameter DOES NOT MEAN that it is immediately available for the master readings. Will only be available after the VALIDATE command. |
+ | |||
+ | **Example** | ||
<code QCL> | <code QCL> | ||
modbus.olong1 = anpos.speed | modbus.olong1 = anpos.speed | ||
Line 474: | Line 474: | ||
</ | </ | ||
- | === - Processo dei parametri tipo iwordNN === | + | === - Process |
- | Per processare i parametri tipo iwordNN, invece, il QCL deve attendere che lo stato st_msgrx venga attivato. Questo significa | + | |
- | che un messaggio di scrittura è stato inviato dal master. Per i messaggi di lettura nessun segnale viene riferito ai | + | |
- | parametri QCL. Il QCL poi deve prelevare i valori dall’area scambio dati e al termine deve inviare il comando RECEIVED, | + | |
- | solo allora lo stato st_msgrx viene disattivato. | + | |
- | **Esempio** | + | To process the iwordNN parameters type, instead,the QCL must wait for the st_msgrx state is activated. This means that a write message was sent by the master. For the read message no signal reportedly to QCL parameters. The QCL then must take the values from the data exchange and at the end needs to send the RECEIVED command, only then the st_msgrx state is disabled. |
+ | |||
+ | **Example** | ||
<code QCL> | <code QCL> | ||
WAIT modbus.st_msgrx | WAIT modbus.st_msgrx | ||
Line 488: | Line 486: | ||
RECEIVED modbus | RECEIVED modbus | ||
</ | </ | ||
- | Naturalmente non esiste nessun controllo per evitare che durante la lettura dei parametri //iwordNN// il master erroneamente | ||
- | esegua un’altra scrittura, prima che il codice del progetto presente nello slave finisca il processo.\\ | ||
- | Inoltre il codice per la manipolazione del device modbus nell’applicativo è consigliato che sia raccolto in un unico task in | ||
- | modo da non creare accessi contemporanei ai device che potrebbero generare delle condizioni non valide in ogni singolo | ||
- | contesto. | ||
- | Tutte le richieste di lettura che arrivano dal master MODBUS | + | There is no control to prevent when reading //iwordNN// parameters the master incorrectly execute another writing, before the project code present in the slave to finish the process.\\ |
- | alla stessa | + | Also the code for handling the modbus device in the application it is recommended that it is collected in a single task in order not to create simultaneous accesses to the device that could generate invalid conditions. |
- | Tutte le richieste di scrittura che arrivano dal master | + | |
- | alla stessa | + | All read requests that arrive from the master MODBUS |
- | ==== - Schema a blocchi | + | All write requests arriving from the MODBUS |
+ | ==== - Block diagram | ||
{{: | {{: | ||
- | ==== - Comandi e parametri | + | ==== - Commands and parameters |
- | === - Simbologia adottata | + | === - Used symbols |
- | Il nome del parametro, stato o comando è riportato alla sinistra della tabella. | + | The parameter name, condition or command is shown at the left of the table. |
**R**\\ | **R**\\ | ||
- | Indica se il relativo parametro o stato è ritentivo | + | Indicates if the parameter or state is retentive |
- | Se il device | + | If the device |
- | R = Ritentivo\\ | + | R = Retentive\\ |
- | 0 = Al momento dell’inizializzazione del device | + | 0 = Upon initialization of the device |
- | 1 = Al momento dell’inizializzazione del device | + | 1 = Upon initialization of the device |
- | - = Al momento dell’inizializzazione del device | + | - = Upon initialization of the device |
**D**\\ | **D**\\ | ||
- | Indica la dimensione del parametro.\\ | + | Indicates the size of the parameter.\\ |
F = Flag\\ | F = Flag\\ | ||
B = Byte\\ | B = Byte\\ | ||
Line 523: | Line 518: | ||
S = Single Float\\ | S = Single Float\\ | ||
- | == Condizioni | + | == Conditions |
- | Sono descritte tutte le condizioni necessarie affinché il parametro sia considerato corretto o perché il comando venga accettato.\\ | + | |
- | In alcuni casi sono specificati dei valori limite per l’accettazione del parametro: se sono introdotti dei valori esterni ai limiti impostati, il dato è comunque accettato; pertanto devono essere previsti opportuni controlli dell’applicativo tali da garantire il corretto funzionamento.\\ Per l’esecuzione di un comando, tutte le relative condizioni devono necessariamente essere soddisfatte; in caso contrario il comando non è eseguito. | + | Describes all the conditions necessary so that the parameter is considered correct or because the command is accepted.\\ |
+ | In some cases, limit values are specified for the acceptance of the parameter: if there are any values outside the limits set, the data is however accepted; therefore appropriate controls of the application must be provided to ensure the proper functioning.\\ To execute a command, all conditions must be met; otherwise the command is not executed. | ||
**A**\\ | **A**\\ | ||
- | Indica la modalità d' | + | Indicates the access mode.\\ |
- | R = Read (lettura).\\ | + | R = Read.\\ |
- | W = Write (scrittura).\\ | + | W = Write.\\ |
RW = Read / Write. | RW = Read / Write. | ||
- | === - Parametri | + | === - Parameters |
- | ^ Nome ^ D ^ R ^ A ^ Condizioni | + | |
- | | mode | B | R | R/W | - | **Mode**\\ (0 ÷ 2)\\ Definisce se la scheda deve funzionare come master | + | ^ Name ^ D ^ R ^ A ^ Conditions |
- | | prot | B | R | R/W | - | **Protocol**\\ | + | | mode | B | R | R/W | - | **Mode**\\ (0 ÷ 2)\\ Defines if the board should function as a master |
- | | wider | B | R | R/W | - | **Wide Registers**\\ | + | | prot | B | R | R/W | - | **Protocol**\\ |
- | | idcard | + | | wider | B | R | R/W | - | **Wide Registers**\\ |
- | | brate | L | R | R/W | - | **Baud rate**\\ Baud rate della seriale.\\ Valori validi: 4800, 9600, 19200, 38400, 57600, 115200. | + | | idcard |
- | | stopb | B | R | R/W | - | **Stop bit**\\ | + | | brate | L | R | R/W | - | **Baud rate**\\ Baud rate of the serial.\\ Valid values: 4800, 9600, 19200, 38400, 57600, 115200. |
+ | | stopb | B | R | R/W | - | **Stop bit**\\ | ||
| par | B | R | R/W | - | **Parity**\\ (0 ÷ 2)\\ **0** = none,\\ **1** = even,\\ **2** = odd. | | | par | B | R | R/W | - | **Parity**\\ (0 ÷ 2)\\ **0** = none,\\ **1** = even,\\ **2** = odd. | | ||
- | | rdelay | + | | rdelay |
| iword1÷32 | | iword1÷32 | ||
- | | st_ibit0÷15 | + | | st_ibit0÷15 |
| ilong1÷16 | | ilong1÷16 | ||
| oword1÷32 | | oword1÷32 | ||
- | | st_obit0÷15 | + | | st_obit0÷15 |
| olong1÷16 | | olong1÷16 | ||
Line 553: | Line 550: | ||
- | === - Variabili | + | === - Variables |
- | ^Nome^D^R^A^Condizioni^ Descrizione^ | + | |
- | |serr|B|0|R/ | + | |
- | === - Stati === | + | ^Name^D^R^A^Conditions^Description^ |
- | ^Nome^D^R^A^Condizioni^ Descrizione^ | + | |serr|B|0|R/W|-|**Serial Errors**\\ Indicates if errors occurred |
- | |st_msgrx|F|0|R||-|**Message received**\\ Stato utilizzato solo in modalitá slave. Indica che un messagio del master ha eseguito una scrittura nell’area scambio dati QCL. Lo stato viene resettato con il comando RECEIVED.| | + | |
- | |st_opencom|F|0|R|-|**Open communication port**\\ L' | + | |
- | |wdata|F|0|R|-|**Warning Data**\\ Questo bit segnala che è stato tentato un inserimento di un valore non valido in un parametro.| | + | |
- | |wcmd|F|0|R|-|**Warning Command**\\ Questo bit segnala che è non è stato eseguito un comando perchè mancano le condizioni necessarie.| | + | |
- | === - Comandi | + | === - States |
- | I comandi a disposizione per gestire il device sono elencati sotto in ordine di priorità decrescente.\\ | + | |
- | Il device esegue tutti i comandi ricevuti entro lo stesso tempo di campionamento iniziando da quello con la priorità maggiore.\\ | + | |
- | Per esempio se il device riceve nello stesso tempo di campionamento i comandi CLOSECOM e OPENCOM, per primo esegue il comando OPENCOM e poi quello di CLOSECOM lasciando perciò la porta di comunicazione chiusa. | + | |
- | ^ Nome ^ D ^ R ^ A ^ Condizioni | + | |
- | | RECEIVED | + | |
- | | VALIDATE | + | |
- | | CLRWDATA | + | |
- | | CLRWCMD | + | |
- | | OPENCOM | + | |
- | | CLOSECOM | + | |
+ | ^Name^D^R^A^Conditions^Description^ | ||
+ | |st_msgrx|F|0|R|-|**Message received**\\ State used only in slave mode. Indicates that a message from the master has executed a write in the QCL data exchange area. The state is reset with the RECEIVED command.| | ||
+ | |st_opencom|F|0|R|-|**Open communication port**\\ Activation indicates that the device is working with the serial communications port. To set this state use the OPENCOM command, for reset use CLOSECOM.| | ||
+ | |wdata|F|0|R|-|**Warning Data**\\ This bit indicates that an attempt was made to insert an invalid value in a parameter.| | ||
+ | |wcmd|F|0|R|-|**Warning Command**\\ This bit indicates that it did not execute a command because they lack the necessary conditions.| | ||
+ | === - Commands === | ||
- | ===== - Migrazione dal device | + | The available commands to manage the device |
+ | The device | ||
+ | For example if the device receives the same sampling time CLOSECOM and OPENCOM commands, first run the OPENCOM command and than to CLOSECOM leaving therefore the communication port closed. | ||
- | Il primo aspetto da tenere presente per la migrazione è il fatto che il device MODBUS01 è esterno mentre il MODBUS è | + | ^ Name ^ D ^ R ^ A ^ Conditions |
- | interno. Questo implica che la dichiarazione del device deve essere eseguita nella sezione “INTDEVICE” dell’unità di | + | | RECEIVED |
- | configurazione del progetto. Inoltre, questo comporta la scelta, durante la definizione del device MODBUS, del tempo di | + | | VALIDATE |
- | campionamento. Il valore del tempo di campionamento che mantiene inalterate le prestazioni della comunicazione tra i | + | | CLRWDATA |
- | due device è pari a 5 ms. Bisogna inoltre, in fase di definizione, | + | | CLRWCMD |
- | Il device MODBUS ha aumentato il numero di variabili di scambio (da 16 word a 32 word) ma questo non influenza il funzionamento | + | | OPENCOM |
- | per le impostazioni che utilizzano al massimo 16 word come sono quelle pensate per il device MODBUS01.\\ | + | | CLOSECOM |
- | Il device MODBUS ha limitato la variabile “num” a 128, mentre per il device MODBUS01 il limite è 256. Questo si è reso | + | |
- | necessario per permettere un’ottimizzazione del tempo di campionamento. La scelta è stata presa in considerazione del | + | |
- | fatto che tali valori venivano impiegati unicamente per la gestione dei Coils, ma che perdeva di logica la lettura/ | + | |
- | più di 128 coils consecutivi.\\ | + | |
- | Il device | + | |
- | del device. Questa nuova funzionalitá è interessante nell' | + | |
- | devices che possono utilizzare la stessa seriale.\\ | + | |
- | Se un applicativo era stato scritto per il device | + | |
- | solo una volta) come mostrato nel seguente esempio. | + | |
- | ==== Esempio: ==== | + | |
+ | |||
+ | ===== - Migration from MODBUS01 device to MODBUS device ===== | ||
+ | |||
+ | The first thing to note for migration is the fact that the MODBUS01 device is external, while the MODBUS is internal. This implies that the device declaration must be done in “INTDEVICE” section in the configuration unit of the project. In addition, this entails choosing, when defining the MODBUS device, of the sampling time. The value of the sample time that keeps the performance of communication between the two devices is 5 ms. Being defined, you must select the serial port to be committed.\\ | ||
+ | The MODBUS device increased the number of exchange variables (from 16 word to 32 word) but this does not affect the operation for settings that use the maximum 16 word How are those designed for the MODBUS01 device.\\ | ||
+ | The MODBUS device has restricted the “num” variable to 128, while the MODBUS01 device the limit is 256. This was necessary to allow an optimization of sampling time. The decision was taken in view of the fact that those values were used only for Coils managing, but that was logic leaking more than read/write 128 consecutive coils.\\ | ||
+ | The MODBUS device allows you to control (using 2 new commands) communication serial' | ||
+ | If an application was written for the MODBUS01 device you must add the OPENCOM command (executed only once) as shown in the following example. | ||
+ | |||
+ | ==== Example: ==== | ||
<code QCL> | <code QCL> | ||
- | ; impostazione dei parametri di comunicazione | + | ; setting communication parameters |
modbus.mode = 0 | modbus.mode = 0 | ||
modbus.brate = 38400 | modbus.brate = 38400 | ||
Line 615: | Line 605: | ||
WAIT modbus.st_sended | WAIT modbus.st_sended | ||
IF (modbus.err) | IF (modbus.err) | ||
- | CALL ErroreModbus | + | CALL ErrorModbus |
ENDIF | ENDIF | ||
</ | </ | ||