56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
|
|
import threading
|
|
import time
|
|
from device_base import deviceBase
|
|
from pycomm.ab_comm.clx import Driver as plcDriver
|
|
|
|
def write_string(addr, tag, to_send):
|
|
"""
|
|
Writes a given string to the tag in a CLX PLC
|
|
"""
|
|
|
|
data_name = ".".join((tag, "DATA"))
|
|
len_name = ".".join((tag, "LEN"))
|
|
|
|
# Begin by clearing out the entire array
|
|
clear = [0 for _ in range(0, 82)]
|
|
clx = plcDriver()
|
|
if clx.open(addr):
|
|
try:
|
|
clx.write_array(data_name, "SINT", clear)
|
|
clx.write_tag(len_name, 0, "DINT")
|
|
|
|
conv_string = [ord(x) for x in to_send[0:82]]
|
|
clx.write_array(data_name, "SINT", conv_string)
|
|
clx.write_tag(len_name, len(conv_string), "DINT")
|
|
except Exception as e:
|
|
print("Unable to write string {} to {}".format(to_send, tag))
|
|
return False
|
|
clx.close()
|
|
return True
|
|
return False
|
|
|
|
|
|
class start(threading.Thread, deviceBase):
|
|
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
|
threading.Thread.__init__(self)
|
|
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
|
|
|
|
self.daemon = True
|
|
self.version = "2"
|
|
self.finished = threading.Event()
|
|
threading.Thread.start(self)
|
|
|
|
# this is a required function for all drivers, its goal is to upload some piece of data
|
|
# about your device so it can be seen on the web
|
|
def register(self):
|
|
self.channels["status"]["last_value"] = ""
|
|
|
|
def run(self):
|
|
pass
|
|
|
|
def advvfdipp_writenote(self, name, value):
|
|
note_tag_name = "POCloud_note"
|
|
plc_ip = "192.168.1.10"
|
|
return write_string(plc_ip, note_tag_name, value)
|