首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用Pyads库时等待变量更改?

如何在使用Pyads库时等待变量更改?
EN

Stack Overflow用户
提问于 2020-11-15 17:14:05
回答 1查看 500关注 0票数 1

我正在与TwinCatAMR一起做一个项目。我使用Python作为两个系统之间的通信媒介。我在等待变量更改值时遇到了问题。我有一个类型为BOOL的变量,希望在变量更改时执行特定的操作。有人能帮我吗?

P.S.我也通知了变量的变化。

代码语言:javascript
复制
import pyads

PLC = pyads.Connection('127.0.0.1.1.1', pyads.PORT_SPS1)
PLC.open()

StnF = PLC.read_by_name('GVL.AGVgotoStnF', pyads.PLCTYPE_BOOL)
print(StnF)

if StnF == 'TRUE' :
    ArrStnF = PLC.write_by_name('GVL.iPosAGV',3,pyads.PLCTYPE_INT)
    print(ArrStnF)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-16 17:05:26

你在找通知。pyads的文档给出和示例如何做到这一点:

代码语言:javascript
复制
import pyads
from ctypes import sizeof

# define the callback which extracts the value of the variable
def callback(notification, data):
    contents = notification.contents
    var = next(map(int, bytearray(contents.data)[0:contents.cbSampleSize]))

plc = pyads.Connection('127.0.0.1.1.1', pyads.PORT_SPS1)
plc.open()
attr = pyads.NotificationAttrib(sizeof(pyads.PLCTYPE_INT))

# add_device_notification returns a tuple of notification_handle and
# user_handle which we just store in handles
handles = plc.add_device_notification('GVL.integer_value', attr, callback)

# To remove the device notification just use the del_device_notication
# function.
plc.del_device_notification(*handles)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64847399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档