Seafoxc

Factory I/O is a simulation software to learn PLC programming. 
You can use OpenPLC to connect with the Modbus protocol to Factory I/O. 
This code is written to run the "production line" one of the Factory I/O scene's.  

Is used the OpenPLC Runtime on Windows for this project and the language is FBD. 

Factory IO post.jpg   

The line exist out of two CNC machine centers and some conveyers. The CNC centers look difficult but it is a lot easier then it seems. 

I made a small video (3:20min) to give you an idea what the code does. 

https://youtu.be/20qy7CKbF7E


Explanation program 

First I started with some good RTFM (Read The F***ng manual) about the machine center:  https://docs.factoryio.com/manual/parts/stations/

Then I opened the scene's and changed all the variables. 
I use a variable name based if it is an Input or Output, The location, The object and the function. 

I_ = Input
Q_ = Output
Z = Zone
MC = Machine Center
Sens = Sensor
Pb = Pushbutton
BC = Band Conveyer
RC = Roller Conveyer

So for example: I_Z01BC01ArrivedSens
is an input in Zone 1 and is the arrived sensor of Band Conveyer 01. 

I added the adjusted Scene to the ZIP file. 

Object oriented programming

You have a few objects in the program like the belt conveyers but there is not a lot of control for those in the scene (no manual switch not a lot of sensors) so I did not bother to write a Function block for that. I did made a function block for the Machine center. 

FB machine center.jpgSo both Machine centers use the same function block. 

This code can be improved upon to make it easier to spot mechanical or electrical failures but it is just for training and learning so I will put my time in solving the next scene's. 
 
How to run the code?

Factory I/O set-up

First of all you need Factory I/O (There is a free trail for 30 days without credit card) => Factoryio.com.


Then you unzip the file added to this post and you copy the scene "Production_Line_renamed_var.factoryIO" to the default location of the Factory I/O scene's. 

Documents\Factory IO\MyScenes

You open Factory I/O and open the scene and go to "drivers" (key "F4").

The mapping should be already made but some options should be checked/changed.


driver.jpg 

- Write down the IP address (to be entered in the settings for OpenPLC Runtime slave settings). 

Check the configuration (IP address and Network adaptor can be different). 


settings driver.jpg 

OpenPLC Runtime settings

 - Run Open PLC runtime and add a slave. 


OpenPLCRuntime settings.jpg

- Change the IP address to the same address as in Factory I/O settings. 

Make sure the addresses look like this:



slave good.jpg 

- Upload the OpenPLC runtime project "MachineCenter.st" (file from ZIP file). 
- Set the OpenPLC in Run
- Set Factory I/O in the play setting. 

 

In the Zip file there is also the OpenPLC editor file for you to change and take a look at. 

Let me know what you think if you downloaded it. 

If you are stuck on setting up Factory I/O with OpenPLC you can also find a video on how to do it on my YouTube Channel. 







I have no Idea what I'm doing...
Reply 3 0
thiagoralves
As I said, the poor performance on factory IO is related to GPU, not CPU configuration. If your server lacks a GPU, it won’t run well.
 
As for your SCADA issue, you might get better support from your SCADA software provider. On the OpenPLC side, the runtime v3 comes with Modbus server enabled by default. Any SCADA software that can talk over Modbus will be able to talk to the runtime
Reply 1 0
baskoinge
Good morning, I’m having the following problem, and I don’t understand why it’s happening, as everything was working fine before.
The SlaveDevice settings are correct, and so on…
Can you help me?
Thanks
[203128%2F9725036%2Fmceclip0]
Reply 0 0
baskoinge
Another...
[203128%2F9725118%2Fmceclip0]
Reply 0 0
thiagoralves
What slave device are you using? Did you check if it still works? What is the slave configuration? Is this a Modbus RTU or TCP slave? Have you checked your network settings in case of TCP?
Reply 0 0
baskoinge
I'm using the next:
[203128%2F9725126%2Fmceclip0]
 
