import subprocess,sys,ctypes
from threading import Thread
SDOAnswered = PLCBinary.SDOAnswered
SDOAnswered.restype = None
SDOAnswered.argtypes = []
def SDOThreadProc(*params):
if params[0] == "upload":
command = "ethercat upload -p %d -t %s 0x%.4x 0x%.2x"
command = "ethercat download -p %d -t %s 0x%.4x 0x%.2x %s"
proc = subprocess.Popen(command % params[1:], stdout=subprocess.PIPE, shell=True)
output = proc.communicate()[0]
if params[0] == "upload":
if params[2] in ["float", "double"]:
elif params[2] in ["string", "octet_string", "unicode_string"]:
hex_value, dec_value = output.split()
if int(hex_value, 16) == int(dec_value):
def EthercatSDOUpload(pos, index, subindex, var_type):
SDOThread = Thread(target=SDOThreadProc, args=["upload", pos, var_type, index, subindex])
def EthercatSDODownload(pos, index, subindex, var_type, value):
SDOThread = Thread(target=SDOThreadProc, args=["download", pos, var_type, index, subindex, value])