gpt4 book ai didi

python - 树莓派到 AB controllogix : how to trigger output in GPIO based on continuosly reading plc tag value

转载 作者:太空宇宙 更新时间:2023-11-04 04:30:02 26 4
gpt4 key购买 nike

我在 GitHub 上发现了 pylogix,并一直在 AB L71 CPU 上玩读/写标签。我在读/写部分成功了,但我想做的是根据大于 0 的 plc 值触发 GPIO 引脚输出。

我似乎无法弄清楚我需要做什么才能将不断更新的值输入到输出函数中。

import threading
from pylogix.eip import PLC
from gpiozero import LED
from time import sleep

comm = PLC()
comm.IPAddress = '10.201.191.177'

def readdata():
threading.Timer(1.0, readdata).start()
x = comm.Read('parts')
print (x)
readdata()

if x > 0:
relay = LED(2)

最佳答案

很高兴看到我不是这个论坛上唯一对 PLC 感兴趣的人。我可能会为您推荐这个:

编辑: 我阅读了您模块的文档。在下面试试这个新代码可以找到文档 https://gpiozero.readthedocs.io/en/stable/

import threading # I don't think this is necessity for your application
import time
from pylogix.eip import PLC
from gpiozero import LED
from time import sleep

with PLC() as comm #small edit here to control the closing of sockets upon exit
comm.IPAddress = '10.201.191.177'
running=True
relay = LED(2) #I believe the previous version of your code was constantly overwriting your 'relay' variable with a new instance of class LED
while running==True:
x=comm.read('parts')
if x > 0:
relay.on()
else: relay.off()
time.sleep(.5)
#this will run forever updating your LED every 500ms, I would recommend writing code to exit this loop

关于python - 树莓派到 AB controllogix : how to trigger output in GPIO based on continuosly reading plc tag value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com