rmshahid
Hi,
My aim is to communicate OpenPLC with Simulink Model (Matlab2015a) , I have gone through this too
https://github.com/thiagoralves/OpenPLC_Simulink-Interface 
But I am unable to get any communication. What I am doing is:
I am running this example on Raspberry Pi 
Example : https://www.openplcproject.com/reference-your-first-project
The hardware works fine. Now I want to control the LED attached to %QX0.0 using UDP send block in simulink. 
Also I have SimLink running on windows using Cygwin environment and I edited configure.cfg file as said in this post: https://openplc.discussion.community/post/how-do-i-connect-openplc-with-matlab-simulink-8434575
But still not getting any data in simulink.
Following is the procedure I am following:
1. Building a New Program in OpenPLC editor 
2. Uploading .st file from step 1 to Pi OpenPLC and Starting PLC
3. Running of Simulink Model with setting as said in above post mentioned 
4. Running SimLink in Cygwin environemen

Additionally in a post I read OpenPLC should run with Simulink selected in hardware tab of ip:8080 PLC server page.  I also tried this but in this case the program does not even compile and results in compilation with errors. The compile window contents are attached below: 
error_log.png 

Thanks for your help.
Regards,
rmshahid
Quote 0 0
thiagoralves
You need to select the simulink hardware layer for windows (without dnp3) if you’re running OpenPLC on Windows. Without the hardware layer enabled there won’t be any communication
Quote 0 0
rmshahid
Thanks for your reply, I understand what I need to do now. I was trying to control the actual Hello World LED hardware setup wired to my Raspberry Pi through simulink. 

EDIT:  Is it possible to communicate OpenPLC data running on RaspberryPi to simulink?

Let me ask another question please. Is it possible to program a PID in openPLC running on Pi in a closed loop manner. What I want to do is program any PID in OpenPLC that will run on Raspberry Pi 3. Input to PID is analog for that I will use %IW0.0 and output is also an analog value %QW0.0. What I need is to communicate this data (output) to my application and make decision based on value further change input to the PID. 

Thanks! Looking for a solution.
Quote 0 0
rmshahid
I installed OpenPLC runtime on windows using the installer for the purpose to test the communication between openPLC and Simulink. Here is what I am doing:
I am running OpenPLC runtime on windows this time , last time it was running on Raspberry Pi.
In OpenPLC webserver in hardware menu I selected Simulink from dropdown menu.
I uploaded an simple .st file but it failed to compile here is the screen snip of compile window.
05042020.png 
I tested this program on OpenPLC running on Raspberry Pi with Raspberry Pi selected as hardware and it ran perfectly.
Couldn't figure out what I am doing wrong for Simulink hardware.
The program is as follows:


05042020_1.png 
Thanks for your help.

Quote 0 0
thiagoralves
This program won't run anywhere as it has errors. There is no %QW0.0. It should be just %QW0. Also, %QW is a word location (hence the 'W'). The variable cannot be a BOOL, it needs to be either WORD, UINT or INT. That's why it is complaining about "bit size of data type is incompatible with bit size of location".

About Simulink communication, if you're running on Windows or Raspberry Pi, you need to select the Simulink driver for it to communicate with the SimLink software. On Windows, you need to select the plain Simulink driver (without DNP3). For Raspberry Pi you need to select the Simulink with DNP3 (Linux only) as Raspberry Pi runs on a Linux OS. Keep in mind that if you select the Simulink driver, OpenPLC won't be able to control the Raspberry Pi GPIO pins.
Quote 1 0
rmshahid
Thanks for your reply. Now I know what I was doing wrong. Props for your help. I will get back to you once I achieve my goal.


Thank you so much.
Quote 0 0
rmshahid
Hello! I am able to transmit data using simlink, from Simulink to OpenPLC station. But data from OpenPLC station to Simulink is not arriving. I am using the following LD program to test communication between OpenPLC and Simulink using simlink application.
05072020_1.png 
Following are the configure.cfg file and Simulink Model details. In the Cygwin window I modified the main while loop to print the values in station structure analog in and out variables (stations_data[0].analogIn[0] and  stations_data[0].analogOut[0])
05072020_2.png 



Quote 0 0
thiagoralves
Perhaps it would be easier if you just start with the example in the Simlink repository: https://github.com/thiagoralves/OpenPLC_Simulink-Interface/blob/master/Example/readme.md
Quote 0 0
rmshahid
Yes I am following the same example but in simulink I am not getting any data from plc. I changed the simlink main while 1 loop for debugging to print plc in and out values and they appear to change as intended. The lamp status does change when I see the monitoring window on server when I change the switch to 1, but the lamp status in simulink does not change accordingly and  remains 0 and does not appear to receive data/update from plc.

Thanks for your help.

Regards,
rmshahid
Quote 0 0
thiagoralves
You can try a couple things... first try temporarily disabling antivirus/firewall as those can be in the way of the communication. If that doesn't work, try just restarting simlink while everything else is running (Simulink and OpenPLC keep running). Sometimes you just need to refresh the comm pipes, and restarting simlink will do it. Third, go to monitoring tab on OpenPLC and make sure it is reading the status from Simulink and it is outputting the correct value as well.
Quote 0 0
rmshahid
Hi,
I disabled my network firewall and antivirus program. And restarted several times the simlink application keeping the Simulink model and OpenPLC running but still could not get any data update in Simulink. Also in the monitoring tab on OpenPLC the input and output data do change, the only thing is that i am not getting any update about the output on OpenPLC i.e no UDP receive block update.
Also following is the message that I get while running simlink application.
05082020_1.png 

Also I monitored the network traffic using wireshark application. I only see UDP packets for port 10001 and there is no packet on port 10002.
05082020_3.png 
In addition to above I observed a weird thing in Hello World Example, I modified the while 1 main function loop in simlink to observe the digital in and out values and observed that digial in is not the same as I sent using the Simulink UDP send block.
05082020_4.png 

I am sending a 1 while it shows 97, also the monitoring tab for the Hello World example is as follows:
05082020_5.png  Keen to resolve my problem with this.


Thanks in advance for your help.

Best Regards,
rmshahid

 
Quote 0 0
thiagoralves
It is hard to debug your problem remotely. I would start by just downloading a fresh version of simlink from github with no modifications at all and see if it works. I saw that you modified simlink to display your variables. Even though this should not affect the communication, we as human beings make mistakes all the time. It could be possible that you accidentally modified something on simlink that made it stop working. Use the example provided in the repository for both Simulink and OpenPLC, and check if that works. Once you have the basic example setup and working, you can start playing with your own variables.
Quote 0 0
rmshahid
Hi,
Thank you so much. I get it to work by installing newer version of Matlab and UDP receive does work now. Previously I was running the Simulink model on Matlab 2015a. 
Thank you so much for you kind help.

Best Regards,
rmshahid
Quote 0 0