Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cs:sw:01-mervis:setting-modbus-server-hidden [2020/01/17 07:25] avsetula created |
cs:sw:01-mervis:setting-modbus-server-hidden [2024/03/14 09:08] (current) kcerny typos |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | FIXME - překlad | + | ====== Nastavení Modbus slave (serverového) zařízení ====== |
- | ====== Setting a Modbus server (slave) ====== | + | <WRAP group> |
- | So far in other tutorials, we used a UniPi controller as a Modbus master device. That is the download / upload of data to Modbus slaves (UniPi extensions, energy meters,...) were initiated by the UniPi controller. In this tutorial, we will demonstrate how to set UniPi as Modbus server, or in other terminology Modbus slave. | + | <WRAP half column 81%> |
+ | Doposud jsme v tutoriálech používali kontroléry Unipi jako master zařízení, tj. veškeré stahování či nahrávání dat do Modbus slave zařízení (rozšiřující moduly, elektroměry apod) byly iniciovány kontrolérem. V tomto tutoriálu si ukážeme, jak PLC Unipi nastavit jako Modbus server, či (při použití odlišné terminologie) jako Modbus slave. | ||
+ | </WRAP> | ||
+ | <WRAP half column 15%> | ||
+ | ;;# | ||
+ | <html><span class="dev-tag dev-patron">Patron</span></html> \\ | ||
+ | <html><span class="dev-tag dev-neuron">Neuron</span></html> \\ | ||
+ | <html><span class="dev-tag dev-gate">Gate</span></html> \\ | ||
+ | <html><span class="dev-tag dev-unipi11">Unipi 1.1</span></html> \\ | ||
+ | <html><span class="dev-tag dev-axon">Axon</span></html> | ||
+ | ;;# | ||
+ | </WRAP> | ||
+ | </WRAP> | ||
- | ===== Physical layer ===== | + | ===== Fyzická vrstva ===== |
- | As a first thing, we need to decide, what type of physical layer we will use. On UniPi running a Mervis, we can pick either from RS485 (ModbusRTU) or ethernet (ModbusTCP). The decision will be based on the rest of your existing infrastructure and the capabilities of devices, which will communicate with your UniPi. | + | Prvním krokem je rozhodnutí, jaký typ fyzické vrstvy budeme používat. U PLC Unipi se spuštěným Mervis IDE máme na výběr buď RS485 (protokol Modbus RTU), případně ethernet (protokol Modbus TCP). Tato volba je založena na zbytku existující infrastruktury, a na možnostech zařízení, která mají s PLC komunikovat. |
- | The RS485 physical layer is typically limited by its speed (115200bps) and nature of the [[https://en.wikipedia.org/wiki/Duplex_(telecommunications)#Half_duplex|half-duplex communication]], which limits the speed even further. On the other hand, the RS485 is easy to implement and still very popular in industrial automation. | + | Fyzická vrstva RS485 je typicky limitovaná svou max. rychlostí (115200 bps) a povahou [[https://en.wikipedia.org/wiki/Duplex_(telecommunications)#Half_duplex|poloduplexní komunikace]], která rychlost snižuje ještě více. Na druhou stranu je vrstva RS485 snadná na implementaci a stále jde na poli průmyslové automatizace o velmi populární volbu. |
- | To achieve communication between master and slave, some sort of addressing has to be used. In ModbusRTU, each slave device has to have unique ID or **address**, which is a number 0-255. | + | K nastavení komunikace mezi master a slave je nutné používat nějakou formu adresace. V protokolu Modbus RTU musí mít každé slave zařízení unikátní identifikaci, či **adresu**, která může být v rozsahu 0-255. |
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | On ModbusRTU network only one device can act as a master. Mervis will not allow you to create master and slave on the same RS485 port. But it cannot warn you, if you are setting master on a network, where another master is already present. | + | V síti Modbus RTU může jako master fungovat pouze jedno zařízení. Mervis IDE proto nedovolí vytvořit master i slave zařízení na jednom portu RS485. Zároveň ale nezobrazí varování, pokud nastavíte master zařízení na síti, ve které je master již přítomen. |
</WRAP> | </WRAP> | ||
- | The Ethernet physical layer allows connecting much more devices then RS485 and practically you are not limited by the speed or throughput of the network. **With ModbusTCP, you are also not limited to one master on one network**. | + | Fyzická vrstva Ethernetu umožňuje připojit výrazně více zařízení, než RS485. Zároveň zde neexistuje žádný praktický limit přenosové rychlosti či propustnosti. **S protokolem Modbus TCP rovněž nejste omezeni pouze na jedno master zařízení na síť**. |
- | The addressing on ModbusRTU is via IP address and port. Default port is 502. | + | V Modbus TCP probíhá adresování skrze IP adresu a port. Výchozím portem je port 502. |
- | ===== Setting ModbusRTU server (slave) ===== | + | |
- | In our tutorial, we will use UniPi Neuron L503 which is equipped with two RS485 ports. Let's start with generic project in **Full mode** - attached PLC, one FBD program, configured task and set autogen on the UniPi device. Make sure, that the build and deploy works without any problem. Your workspace should look like this. | + | ===== Nastavení Modbus RTU serveru (slave) ===== |
+ | V tomto tutoriálu budeme používat jednotku Unipi Neuron L503, která je vybavena dvěma porty RS485. Začněme s běžným projektem v **plném módu**, ve kterém máme připojené PLC s nastaveným Autogenem, a jeden FBD program. Ujistěte se, že kompilace i nahrání sestavy fungují bez problémů. Váš pracovní prostor by měl vypadat následovně: | ||
{{ :en:sw:01-mervis:modbus-server-01-workspace.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-01-workspace.png?direct |}} | ||
- | Now we need to add a **Server channel**. On the **Left panel**, right click on the **PLC** and in the context menu click on **Add Server Channel**. | + | Nyní je třeba přidat **kanál serveru**. V **levém panelu** klikněte pravým tlačítkem na **PLC** a v kontextovém menu klikněte na **Přidat kanál serveru**. |
{{ :en:sw:01-mervis:modbus-server-02-add-server-channel.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-02-add-server-channel.png?direct |}} | ||
<WRAP center round info 60%> | <WRAP center round info 60%> | ||
- | We are used to add **channel**, instead of **server channel**. **Channel** is for communication initated by UniPi controller. **Server channel** is for communication initiated by some other device to which the UniPi will respond to. | + | Doposud jsme přidávali **kanál**, nikoliv **kanál serveru**. **Kanál** je označení pro komunikaci iniciovanou kontrolérem Unipi. **Kanál serveru** je oproti tomu komunikace řízená jiným zařízením, kterému PLC odpovídá. |
</WRAP> | </WRAP> | ||
- | A new **server-channel** will appear under the **PLC**. Double click on it and on the **Properties panel** change the name to something more descriptive. The channel will be for ModbusRTU master communication, so the name **ModbusRTU-master** makes sense. | + | Pod **PLC** se objeví položka **server-channel**. Dvojitě na ni klikněte a v panelu **Vlastnosti** změňte jeho název na něco více popisného. Kanál bude sloužit pro komunikaci Modbus RTU v režimu slave, nazvěme jej proto třeba **ModbusRTU-slave**. |
{{ :en:sw:01-mervis:modbus-server-03-channel-name.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-03-channel-name.png?direct |}} | ||
- | On the same panel, change the **Protocol** to ModbusServer. | + | Na stejném panelu změňte **Protokol** na ModbusServer. |
{{ :en:sw:01-mervis:modbus-server-04-protocol.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-04-protocol.png?direct |}} | ||
- | The **Link Protocol** is already selected to **Serial**. But we need to set the correct port. | + | **Linkový protokol** je již přednastaven na **Serial**, nicméně stále je třeba nastavit správný port. |
{{ :en:sw:01-mervis:modbus-server-05-port-number.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-05-port-number.png?direct |}} | ||
- | We have the channel configured, now we need to define some device. Right click on the channel name in the **Left panel** and in the context menu click on the **Add Server Device**. | + | Kanál je nyní nakonfigurovaný, je na čase nastavit na něm zařízení. V **levém panelu** klikněte pravým tlačítkem na název kanálu, a v kontextovém menu klikněte na **Přidat zařízení serveru**. |
{{ :en:sw:01-mervis:modbus-server-06-add-server-device.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-06-add-server-device.png?direct |}} | ||
- | A new device will appear under the channel **ModbusRTU-master**. Double click on it and in the **Properties panel** change the **Device address** to something meaningful. We could change the **Name** as well, but on this channel we will have only one device. | + | Pod kanálem **ModbusRTU-slave** se objeví nové zařízení. Dvojitě na něj klikněte a v panelu **Vlastnosti** změňte **Adresu zařízení** na něco více popisného. Můžeme změnit i jméno, na tomto kanálu ale budeme mít pouze jedno zařízení. |
{{ :en:sw:01-mervis:modbus-server-07-device.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-07-device.png?direct |}} | ||
- | No we prepared everything we need to allow other devices to read and set variables in our PLC via ModbusRTU. The last thing is to define the Modbus registers and coil and their mapping to our variables. This will be the same for ModbusTCP server, so jump to the section [[#defining_registers|Defining registers]] | + | Nyní máme připravené vše potřebné k tomu, abychom mohli ostatním zařízením povolit číst a zapisovat proměnné na naše PLC skrze protokol Modbus RTU. Posledním krokem je definovat Modbus registry a coily, a namapovat je na naše proměnné. Tento proces probíhá stejně i na serveru Modbus TCP, u něj proto můžete přejít do sekce [[#definice_registru_a_coilu|Definice registrů]] |
- | ===== Setting ModbusTCP server (slave) ===== | + | |
- | Setting a ModbusTCP server (slave) is similar to the ModbusRTU server, but with different configuration of the server channel. Let's start with the same basic project. Your workspace should look like this. | + | ===== Nastavení Modbus TCP serveru (slave) ===== |
+ | Nastavení Modbus TCP serveru (slave) probíhá podobně jako u Modbus RTU serveru, budeme zde ale provádět jiná nastavení kanálu serveru. Začněme se stejným základním projektem. Váš pracovní prostor by měl vypadat následovně: | ||
{{ :en:sw:01-mervis:modbus-server-01-workspace.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-01-workspace.png?direct |}} | ||
- | Now we need to add a **Server channel**. On the **Left panel**, right click on the **PLC** and in the context menu click on **Add Server Channel**. | + | Nyní je třeba přidat **Kanál serveru**. V **levém panelu** klikněte pravým tlačítkem na **PLC** a v kontextovém menu klikněte na **Přidat kanál serveru**. |
{{ :en:sw:01-mervis:modbus-server-02-add-server-channel.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-02-add-server-channel.png?direct |}} | ||
- | <WRAP center round info 60%> | + | Pod **PLC** se objeví položka **server-channel**. Dvojitě na ni klikněte a v panelu **Vlastnosti** změňte jeho název na něco více popisného. Kanál bude sloužit pro komunikaci Modbus TCP v režimu slave, nazvěme jej proto třeba **ModbusTCP-slave**. |
- | We are used to add **channel**, instead of **server channel**. **Channel** is for communication initated by UniPi controller. **Server channel** is for communication initiated by some other device to which the UniPi will respond to. | + | |
- | </WRAP> | + | |
- | + | ||
- | A new **server-channel** will appear under the **PLC**. Click on it and on the **Properties panel** change the name to something more descriptive. The channel will be for ModbusTCP slave communication, so the name **ModbusTCP-slave** makes sense. | + | |
{{ :en:sw:01-mervis:modbus-server-08-server-channel-name.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-08-server-channel-name.png?direct |}} | ||
- | On the same panel, change the **Protocol** to ModbusServer. | + | Na stejném místě změňte **Protokol** na ModbusServer. |
{{ :en:sw:01-mervis:modbus-server-08-server-channel-protocol.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-08-server-channel-protocol.png?direct |}} | ||
- | And in the **Link Protocol** select **Tcp** | + | Jako **Linkový protokol** pak vyberte **Tcp**. |
{{ :en:sw:01-mervis:modbus-server-09-tcp-protocol.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-09-tcp-protocol.png?direct |}} | ||
- | That's all for the **Server channel** settings, now we need to define the device. Right click on the **ModbusTCP-slave** channel on the **Left panel** and in the context menu click on the **Add Server Device**. | + | Tím jsme dokončili nastavení **Kanálu serveru**, nyní je třeba nadefinovat zařízení. V **levém panelu** klikněte pravým tlačítkem na **ModbusTCP-slave** a v kontextovém menu klikněte na **Přidat zařízení serveru**. |
{{ :en:sw:01-mervis:modbus-server-10-add-server-device.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-10-add-server-device.png?direct |}} | ||
- | New **device** will appear under the channel **ModbusTCP-slave**. Select it and in the **Properties panel**, change the **Device address** to something meaningful. | + | Pod kanálem **ModbusTCP-slave** se objeví nové zařízení s názvem **device**. Vyberte jej a v panelu **Vlastnosti** změňte **Adresu zařízení** na platnou hodnotu. |
{{ :en:sw:01-mervis:modbus-server-11-device-address.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-11-device-address.png?direct |}} | ||
- | In the **TCP Parameters** section, you can see **Device IP Address** and **Device Port**. | + | V sekci **Parametry TCP** můžete vidět kolonky **IP adresa zařízení** a **Port zařízení**. |
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | You can leave the **Device IP Address** as is (0.0.0.0). The Mervis will internally set it to the current IP address of the PLC. | + | **IP adresu zařízení** můžete ponechat na výchozí hodnotě (0.0.0.0). Mervis IDE interně nastaví adresu stejnou jako pro PLC. |
- | The **Device Port** however, you need to set. Typical ModbusTCP port is 502, but there is already running internal application on this port. So set it to 503 for example. | + | Naopak **Port zařízení** je třeba nastavit. Obvyklým Modbus TCP portem je port 502, na něm již ale jedna aplikace běží. Nastavte jej proto např. na 503. |
</WRAP> | </WRAP> | ||
{{ :en:sw:01-mervis:modbus-server-12-device-port.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-12-device-port.png?direct |}} | ||
- | No we prepared everything we need to allow other devices to read and set variables in our PLC via ModbusTCP. The last thing is to define the Modbus registers and coil and their mapping to our variables. | + | Nyní máme připravené vše potřebné k tomu, abychom mohli ostatním zařízením povolit číst a zapisovat proměnné na naše PLC skrze protokol Modbus TCP. Posledním krokem je definovat Modbus registry a coily, a namapovat je na naše proměnné. |
- | ===== Defining registers and coils ===== | + | |
- | The Modbus communication is for exchanging data only. The master reads and sets datapoints configured in the slave. In Modbus, there are four types of datapoints you can read or write, but they have only two data types: boolean and word (16bit integer). This is due to the age of the Modbus protocol (more than 40 years), and to keep the communication as simple as possible. Any other datatype (32bit real, string,...) has to be converted to 16bit value, for example by using more datapoints. | + | |
+ | ===== Definice registrů a coilů ===== | ||
+ | Komunikace přes Modbus je určena pouze pro výměnu dat. Master zařízení vyčítá a nastavuje datové body, které jsou nakonfigurovány na slave zařízení. V protokolu Modbus existují čtyři druhy datových bodů pro čtení i zápis, které ale mohou používat pouze dva datové typy - boolean a word (16-bitový integer). Toto omezení je zde kvůli stáří protokolu Modbusu (více než 40 let) a k udržení komunikace co nejjednodušší. Jakýkoliv jiný datový typ (32-bit real, string aj.) je třeba nejprve převést na 16-bitovou hodnotu, například použitím více datových bodů. | ||
- | ==== Datapoints ==== | + | ==== Datové body ==== |
+ | **Coil** je booleanovský datový bod, u kterého může master zařízení provádět čtení i zápis. Coily se obvykle používají pro ovládání digitálních či reléových výstupů, které mohou nabývat pouze hodnot ''TRUE'' nebo ''FALSE''. | ||
- | A "**coil**" is a boolean datapoint which the master can read and set its value. This datapoint is typically for controlling digital or relay outputs, which can only be set to ''TRUE'' or ''FALSE''. | + | Druhým booleanovským datovým bodem je **vstup** či **stav vstupu**, který může master pouze číst. Typicky jej využijete u digitálních vstupů. |
- | The second boolean datapoint is called "**input**" or "input status" and master can only read its value. Typically, you would use this datapoint for digital input. | + | Datový bod typu word se nazývá **registr** či **holding registr** a master jej může číst i zapisovat do něj. Tento datový bod je vhodný pro výměnu analogových hodnot. |
- | The word datapoint is called "**register**" or "holding register" and master can read and set its value. You will use this datapoint for exchanging analog values. | + | Druhý datový bod typu word má název **vstupní registr**. Z něj může master pouze vyčítat. Obvykle se tento datový bod používá pro odečty teploty. |
- | The second word datapoint is called "**input register**" and master can only read its value. Typically, you would use this datapoint for reading a temperature. | ||
- | ==== Setting a datapoints ==== | + | ==== Vytvoření datového bodu ==== |
- | To set the datapoints, double click on the **device** under your Modbus slave channel in the **Left panel**. | + | K nastavení datových bodů klikněte v **levém panelu** na položku **device** pod Modbus slave kanálem. |
{{ :en:sw:01-mervis:modbus-server-13-list-of-registers.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-13-list-of-registers.png?direct |}} | ||
- | The list of registers exported by the device will appear in the **Main window**. At the bottom of the **Main window**, you can see tabs **Analogs** and **Digitals**. On the **Analogs** tab, you can manage the **registers** and **input registers**. On the **Digitals** tab, you can manage the **coils** nad **inputs**. | + | V **hlavním panelu** se objeví seznam registrů exportovaný zařízením. Na dolním okraji **hlavního panelu** můžete vidět záložky **Analogové** a **Digitální**. V záložce **Analogové** můžete spravovat **registry** a **vstupní registry**. V záložce **Digitální** pak můžete měnit nastavení **coilů** a **vstupů**. |
- | To add new register, right click on the empty list, and in the context menu, click on the **Add Variable**. This is the quicker way than selecting the **Add Register**. | + | Nový registr přidáte kliknutím pravým tlačítkem do prázdného prostoru. V kontextovém menu pak vyberte **Přidat proměnnou**. Tento způsob je rychlejší, než **Přidat registr**. |
{{ :en:sw:01-mervis:modbus-server-14-add-variable.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-14-add-variable.png?direct |}} | ||
- | The list of available variables will appear, and you can search in this list. Search for **CNT_1.01** and select the **Neuron_L503_CNT_1.01** variable, or the one with the similar name. An confirm by clicking on **OK**. | + | Objeví se seznam dostupných proměnných, ve kterým můžete vyhledávat. Vyhledejte **CNT_1.01** a vyberte proměnnou s názvem "Neuron_L503_CNT_1.01" či podobným. Potvrďte kliknutím na **OK**. |
{{ :en:sw:01-mervis:modbus-server-15-select-variable.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-15-select-variable.png?direct |}} | ||
- | The new register will appear on the list. We can see it's properties: | + | V seznamu se objeví nový registr, u kterého můžeme vidět jeho vlastnosti: |
{{ :en:sw:01-mervis:modbus-server-16-register-detail.png?direct |}} | {{ :en:sw:01-mervis:modbus-server-16-register-detail.png?direct |}} | ||
- | The properties are: | + | Těmito vlastnostmi jsou: |
- | - **Starting element** is the **address of the register**. The address cannot be changed | + | - **Počáteční prvek** je **adresou registru**. Tuto adresu nelze změnit. |
- | - **Simple transform** offers a way how to transform the value from mapped variable to the Modbus register, e.g. convert to int, if the mapped variable is real | + | - **Prostá transformace** je způsob, jakým se převádí hodnota z namapované proměnné na Modbus registr (např. převod na int, pokud je mapovaná proměnná typu real). |
- | - **Function** is the Modbus function by which the register can be read | + | - **Funkce** označuje Modbusovou funkci, která umožňuje z registru vyčítat |
- | - **Mapped variable** contains name of the mapped variable | + | - **Mapovaná proměnná** udává název namapované proměnné |
- | - **Type** shows the type of the mapped variable | + | - **Typ** udává typ namapované proměnné |
- | To set the **coils**/**inputs** is practically the same, just proceed on the **Digitals** tab. | + | Nastavení **coilů** / **vstupů** probíhá prakticky shodně, pouze se tak děje v záložce **Digitální**. |