eightbitsandwich Show full post »
There are debug messages (printf) commented out on SimLink code. You can try to remove the comments and compile again, to see if you're getting anything. Due to buggy code, the order in which you start the programs can prevent them from communicating. I need to cleanup the code to fix those issues, but right now it is not on my priority list. Try launching OpenPLC first, and then SimLink, and then your Simulink model. Also, try to add a constant on your Simulink model and send that constant to OpenPLC, just to see if OpenPLC is receiving data from Simulink.

Are you running SimLink and OpenPLC on the same VM? If that's the case, you can also try to replace the station0.ip with "localhost".
Quote 0 0
I may be looking at the wrong items here but I noticed that "/OpenPLC_v2/core/hardware_layer.cpp" defines PORT as 6668 but the config file calls out ports 10001 and 10002. Do you think this could have anything to do with the OpenPLC server being non-responsive to my simulink inputs?
Quote 0 0

-It seems that OpenPLC isn't responding to the interface.cfg settings and instead is defaulting to the port in hardware_layer.cpp, that is it is using port 6668 instead of 10001.

-One thing I also noticed is that OpenPLC doesn't send data back towards the Simulink IP listed in the interface.cfg file but rather it sends it back to the IP listed as the source in the UDP packet. I'm not sure why but maybe the virtual NIC is masking the source IP ( and replace it with its own ( OpenPLC responds by using the virtual NIC IP as the destination IP instead of the original source IP. (For reference I have the original source IP in the interface.cfg)

Quote 0 0
OpenPLC doesn't read the interface.cfg file. The port 6668 hardcoded in the hardware_layer.cpp file is used to communicate with SimLink directly. I have the feeling that you're leaving SimLink out of the equation. Without it, OpenPLC cannot communicate with your Simulink model. SimLink is the software that reads your interface.cfg file (the SimLink executable and the .cfg file must reside on the same folder) and opens the ports to communicate with your Simulink model. It also connects to OpenPLC stations on the 6668 port to read/write data. The reason why I created this communication bridge (SimLink) instead of having the connection directly with OpenPLC is to allow the simulation of more complex models with many PLC stations. This way, your complex Simulink model talks to SimLink, which opens connections to many OpenPLC stations simulating many PLCs.
Quote 0 0
Hello Thiago,

I would like to thank you for your great program. I'm doing some research using OpenPLC to create and run plcs.
I'm trying to implement this Hello_World example. I cannot connect OpenPLC to the simulation (Simulink) using SimLink.

1)  I cannot open hello world.xml with Openplc Editor. It says can not open a folder content file! However I created another project as scratch, then put that xlm file in it and compiled it to have .st to run in on OpenPLC runtime. (I am not sure if it works correctly but I guess it does - I checked the .st code it seemed ok).

2) I have chosen simulink as the hardware layer in OpenPLC runtime and uploaded .sd file. Is that correct?

3)  When I run simulation and start plc, then I run SimLink. I have SimLink.cpp and “interface.cfg” on Desktop and I run this command in Cygwin: g++ C:/Users/justin/Desktop/simlink.cpp -o simlink -pthread

4)  In interface.cfg,  simulink.ip = "localhost" and station0.ip = "localhost" . Also I have tried all previous steps using localhost number instead of “localhost”. My localhost number (IPv4 number) is

After doing all, still I can not see green light. I guess Simulink does not send signal to OpenPLC (or maybe it does but SimLink connection does not work).  Any suggestion over the problem? Thank you.
Quote 0 0
Hi there. I’m afraid you’re not running SimLink. The command you mentioned on 3) is just to compile SimLink, not to run it. After you have that compiled, you must launch the executable file from Cygwin to start it: ./simlink

Try that and, if it still doesn’t work, post here the dashboard logs when OpenPLC is running
Quote 1 0
Hi Thiago. So I run simlink.exe on cygwin and I got this error: "Segmentation Fault (core dumped).

simlink.exe.stackdump log:

Exception: STATUS_ACCESS_VIOLATION at rip=001004024D4
rax=0000000000000000 rbx=00000000FFFFCC70 rcx=0000000100408068
rdx=0000000000000000 rsi=000000018027FB40 rdi=00000000FFFFCDF0
r8 =0000000000000000 r9 =0000000000000000 r10=0000000100000000
r11=00000001004024CD r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
rbp=00000000FFFFCC20 rsp=00000000FFFFCBF0
program=C:\Users\justin\OpenPLC\Runtime\home\justin\simlink.exe, pid 1419, thread main
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B
Stack trace:
Frame Function Args
000FFFFCC20 001004024D4 (00000000020, 30001000000FF00, 0018004A7AA, 001800497F0)
000FFFFCCD0 0018004A816 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 00180048353 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 00180048404 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace

Also here is the log of OpenPLC:

OpenPLC Runtime starting...
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Interactive Server: Listening on port 43628
Warning: Persistent Storage file not found
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
Quote 0 0
OK. I figured out that I had to move my interface.cfg to the folder which I created .exe file. Thank you very much for your support.
Quote 0 0