Michał Birnbach
Michał Birnbach

Reputation: 1

TwinCat 3 Siemens PLC MODBUS TCP communication

My question is quite simple. Is it possible to communicate TwinCat PLC simulation (TwinCat 3 on normal PC) with real siemens S7-1200 over MODBUS TCP? From what I've gathered, PC without Intel chipset network card prevents you from using protocols like EtherCat or Profibus. Nowhere in documentation is stated that Modbus TCP requires such card.

I've been trying to use Modbus TCP sample program from Beckhoff site for two days now, with no success. TCPView shows that connection between server (PC with TwinCat) and client (S7-1200) is "established" and even some packets are being exchanged. I'm pretty sure that the adressess and lengths and all that stuff are correct, yet TwinCat still gives me ERROR 26. On the Siemens side MB_Client shows 7004 then 7005 and 7006 one after the other with no data coming to my array.

Is there something to do on the TwinCat side other than coping the sample code and changing the parameters, that i need to do? (I also set up the server with TcModbusSrvCfg.exe)

Sorry for the long post. If you have any ideas about what else i can do, plaase share.

Upvotes: 0

Views: 1471

Answers (3)

Bryan Hdez
Bryan Hdez

Reputation: 23

Seems like the problem has to do directly with the configuration of your conection, the hardware itself shouldn't cause any problems with the connection and just like -kolyur said, for test you should deactivate the pc firewall.

As for the modbus server setup, you have to run the "TcModbusSrcCfg.exe"in your computer and set default parameters (to use your computer as server trough port 502), once you make a sucessfull conection with the PLC Siemens at port 502 (default configuration) you can try to modify the program.

The Beckhoff documentation already tells you the libraries, functions and values you should use for a default connection, just make sure you follow the server configuration steps, cause' in the past I had many issues with modbus just for not setting the modbus server right

I used this sample FB for modbus communitation to read from a Modbus Festo Master for IO Modules if you want to compare your variable values.

FB Variables

a_Communication

Upvotes: 0

Lachlan Wright
Lachlan Wright

Reputation: 311

My question is quite simple. Is it possible to communicate TwinCat PLC simulation (TwinCat 3 on normal PC) with real siemens S7-1200 over MODBUS TCP?

In answer to your question. Yes!! Absolutely you can!!

Is there something to do on the TwinCat side other than coping the sample code and changing the parameters, that i need to do? (I also set up the server with TcModbusSrvCfg.exe)

So part of your problem may be in this statement here. Using TcModbusSrvCfg.exe sets up the TwinCat PC Modbus TCP server, but the sample code provided in the manual is the TwinCat program acting as a Modbus TCP client. From your question it isn't 100% clear to me what you are trying to achieve.

The manual in section 2 (page 8 at the time of writing) shows the two different ways it can be setup. In the picture below;

  • the red line with a (1) next to it shows TwinCAT acting as a Modbus TCP Server, and
  • the red line with a (2) next to it shows TwinCAT acting as a Modbus TCP Client.

image from TF6250 manual showing architecture

From your question it sounds like you have setup a Modbus Client on your siemens. If this is the case, you do not need to implement any example code in your TwinCAT program. The example code provided in the manual is for when Twincat is acting a Modbus Client. I think what you are probably looking for is to follow what is in section 4.

From a high level, the TwinCAT Modbus TCP server maps Modbus Registers to TwinCAT Memory areas. You would need to create TwinCAT tags and assign these tags to the appropriate memory areas. You can view the default mapping in section 4.3 or you can use the "Export Configuration" function on the Configuration tool to export an XML file where you can customize your mapping, and then import it again and apply the changes.

I don't know a lot about seimens, but to me it sounds as if your siemens client is actually connecting to the TwinCAT modbus server, however you have not created the relevant TwinCAT tags at the appropriate memory areas/address. If you want the seimens to read data from TwinCAT, then you will need to populate data in tags assigned to the memory areas in TwinCAT. If you want the siemens to write data to TwinCAT, then you will need to add tags in TwinCAT (again at the correct memory area) to view the data.


If however you do want TwinCAT to act as a client connect to a modbus server, you would need to following section 6.

Upvotes: 0

Aporie
Aporie

Reputation: 11

Like Kolyur said, please check that TF6250 is installed on your machine.

As complement of Cliff response here are 3 tools to check your Modbus protocol on both sides : Ananas, Modbus Doctor, Modbus Twin Request

Which Modbus function did you implement you could just try a simple Modbus write register (function 16).

Upvotes: 0

Related Questions