python实现Ethernet/IP协议的客户端(二)

Ethernet/IP是一种工业自动化领域中常用的网络通信协议,它是基于标准以太网技术的应用层协议。作为工业领域的通信协议之一,Ethernet/IP 提供了一种在工业自动化设备之间实现通信和数据交换的标准化方法。python要实现Ethernet/IP的客户端,可以采用pycomm3模块,但不一定是pycomm3,其中原委咋们慢慢聊,本文为第二篇。

一、模块选型

1、查找模块的方式

(1)可以去python官方网站查询

在查询时注意输入Ethernet/IP时,将/去掉,这跟官网的查询方式有关。

PyPI · The Python Package Index

(2)EthernetIP

GitHub: Let’s build from here · GitHub

(3)搜索引擎

可以通过百度、谷歌等查找模块。

2、备选模块

(1)pycomm3

简单看一下模块的介绍,还是跟PLC相关的,因此这个EIP比较靠谱。

pycomm3 started as a Python 3 fork of pycomm, which is a Python 2 library for communicating with Allen-Bradley PLCs using Ethernet/IP. The initial Python 3 port was done in this fork and was used as the base for pycomm3. Since then, the library has been almost entirely rewritten and the API is no longer compatible with pycomm. Without the hard work done by the original pycomm developers, pycomm3 would not exist. This library seeks to expand upon their great work.

(2)cpppo

也是跟PLC相关的,不过实现的是与Allen-Bradley通信,而且一些实现并不完整。

A subset of the EtherNet/IP client and server protocol is implemented, and a simulation of a subset of the Tag communications capability of a Allen-Bradley ControlLogix 5561 Controller is provided. It is capable of simulating ControlLogix Tag access, via the Read/Write Tag [Fragmented] services.

Only EtherNet/IP “Unconnected” type connections are supported. These are (somewhat anomalously) a persistent TCP/IP connection from a client to a single EtherNet/IP device (such as a *Logix Controller), which allow the client to issue a sequence of CIP service requests (commands) to be sent to arbitrary CIP objects resident on the target device. Cpppo does not implement “Connected” requests (eg. those typically used between *Logix PLCs, in an industrial LAN environment).

A Tag is simply a shortcut to a specific EtherNet/IP CIP Object Instance and Attribute. Instead of the Client needing to know the specific Instance and Attribute numbers, the more easily remembered and meaningful Tag may be supplied in the request path.

(3)其他

还有一些模块跟EtherNet/IP相关,大家可以跟据上述提供的查找方式进行查询,我们先以这两个相对靠谱模块实验一把。

二、实验方式

1、如何实验

(1)先抓一个正常的交互包,作为基准

(2)使用模块安装官方文档进行请求,查看包的情况

(3)根据包的情况与官方文档调整请求参数

(4)一步步实验直到通讯正常

2、已知EDS文件的情报

(1)包含了连接与请求的相关信息

(2)不确定这些信息该在模块中如何使用

三、开始实验

1、使用pycomm3的哪个类?

通过上一篇文章,我们知道pycomm3的三个类情况,而我们的实验对象不是标准的PLC,因此先实验 CIPDriver

from pycomm3 import CIPDriver

print(CIPDriver.discover())

如下图,这个模块是可以查询 EIP的相关设备的,有点靠谱。

而通过以下方法可以获取指定IP的EIP设备信息:

CIPDriver.list_identity('192.168.1.189')

现在我们连接一下EIP设备,看看表现:

from pycomm3 import CIPDriver

CIPDriver("192.168.1.189").open()

如下图,没有报错说明是可连的。

但当进一步想要获取设备的模块信息时,却无法进行:

from pycomm3 import CIPDriver

driver=CIPDriver("192.168.1.189")
driver.open()
driver.get_module_info(0)  # Slot 0: PLC

很显然,报错表明无法获取EIP设备的模块信息,猜测其原因可能是EIP设备没有相关获取信息的服务提供给出来。这个模块看起来可以获取PLC的其他插槽的板卡信息。

我们查看数据包的情况,发现我们的请求时不连接发送,可能这种请求方式不被服务器处理:

经过上述实验,使用CIPDriver类还是比较靠谱的,而其他两个类是针对指定型号的PLC,基于CIPDriver类进行的封装,因此不需要再去尝试其他类。

2、后续实验

经过上述操作,我们简单了解了实验过程,并且确定了使用哪个模块哪个类去做实验,而后续实验将基于这个类慢慢展开。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lion King

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值