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

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

相关推荐
橙露18 小时前
时间序列分析实战:用 Python 实现股票价格预测与风险评估
人工智能·python·机器学习
神云瑟瑟18 小时前
看langchain理解python中的链式调用
python·langchain·链式调用
栈与堆18 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
CCPC不拿奖不改名18 小时前
循环神经网络RNN:整数索引→稠密向量(嵌入层 / Embedding)详解
人工智能·python·rnn·深度学习·神经网络·自然语言处理·embedding
鹤入云霄18 小时前
基于Python的空气质量监测系统
python
长行20 小时前
Python|Windows 安装 DeepSpeed 安装方法及报错 Unable to pre-compile async_io 处理
windows·python·deepspeed
百锦再20 小时前
python之路并不一马平川:带你踩坑Pandas
开发语言·python·pandas·pip·requests·tools·mircro
Python之栈20 小时前
5款拖拽式Python GUI生成器助你快速打造炫酷界面
python
灏瀚星空20 小时前
基于 Python 与 GitHub,打造个人专属本地化思维导图工具全流程方案(上)
开发语言·人工智能·经验分享·笔记·python·个人开发·visual studio
用什么都重名20 小时前
「实战指南」使用 Python 调用大模型(LLM)
python·大模型·llm·api调用