c# - EtherNet/IP(工业协议(protocol)).NET 库

标签 c# io protocols ethernet industrial

我有一个带 8 个模拟输入的 I/O 远程设备 (EIP-2017),它实现 EtherNet/IP 协议(protocol)来读取 I/O 值。我在 codeplex ( https://eipnet.codeplex.com/) 上找到了一个用 .net c# 编写的库,但它没有文档或示例如何使用它。

所以,这是目标(I/O 远程设备)文档:

We suggest users using Implicit Message communicate with EIP-2000. Implicit Messages are applied only for accessing the Input Instance 65 hex (101) and Output Instance 66 (102) of the Assembly Object in the object model. Before using Implicit Messages, you must use the Forward Open service with correct “Instance ID” and “Data length” settings of the Connection Manager Object to build a connection between the EtherNet/IP scanner and the EIP-2000. Afterwards, the Implicit Message can be used. The “Instance ID” of EIP-2000 modules are shown below, but the “Data length” is different from modules.

此设备具有以下功能,
输入 (T->O) 实例 ID:0x65,长度:53 字节 Out (O->T) 实例 ID:0x66,长度:22 字节 配置实例ID:0x64,长度:0字节

然后我写了这些代码行:

static void Main(string[] args)
        {
            byte[] sc = new byte[8] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
            byte[] path = new byte[] { 0x20, 0x04, 0x24, 0x64, 0x2C, 0x66, 0x2C, 0x65 };

            SessionInfo si = SessionManager.CreateAndRegister("192.168.2.227", senderContext: sc);
            si.SetConnectionParameters(101, 3000, 101, 803, 888);

            EIPNET.ConnectionManager.ForwardOpen(si, path);

            bool CIPok = EIPNET.EIP.SessionManager.VerifyCIP(si);

            EIPNET.EIP.EncapsPacket p = new EncapsPacket();
            p.Command = (ushort)EncapsCommand.ListIdentity;
            p.SessionHandle = si.SessionHandle;
            p.SenderContext = sc;
            p.Length = 0;
            //p.EncapsData = new byte[53];
            byte[] rec = si.SendData_WaitReply(p.Pack());
}

我正在注册 session ,然后使用 Forward Open 命令打开连接,然后……什么都没有……

最佳答案

您是否连接到 PLC/CompactLogix 或任何通过以太网/IP 连接的设备? 此外,隐式消息传递 (UDP) 应该只用于关键任务。如果您只是从设备中的数据表中读取寄存器,则应使用显式消息传递 (TCP/IP)。

关于c# - EtherNet/IP(工业协议(protocol)).NET 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35745135/

相关文章:

iphone - 委托(delegate)方法停止被调用(用于工作)

c# - 多线程行为时的 CPU 缓存

python - 为什么在 python 中调用 file.read 会使我的文件充满垃圾?

c# - 切换到其他应用程序时音频不播放

c# - 如何在 C# 中围绕第三方 IO 库编写异步包装器

java - 从同一个文件java读取字符串和字节

ios - 当我创建自己的@protocol 时,有人能解释一下@required 和@optional 概念的作用吗?

ios - 什么是通过 Enum 进行可重用 UIAlertController 配置的 Swift 最佳实践

c# - 返回字符串之间第一个差异的索引

c# - C# 文档工具,不仅可以从源代码生成文档