kvskrishna
Hi, 

Im currently working on a project where I need to connect the Open Plc to Matlab Simulink. Can you tell me if that can be possible or not? If so, How do I establish a connection. Data can be sent using the either TCP or UPD packets
Quote 0 0
thiagoralves
It is possible, but is not very straightforward. You can attach virtual sensors and actuators as UDP Blocks in the Simulink model. These blocks should be constantly sending data through some IP ports, and constantly listening for data at some other IP ports. You will have to use another program to communicate with the Simulink model over these IP ports, that is available here:  https://github.com/thiagoralves/OpenPLC_Simulink-Interface . The Simulink Interface program listens to the data coming from each virtual sensor, create an input packet with all this information and send it to OpenPLC through the Simulink I/O driver. Then, it must get the output packet with all output information from the OpenPLC and respond back with control data to each virtual actuator on the Simulink model. This way, the Simulink Interface program makes a bridge between OpenPLC and the virtual sensors and actuators in your model.

The Simulink Interface program relies on a configuration script to know some information about the virtual OpenPLC stations (it can talk to more than 1 OpenPLC instance) and the virtual sensors and actuators. The following example shows the configuration script for two OpenPLC stations, each one having one analog input and two digital outputs:

num_stations = "2"
simulink.ip = "192.168.171.1"

#Configuration for the first station
station0.ip = "192.168.171.101"
station0.add(analog_in) = "10001"
station0.add(digital_out) = "10002"
station0.add(digital_out) = "10003"

#Configuration for the second station
station1.ip = "192.168.171.102"
station1.add(analog_in) = "10004"
station1.add(digital_out) = "10005"
station1.add(digital_out) = "10006"

As it can be seen from the example above, the script defines the number of OpenPLC stations, the ip address for each station, including the machine running the Simulink model, and the sensors and actuators that should be connected to each OpenPLC station. The sensors are inputs to the OpenPLC, and they can be either digital or analog. On the other hand, the actuators are outputs from the OpenPLC, and can be as well either digital or analog. The number inside quotes after the sensor or actuator declaration denotes the IP port to which the device is connected to in the Simulink model.

The input and output ports added by this script are connected directly to the OpenPLC I/O buffers via the Simulink I/O driver. Therefore, at the end of the OpenPLC software installation, you will have to choose the Simulink driver for it to work. The Simulink driver adds inputs and outputs in the order they appear in the script, which means that, for instance, the first digital_out declaration will be connected to the first digital output of the OpenPLC, the second digital_out to the second digital output, and so on.
Quote 0 0
sachinsm
Hello,
Can you please provide instructions on how to use the files in   https://github.com/thiagoralves/OpenPLC_Simulink-Interface 
and If you also have a  example project on this topic can you please provide some details/content?
Thankyou
Quote 0 0
thiagoralves
https://github.com/thiagoralves/OpenPLC_Simulink-Interface/tree/master/Example
Quote 0 0