Open jinyistudio534 opened 7 months ago
But I try this is ok. π π To slave/master are OK πΊπΊπΊ
class EASYCAT32(EBPFTerminal):
compatibility = {(1946, 14614238)}
class Channel(Struct):
byte0 = ProcessDesc(0x0005, 1,'B')
byte1 = ProcessDesc(0x0005, 2,'B')
byte2 = ProcessDesc(0x0005, 3,'B')
byte3 = ProcessDesc(0x0005, 4,'B')
byte4 = ProcessDesc(0x0005, 5,'B')
byte5 = ProcessDesc(0x0005, 6,'B')
byte6 = ProcessDesc(0x0005, 7,'B')
byte7 = ProcessDesc(0x0005, 8,'B')
outputs = Channel(0)
inputs = Channel(1)
master = FastEtherCat("eth0")
await master.connect()
print("Number of terminals:", await master.count())
out1 = EL2088(master)
await out1.initialize(-3,3)
out2 = EL2088(master)
await out2.initialize(-4,4)
easycat = EASYCAT32(master)
await easycat.initialize(-5,5)
do1 = DigitalOutput(out1.channel1) # use channel 1 of terminal "out"
do2 = DigitalOutput(out2.channel3) # use channel 1 of terminal "out"
ob0 = AnalogOutput(easycat.outputs.byte0)
ob1 = AnalogOutput(easycat.outputs.byte3)
ib1 = AnalogInput(easycat.inputs.byte3)
sg = SyncGroup(master, [do1,do2,ob1,ob0,ib1]) # this sync group only contains one terminal
task = sg.start() # start operating the terminals
ox = 0
ix = 0
for i in range(5000):
do1.value = 1 if do1.value==0 else 0
do2.value = 1 if do2.value==0 else 0
ob0.value = random.randint(0, 255)
ob1.value = random.randint(0, 255)
print('ib1: ',ib1.value)
await asyncio.sleep(0.1)
task.cancel() # stop the sync group
Hello, I can only read and write a single byte using the successful method now. Is there a way for me to read 32 bytes of input and write 32 bytes of output in one loop?
The 'B'
in the ProcessDesc
stands for byte. Use a 'I'
and you read or write four bytes. The letters are described here: https://docs.python.org/3/library/struct.html
I refer to ESI/XML to midify old class to as following.
class EASYCAT32(EBPFTerminal): compatibility = {(1946, 14614238)}
input PDO
Sorry, I really donβt know how to use the SyncManager you mentioned? Can you please teach me how to write a program. Let output1 = input2 π΅π΅