TwinCat 3 西门子 PLC MODBUS TCP 通讯

发布于 2025-01-16 11:20:35 字数 509 浏览 3 评论 0原文

我的问题很简单。是否可以通过 MODBUS TCP 与真实的西门子 S7-1200 进行 TwinCat PLC 仿真(普通 PC 上的 TwinCat 3)通信? 据我所知,没有 Intel 芯片组网卡的 PC 会阻止您使用 EtherCat 或 Profibus 等协议。文档中没有任何地方说明 Modbus TCP 需要此类卡。

我已经尝试使用 Beckhoff 网站上的 Modbus TCP 示例程序两天了,但没有成功。 TCPView 显示服务器(带有 TwinCat 的 PC)和客户端 (S7-1200) 之间的连接已“建立”,甚至正在交换一些数据包。我非常确定地址、长度以及所有这些内容都是正确的,但 TwinCat 仍然给我错误 26。 在西门子方面,MB_Client 依次显示 7004、7005 和 7006,没有数据进入我的阵列。

除了处理示例代码和更改参数之外,我需要在 TwinCat 方面做些什么吗? (我还使用 TcModbusSrvCfg.exe 设置了服务器)

很抱歉这篇文章很长。如果您对我还能做什么有任何想法,请分享。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生死何惧 2025-01-23 11:20:35

就像 Kolyur 所说,请检查您的计算机上是否安装了 TF6250。

作为 Cliff 响应的补充,这里有 3 个工具来检查双方的 Modbus 协议:
凤梨,
Modbus 医生,
Modbus 双请求

您实现了哪个 Modbus 功能,您可以尝试一个简单的 Modbus 写入寄存器(功能 16)。

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).

等往事风中吹 2025-01-23 11:20:35

我的问题很简单。是否可以与TwinCat PLC进行通信
使用真正的西门子 S7-1200 进行模拟(普通 PC 上的 TwinCat 3)
MODBUS TCP?

回答你的问题。是的!!绝对可以!!

除了应对问题之外,TwinCat 方面还有什么可做的吗?
示例代码并更改参数,我需要做什么? (我也
使用 TcModbusSrvCfg.exe 设置服务器)

因此您的部分问题可能出在此处的此语句中。使用 TcModbusSrvCfg.exe 设置 TwinCat PC Modbus TCP 服务器,但手册中提供的示例代码是充当 Modbus TCP 客户端的 TwinCat 程序。从你的问题来看,我并不清楚你想要实现什么目标。

手册第 2 部分(当时的第 8 页)写作)显示了两种不同的设置方式。如下图中;

  • 旁边带有 (1) 的红线表示 TwinCAT 用作 Modbus TCP 服务器,
  • 旁边带有 (2) 的红线表示 TwinCAT 用作 Modbus TCP 客户端。

图片来自TF6250 手册显示架构

从您的问题来看,您似乎已经在西门子设备上设置了 Modbus 客户端。如果是这种情况,您不需要在 TwinCAT 程序中实现任何示例代码。手册中提供的示例代码适用于 Twincat 充当 Modbus 客户端时的情况。我认为您可能需要遵循第 4 节中的内容

。从较高的层次来看,TwinCAT Modbus TCP 服务器将 Modbus 寄存器映射到 TwinCAT 内存区域。您需要创建 TwinCAT 变量并将这些变量分配到适当的存储区域。您可以在第 4.3 节中查看默认映射,也可以使用配置工具上的“导出配置”功能导出 XML 文件,您可以在其中自定义映射,然后再次导入并应用更改。

我对西门子了解不多,但对我来说,听起来好像你的西门子客户端实际上正在连接到 TwinCAT modbus 服务器,但是你还没有在适当的内存区域/地址创建相关的 TwinCAT 标签。如果您希望西门子从 TwinCAT 读取数据,则需要将数据填充到分配给 TwinCAT 内存区域的标签中。如果您希望西门子将数据写入 TwinCAT,则需要在 TwinCAT 中添加标签(同样在正确的内存区域)才能查看数据。


然而,如果您确实希望 TwinCAT 充当连接到 modbus 服务器的客户端,则需要遵循第 6 节。

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.

债姬 2025-01-23 11:20:35

似乎问题与您的连接配置直接相关,硬件本身不应该导致任何连接问题,就像 -kolyur 所说,为了测试,您应该停用电脑防火墙。

至于modbus服务器设置,一旦您与西门子PLC的502端口(端口)成功连接,您必须在计算机中运行“TcModbusSrcCfg.exe”并设置默认参数(通过端口502使用您的计算机作为服务器)。默认配置)您可以尝试修改程序。

Beckhoff 文档已经告诉您应该用于默认连接的库、函数和值,只需确保遵循服务器配置步骤即可,因为过去我在使用 modbus 时遇到了很多问题,只是因为没有正确设置 modbus

服务器如果您想比较变量值,请使用此用于 modbus 通信的示例 FB 从 Modbus Festo Master for IO 模块读取。

FB 变量

a_Communication

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文