tecki / ebpfcat

A Python-base EBPF code generator
GNU General Public License v2.0
17 stars 5 forks source link

How to access the specified slave in a multi slaves bus ? #5

Open jinyistudio534 opened 7 months ago

jinyistudio534 commented 7 months ago

Hi, Sorry to keep bothering you. 😅 I have 4 slaves on the ek1100. They are el1088, el1088, el2088, el2088 in order. with your ethercat.py in the example. i can get 5 slaves. I have two EL1088 and two EL2088 each. How should I write my program code to control them ? 😵 print("Number of terminals:", await master.count()) out = EL4104(master) await out.initialize(-2, 20)

jinyistudio534 commented 7 months ago

I try it, OK 👍

import asyncio from ebpfcat.ebpfcat import FastEtherCat, SyncGroup from ebpfcat.devices import DigitalInput, DigitalOutput from ebpfcat.terminals import EK1100 from ebpfcat.terminals import EL1088 from ebpfcat.terminals import EL2088

async def main(): master = FastEtherCat("eth0") await master.connect() print("Number of terminals:", await master.count()) out1 = EL2088(master) await out1.initialize(-3,19) out2 = EL2088(master) await out2.initialize(-4,20) do1 = DigitalOutput(out1.channel1) # use channel 1 of terminal "out" do2 = DigitalOutput(out2.channel3) # use channel 1 of terminal "out" sg = SyncGroup(master, [do1,do2]) # this sync group only contains one terminal task = sg.start() # start operating the terminals for i in range(100): do1.value = 1 if do1.value==0 else 0 do2.value = 1 if do2.value==0 else 0 await asyncio.sleep(0.5)

task.cancel()  # stop the sync group
asyncio.run(main())