[203128%2F9725127%2Fmceclip0]
Reply 0 0
thiagoralves
Got it. From the logs, the runtime is not being able to communicate with the slave (Factory I/O in your case). Make sure your Factory IO Modbus server is accessible from the device running OpenPLC runtime, and that the server is running correctly.
Reply 0 0
baskoinge
Got it. From the logs, the runtime is not being able to communicate with the slave (Factory I/O in your case). Make sure your Factory IO Modbus server is accessible from the device running OpenPLC runtime, and that the server is running correctly.
Both are on the same device, with the same IP address, so the communication is internal
Reply 0 0
thiagoralves
Well, if both are on the same device then possibly you are getting a server conflict. Is Modbus server enabled on OpenPLC Runtime as well? It is normally enabled by default, so if you didn't change that, it probably is enabled. And the default port is 502 (default Modbus port). This means OpenPLC runtime and Factory I/O are both trying to start a Modbus server on the same IP and the same port. Not going to work every time. One of them is going to prevent the other from starting. If that's your case you can either disable the Modbus server or change the Modbus server port on OpenPLC Runtime (server, not client, as the client must connect to Factory IO port) to something else other than 502.
Reply 0 0
baskoinge
Well, if both are on the same device then possibly you are getting a server conflict. Is Modbus server enabled on OpenPLC Runtime as well? It is normally enabled by default, so if you didn't change that, it probably is enabled. And the default port is 502 (default Modbus port). This means OpenPLC runtime and Factory I/O are both trying to start a Modbus server on the same IP and the same port. Not going to work every time. One of them is going to prevent the other from starting. If that's your case you can either disable the Modbus server or change the Modbus server port on OpenPLC Runtime (server, not client, as the client must connect to Factory IO port) to something else other than 502.
I’ve changed the port in OpenPLC to 502 and left it as 503 in factoryIO; the IP address remains the same. This has worked well for me on other machines.
Now the following message appears and the robotic arm doesn’t move in factory.
[203128%2F9725371%2Fmceclip0]
Reply 0 0
thiagoralves
From the logs it looks like you made OpenPLC connect to itself. Your best bet is to disable OpenPLC Modbus server, especially if you’re not using it. Then leave everything at port 502
Reply 0 0
baskoinge
From the logs it looks like you made OpenPLC connect to itself. Your best bet is to disable OpenPLC Modbus server, especially if you’re not using it. Then leave everything at port 502
When I disable it, the following happens: when I start up the OpenPLC, the robotic arm still doesn’t move. Sorry for the trouble, but I’m surprised because everything was working fine and then suddenly it stopped working.
[203128%2F9725408%2Fmceclip0]
[203128%2F9725410%2Fmceclip0]
[203128%2F9725416%2Fmceclip0]
[203128%2F9725417%2Fmceclip0]
Reply 0 0
thiagoralves
That means your OpenPLC runtime cannot reach your Factory IO Modbus server. Either your IP, port, slave ID configuration is wrong, or Windows is blocking these process to talk to each other, or Factory IO Modbus server is not running at all. OpenPLC side seems to be working as it can even connect to itself when the Modbus server is enabled.
Reply 0 0
baskoinge
That means your OpenPLC runtime cannot reach your Factory IO Modbus server. Either your IP, port, slave ID configuration is wrong, or Windows is blocking these process to talk to each other, or Factory IO Modbus server is not running at all. OpenPLC side seems to be working as it can even connect to itself when the Modbus server is enabled.
Sorry, but i don't understand because i copied the step by step for the beginning of this instructions:
You open Factory I/O and open the scene and go to "drivers" (key "F4").
The mapping should be already made but some options should be checked/changed.

driver.jpg
- Write down the IP address (to be entered in the settings for OpenPLC Runtime slave settings).
Check the configuration (IP address and Network adaptor can be different).

settings driver.jpg

OpenPLC Runtime settings
 - Run Open PLC runtime and add a slave.

OpenPLCRuntime settings.jpg
- Change the IP address to the same address as in Factory I/O settings.
Make sure the addresses look like this:


slave good.jpg
- Upload the OpenPLC runtime project "MachineCenter.st" (file from ZIP file).
- Set the OpenPLC in Run
- Set Factory I/O in the play setting.
 
In the Zip file there is also the OpenPLC editor file for you to change and take a look at.

Let me know what you think if you downloaded it.
If you are stuck on setting up Factory I/O with OpenPLC you can also find a video on how to do it on my YouTube Channel.
Reply 0 0
thiagoralves
You will have to check your system, network, settings and configuration. Make sure that both IP and port are the same on Factory IO and slave device configuration. On the screenshot you posted it seems that port being used is 503. Make sure your slave configuration is pointing to 503.
Reply 0 0
baskoinge
You will have to check your system, network, settings and configuration. Make sure that both IP and port are the same on Factory IO and slave device configuration. On the screenshot you posted it seems that port being used is 503. Make sure your slave configuration is pointing to 503.
It's sorted now; I've reinstalled everything with exactly the same settings, and it's working now.
Thanks for your help.
Reply 1 0
Reply