Changes between Version 1 and Version 2 of scada/codesysplcdemo


Ignore:
Timestamp:
03/13/2025 09:23:14 PM (3 weeks ago)
Author:
Blake Stewart
Comment:

Copied documentation + images from document

Legend:

Unmodified
Added
Removed
Modified
  • scada/codesysplcdemo

    v1 v2  
    1 = Gateworks Codesys - PLC - SCADA Demo
     1= Gateworks SoftPLC + SCADA Factory Automation Demo
    22
    3 insert info here
     3This documentation provides a technical overview + steps to create a SoftPLC device on a Gateworks SBC running custom user-defined ladder logic, then connect it over Modbus TCP to a SCADA controller for factory-automation environments.
     4
     5[[PageOutline]]
     6
     7
     8[[Image(SCADA-PLC-GW.jpg, width=600)]]
     9
     10
     11**The CODESYS SoftPLC platform turns Gateworks SBCs into industrial-grade logic controllers for seamless, reliable factory automation at every level.** CODESYS SoftPLCs are Linux-based and have more flexibility than traditional PLC controllers; Gateworks SBCs are the preferred industrial boards to host the CODESYS automation system.
     12
     13
     14[[Image(ladder-logic-diagram-help-codesys-v0-dov1m4j4vi8d1.png, width=500)]]
     15
     16''CODESYS Ladder Logic''
     17
     18**Ignition SCADA** software can configure tasks and conditionals, and display comprehensive reliable dashboards for configuring and monitoring systems remotely or on-site. Acting as the “brain” of the system, it provides both oversight and configuration. Many users appreciate Python’s versatility, enabling scripts to trigger alarms or logic controllers for high-level automation. Given the critical task of overseeing automation, an unreliable computer is not an option. Hosting Ignition SCADA on a Gateworks board ensures reliability and robustness.
     19
     20[[Image(scada_dash.jpg, width=500)]]
     21
     22''SCADA Dashboard''
     23
     24=== Hardware Requirements
     25For **CODESYS SoftPLC**:
     26* 1x Gateworks SBC (Documentation uses GW7201)
     27* 2x Ethernet CAT.6 for network & POE
     28For **Ignition SCADA**:
     29* 1x Gateworks SBC (Recommended GW74xx for expansion capabilities)
     30* Ethernet CAT.6 for each directly connected PLC + POE
     31
     32== CODESYS Installation Steps
     33Installation occurs on the development host (Windows) and the Gateworks SBC (SoftPLC).
     34
     35You will need:
     36* Fresh install of Ubuntu Noble Venice on a GW7xxx (this documentation was done with GW7201)
     37* [https://store.codesys.com/en/codesys.html CODESYS Development Environment] on Windows Host
     38* A connection between host and SBC via IP (SSH connection steps [https://trac.gateworks.com/wiki/gettingstarted#SSHEnabling here])
     39* [https://store.codesys.com/en/codesys-control-for-linux-arm-sl-1.html CODESYS Control for Linux ARM SL], the runtime environment for the SoftPLC
     40
     41Once you have a confirmed connection/ping between the Windows machine and the board, install the CODESYS Linux Runtime which can be obtained in the link above. To install on the board, use the Windows host with CODESYS software which handles downloading. Create a new Standard Project.
     42
     43[[Image(image19.png, width=500)]]
     44
     45From a fresh install, make sure that you can **ssh into the SBC** root. Edit the sshd_config on the board if necessary.
     46Then you should be able to fetch “System Info” from the Windows host given the username, password, and SBC IP.
     47
     48[[Image(compound.png,width=500)]]
     49
     50The CPU Info and Network Info areas being populated show that CODESYS can connect to the device. The next step is to **install the CODESYS Runtime Package**.
     51This documentation assumes access to the 4.13.0.0 (linuxarm64, arm64) runtime package, listed above in the requirements, which can be [https://store.codesys.com/en/codesys-control-for-linux-arm-sl-1.html accessed through the CODESYS website].
     52Installing the runtime package will likely also prompt installation of the Edge Gateway, which also needs to be installed.
     53
     54[[Image(image9.png,width=500)]]
     55
     56Once complete, click “Reboot Target” to ensure the device is running correctly. “System Info” will now show information about the package and runtime info.
     57
     58[[Image(image17.png,width=500)]]
     59
     60The installation of the CODESYS runtime is now complete, and the SoftPLC is ready to have logic implemented on it. The next steps will show exactly how to do so.
     61
     62== Connecting to the PLC from CODESYS
     63
     64Now that the runtime and gateway are installed on the device, there is a second layer of abstraction when connecting to it from our Windows (development) host. There is the Linux user (in our case, the default “root”) and the SoftPLC Device user (which is determined on the first login). You will be prompted to create a device user when connecting to the device on the “Device” tab.
     65Enter the IP address of the device/board on the right, and a connection will be established to that inner abstraction layer (The SoftPLC). You will be prompted to log in to the device.
     66
     67
     68[[Image(image14.png,width=500)]]
     69
     70
     71[[Image(image11.png,width=500)]]
     72
     73
     74Once connected, you will have a dashboard of the current program running on the PLC.
     75
     76== Ladder Diagrams + GPIO: Button to LED
     77
     78We will implement a simple program through ladder logic in CodeSYS to turn on a light as long as a button is pressed. Infinitely more logic can be added, but the simple demo shows the connection between software and hardware; in the next section, we will include multi-device communication to reliably turn on and off lights.
     79
     80Our GW7201 which this documentation is written on has 2 exposed GPIO ports by default. In most cases, GPIO ports will be exposed through expanders or other devices, and the same process should follow. You can find specific information on the Wiki about [https://trac.gateworks.com/wiki/gpio Gateworks GPIO] and about [https://trac.gateworks.com/wiki/venice/DigitalIO Venice family DIO] for your board specifically.
     81
     82Our logic will use one DIO as an input (button), and one DIO as an output (LED).
     83
     84Running “$ gpioinfo gpiochip0” shows the DIO lines on the standalone SBC. In our case, they exist on Line 9 (dio0) and Line 11 (dio1)
     85
     86[[Image(image7.png,width=500)]]
     87
     88
     89Add Device GPIO, Add device GPIO 4 pins (choice of 1, 4, or 16. We’re using 2, so selecting 4 will be the least complicated)
     90
     91[[Image(image4.png,width=500)]]
     92
     93
     94In the GPIOs_4_bit GPIOSysfsModuleParameters, establish a connection between Bits 1 and 2 and the DIOs listed from the gpioinfo response from earlier. In our case, DIO0 and DIO1 are on lines 9 and 11, but this varies from board to board (such as a GW7200 versus a GW7400).
     95In this example, Bit 1 is an INPUT for the button, and Bit 2 is an OUTPUT for the LED.
     96
     97
     98[[Image(image13.png,width=500)]]
     99
     100
     101Once entered, view the CODESYS variables associated with each bit on the next tab labeled “GPIOSysfsModule I/O Mapping” (Bit 1 is an input, Bit 2 is an output)
     102
     103
     104[[Image(image12.png,width=500)]]
     105
     106
     107On the ladder diagram PLC_PRG, connect the Bit 1 Input to BUTTON coil, and the LED variable to the Bit 2 output. The specific mapping name (i.e. %IX20.0) will change depending on your project. On the bottom network, we implement a simple connection directly between the BUTTON contact and the LED being activated.
     108
     109[[Image(image2.png,width=500)]]
     110
     111
     112On a breadboard, establish a simple button connection using a pull-down resistor, pushbutton, and LED.
     113
     114[[Image(schematic.png,width=500)]]
     115
     116After the connections have been made, upload the program with the “login” button and watch as CODESYS shows a real-time view of the connections.
     117
     118[[Image(image20.png,width=500)]]
     119
     120More customization can be done on the CODESYS application side, such as visualizations, which are easy to implement once you have the base logic set up successfully.
     121
     122[[Image(image21.png,width=250)]]
     123
     124== Modbus TCP Communication
     125
     126Modbus TCP and Profinet are both communication protocols used in factory automation: Profinet by Siemens is a gold standard that Gateworks devices support.
     127While Gateworks SBCs & CODESYS support Profinet just fine, Modbus TCP was used for this demo since Inductive Automation supports it natively.
     128
     129=== Interfacing Modbus TCP In CODESYS
     130
     131Add an Ethernet device to the Device, and then add a Modbus TCP Server Device to that ethernet device. This enables Modbus TCP communication on the SoftPLC.
     132Configure the Ethernet device to have the IP of the SBC (static is preferred)
     133In the Modbus TCP server device, note the bits from the preferred holding registers.
     134
     135[[Image(image10.png,width=500)]]
     136
     137The Modbus TCP protocol opens up many read/write registers each containing 16 bits; these can be connected directly on the ladder logic diagram to remotely control them with commands or Ignition SCADA.
     138In this case, the first 2 bits of register 0 are connected to the first 2 GPIOs (configured as output). This allows for commands to be sent to instantly control both LEDs independently.
     139
     140[[Image(image3.png,width=500)]]
     141
     142Now you can upload the program to the PLC and test the functionality using the ‘mbpoll’ tool from the development machine’s command line.
     143
     144=== Reading from Modbus TCP remotely using mbpoll on the CLI (development only)
     145mbpoll -t 4 -c 2 -v <ip>
     146
     147=== Writing to Modbus TCP (development only)
     148mbpoll -t 4 -v <ip> -r <register> <register value>
     149mbpoll -t 4 -v <ip> [register values …
     150
     151== Connection to Ignition SCADA
     152Ignition SCADA is perfectly equipped to use Modbus TCP to robustly talk to a multitude of SoftPLCs; this is industry standard.
     153Ignition has this process [https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/opc-ua/opc-ua-drivers/modbus/connecting-to-modbus-device well documented here]. The ladder logic diagrams we implemented earlier run independently of SCADA, and Modbus TCP’s registers serve as the interface between the SCADA “brain” overseeing automation and the PLCs.
     154
     155[[Image(scada_dash.jpg,width=500)]]
     156
     157== Ensuring Security and Reliability
     158During the development process, we opened up the root of the Linux SBCs to SSH connections. This should be disabled in any production environment.
     159VLAN isolation should also be used in production environments to protect the SBCs from outside traffic. In the production environment, the SBCs only communicate to the SCADA host via the MODBUS TCP protocol; all others should be blocked. Include layers of communication in the VLAN and strictly block all traffic between the PLC and outside devices.
     160Gateworks SBCs run Linux, which has many resources for standardized, industrial networking.
     161
     162== Conclusion
     163With knowledge of implementing SoftPLCs and SCADA systems, you are now fully equipped with the foundation to implement robust, industrial-grade automation systems on Gateworks SBCs!
     164
     165
     166
     167