我最近买了一台ACS线性执行器(Tolomatic ),我正尝试从Python应用程序向其发送数据。设备本身使用以太网/IP协议进行通信。
我已经通过pip安装了cpppo库。当我发出一个命令试图读取设备的状态时,我得到的结果是None。检查与Wireshark的通信,我看到它似乎正在正常进行,但我注意到来自设备的响应指示:服务不受支持。
我用来测试读取"Input Assembly“的代码示例:
from cpppo.server.enip import client
HOST = "192.168.1.100"
TAGS = ["@4/100/3"]
with client.connector(host=HOST) as conn:
for index, descr, op, reply, status, value in conn.synchronous(
operations=client.parse_operations(TAGS)):
print(": %20s: %s" % (descr, value))
我希望得到一个“输入程序集”读取,但它似乎不是这样工作的。我想我错过了一些东西,因为这是我第一次尝试以太网/IP通信。
我不确定如何继续,也不确定以太网/IP的哪些方面可能会使其正常工作。
发布于 2016-01-30 07:52:35
clutton --我是cpppo模块的作者。
对于延迟的响应,我很抱歉。我们最近才实现了与简单(非路由) CIP设备通信的能力。ControlLogix/CompactLogix控制器实现了一组扩展的以太网/IP CIP功能,这是大多数简单CIP设备所不具备的。此外,它们通常也不实现*Logix "Read Tag“请求;您必须努力处理基本的"Get Attribute Single/All”请求--这些请求只返回原始的8位数据。这取决于您是否将其转换回CIP REAL、INT、DINT等。
为了与您的线性执行器通信,您需要禁用这些增强的封装,并使用"Get Attribute Single“请求。这是通过在解析操作时指定一个空的route_path=[]和send_path='‘来完成的,并使用cpppo.server.enip.getattr的attribute_operations (而不是cpppo.server.enip.client的parse_operations):
from cpppo.server.enip import client
from cpppo.server.enip.getattr import attribute_operations
HOST = "192.168.1.100"
TAGS = ["@4/100/3"]
with client.connector(host=HOST) as conn:
for index, descr, op, reply, status, value in conn.synchronous(
operations=attribute_operations(
TAGS, route_path=[], send_path='' )):
print(": %20s: %s" % (descr, value))
这应该能起到作用!
我们正在推出cpppo模块的重大更新,所以克隆https://github.com/pjkundert/cpppo.git Git repo,并检查feature-list-identity分支,以便及早访问更好的API,以便从这些简单的设备访问原始数据,以便进行测试。您将能够使用cpppo将原始数据转换为CIP REALs,而不必自己执行此操作……
..。
使用Cpppo >= 3.9.0,您现在可以使用更强大的cpppo.server.enip.get_attribute 'proxy‘和'proxy_simple’接口来路由CIP设备(例如,ControlLogix )和非路由“简单”CIP设备(例如,MicroLogix、PowerFlex等):
$ python
>>> from cpppo.server.enip.get_attribute import proxy_simple
>>> product_name, = proxy_simple( '10.0.1.2' ).read( [('@1/1/7','SSTRING')] )
>>> product_name
[u'1756-L61/C LOGIX5561']
如果您想要定期更新,请使用cpppo.server.enip.poll:
import logging
import sys
import time
import threading
from cpppo.server.enip import poll
from cpppo.server.enip.get_attribute import proxy_simple as device
params = [('@1/1/1','INT'),('@1/1/7','SSTRING')]
# If you have an A-B PowerFlex, try:
# from cpppo.server.enip.ab import powerflex_750_series as device
# parms = [ "Motor Velocity", "Output Current" ]
hostname = '10.0.1.2'
values = {} # { <parameter>: <value>, ... }
poller = threading.Thread(
target=poll.poll, args=(device,), kwargs={
'address': (hostname, 44818),
'cycle': 1.0,
'timeout': 0.5,
'process': lambda par,val: values.update( { par: val } ),
'params': params,
})
poller.daemon = True
poller.start()
# Monitor the values dict (updated in another Thread)
while True:
while values:
logging.warning( "%16s == %r", *values.popitem() )
time.sleep( .1 )
还有,瞧!现在,您可以定期更新“values”字典中的参数名称和值。请参考cpppo/server/enip/poll_example*.py中的示例,了解更多详细信息,例如如何上报故障、如何控制连接重试的指数回退等。
3.9.5版本最近发布了,它支持使用cpppo.server.enip.get_attribute代理和proxy_simple API写入CIP标记和属性。请参阅cpppo/server/enip/poll_example_many_with_write.py
发布于 2015-07-17 02:19:17
希望这是显而易见的,但是只有位于子网192.168.1上的系统才能访问HOST = "192.168.1.100“。*
https://stackoverflow.com/questions/31461069
复制相似问题