Emulate a PLC in Windows using Open PLC Runtime

Emulate a PLC in Windows using Open PLC Runtime

I need to develop a C# application that will communicate with a PLC to synchronize events on PC with actuators PLC(s) will drive. I don’t want to buy all the PLC(s) for my lab though so I was put onto a open source system called “Open PLC Project”. This includes a PLC runtime to emulate PLC functionality, and a editor for ladder logic (PLC programming).

Installing Open PLC Runtime

Open PLC is a webserver application. You can map digital IO hardware to the device if you are on a specific platform, or it appears as though you can monitor IO in software through the web interface. I’m using Windows as my development environment so I installed the windows webserver following the tutorial below:

The Open PLC Project website is no longer maintained so I found the runtime at the link below:

Opening the web server with Open PLC

If you want to drive inputs then you can use a web / IoT device such as a Raspberry PI, or Arduino with Digital IO. I chose to use a Windows PC.

  1. Open your web browser and type in localhost:8080 (that’s local host port 8080). Otherwise, use IP of device on your network with runtime installed on it, in place of “localhost”.
  2. A login screen appears. The default login is username “openplc” password “openplc”

Writing a PLC Program

You need to download Open PLC Editor and install it to write your program. I downloaded the editor form the link below:

MUST define memory location for variables

We’re going to run through loading your first program. It’s vital you define a memory location for your variables otherwise the “Monitoring” page in the PLC web interface won’t report Input / Output (IO).

For my first program I used the blink example. Once loaded you need to populate the location of the variable (Output) driving the LED in the example. For the location I swiped a memory location from the list defined in link below:

NOTE: You can use any of the defined memory locations (I think) so long as it’s an “output” since we’re observing an “output”.

When you are done creating your program you can click build. You can also run the program in debug mode in the editor. There’s probes you can select to watch state of given variables as well. See below…

PLC Interface / Loading your first program

Building the program generates a “.st” file. This ASCII file contains the code for the PLC to run. The PLC interface is a Web Server application you run in your web browser as mentioned earlier in this article.

  1. Load the program you created under the “</> Program” menu.
  2. Make sure your “Hardware” is set to “Blank” for Windows Runtime.
  3. Click Start PLC
  4. Go to “Monitoring” tab and you should be able to view the status of your memory mapped variables. That is, location defined in editor / code.
Matthew Jeschke

Comments are closed.