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、后续实验

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

相关推荐
leisoo80976 小时前
100GBA股股票数据怎么存ClickHouseRedisMySQLJSON完整对比
大数据·linux·服务器·开发语言·python
WangYan20226 小时前
基于XGBoost与AI的生态—地学多源数据建模:植被与土地利用识别、土壤碳氮空间预测、生物多样性驱动机制、土壤微生物功能预测、生态退化与风险识别
python·机器学习·xgboost
金銀銅鐵8 小时前
[Python] 借助 turtle 逐字展示唐诗《金缕衣》
python
Python大数据分析@10 小时前
使用大模型MCP采集数据,爬虫已经无门槛
python·网络爬虫
quantdash_cc10 小时前
告别自建 Requests/BS4 网页爬虫:基于 QuantDash 搭建零维保的高性能量化行情流水线
开发语言·爬虫·python·pandas·量化·quantdash
65岁退休Coder11 小时前
LangChain v1.3.4 笔记 - 07 补充:链式调用 LCEL
后端·python·langchain
卷无止境11 小时前
FastAPI 部署在 Nginx 后面到底该怎么配
后端·python
半亩码田11 小时前
C#转Python第3.1篇:Python 的 class 没有访问修饰符?面向对象的另一条路
开发语言·python·c#
Wzx19801212 小时前
python沙箱和docker沙箱你选对了吗?
开发语言·python·docker
Python私教12 小时前
签名 URL 刷新导致审批失效?别急着删掉所有 query
python·安全