TCP/IP communication between MATLAB and Siemens PLC 1500

48 views (last 30 days)
Hi All,
I am trying to establish communication between SIemens PLC and Matlab.
I followed a tutorial on youtube at this link: https://www.youtube.com/watch?v=mYXUWUf7LxU
But when I got to the stage at time: 14m:06sec of the video where I need to run the fopen(t) command, the MATLAB was in busy mode forever.....I could not establish communication. I dont know excatly what it wrong.
I could ping from the windows command promt(cmd.exe) the PLC address which is already connected to my computer.
I could also view the PLC from the Web browser and also communcate with it from TIA portal.
I used port 2000 as mentioned in the video yet i could not open the commnection using fopen(t).
Please someone to advise me on what next to do..
Thanks
Abiodun

Accepted Answer

Hassaan
Hassaan on 11 Jan 2024
  1. Check PLC Configuration:
  • Ensure that your PLC is configured to accept external communications on the port you are trying to use (in your case, port 2000).
  • Verify that the PLC's communication settings (like IP address and port) match what you've set in MATLAB.
  1. Firewall Settings:
  • Check your computer’s firewall settings to ensure that MATLAB is allowed to communicate over the network and that the port you are using is not being blocked.
  1. MATLAB Instrument Control Toolbox:
  • Ensure that you have the MATLAB Instrument Control Toolbox installed and properly set up, as this is required for TCP/IP communication.
  1. Network Settings:
  • Confirm that both your computer and the PLC are on the same network and can see each other.
  • Since you mentioned you could ping the PLC, it seems like they are on the same network, but double-check to ensure there are no VLANs or other network settings that might be isolating the devices from each other.
  1. MATLAB TCP/IP Object Settings:
  • Review the properties of your MATLAB TCP/IP object (t in your case) to ensure they match the PLC’s settings. This includes IP address, port, and other relevant parameters.
  1. Try a Different Port:
  • Although the tutorial uses port 2000, it’s possible that this port is not the correct one for your specific PLC model or setup. Refer to your PLC’s documentation to find the correct port.
  1. Test with a Simple TCP/IP Echo Server:
  • As a diagnostic step, try connecting MATLAB to a simple TCP/IP echo server to ensure that MATLAB’s TCP/IP functions are working correctly. There are many free echo server tools available online, or you can write a simple one in a language like Python.
  1. Consult the PLC’s Documentation:
  • Siemens PLCs have extensive documentation. Check to see if there are specific settings or procedures required for establishing a TCP/IP connection.
  1. Check for Error Messages:
  • After the fopen(t) command, check t.Status to see if the connection was successful or not. If it’s not successful, MATLAB might provide an error message that can give you a clue as to what’s going wrong.
  1. Reach Out for Support:
  • If you continue to face issues, consider reaching out to Siemens support or the MATLAB user community for more specific guidance.
  1. Software and Hardware Versions:
  • Ensure that your software (both MATLAB and TIA Portal) and PLC firmware are up to date.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  4 Comments
Abiodun Abiola
Abiodun Abiola on 14 Jan 2024
@Muhammad Hassaan Shah thanks for your explanations as they were very helpful to giude me in understanding what was happening at the background. . Then based on your advice, I also contacted Siemens support and I was able to get additional help.
And now I have been able to exchange data between Siemens s7-1500 and Matlab using TCP/IP....!
The following were the observations on my road to the solution:
  • Your advice on the use of TCP/IP Echo Server helped me to understand the ports that were available on the PC
  • Reading from the MATLAB help document (https://www.mathworks.com/help/instrument/resolve-tcpip-server-connection-errors.html), I used the command: !netstat -a -n -p TCP and I could see the condition of various connections of my PC and assigned ports.
  • From the Siemens PLC support, I found that there are specific ports for the type of communication I needed. So I used the recommended one which was 502 on the PLC
  • I also found out that the antivirus on my PC prevented the connection anytime it is enabled. So once i dis-abled it, I was able to open the port and communicate. I previously saw the same explanation in the video i uploaded but i even when i had disabled the antivirus, the I still could not comunicate until i had enabled the TCON block in Siemens TIA portal. It appears there is a sequence of creating the server object, enabling TCON block and opening the port to establish communication; Whereas in the video, the command fopen(t) was able to open the port without the need for enabling the TCON block. I find this strange for my case but i was able to open the port with my sequence anyway.
  • My firewall did not affect my communiction between S7-1500 and Matlab, as it was well set-up during installation of matlab.
Thanks for your explanation which aided me in getting the solution.
I am glad to be part of the MATAB family
Hassaan
Hassaan on 14 Jan 2024
@Abiodun Abiola Thats great news. You are welcome.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!