Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use PacketDesc() ? #8

Open
jinyistudio534 opened this issue Apr 10, 2024 · 3 comments
Open

How to use PacketDesc() ? #8

jinyistudio534 opened this issue Apr 10, 2024 · 3 comments

Comments

@jinyistudio534
Copy link

jinyistudio534 commented Apr 10, 2024

I refer to ESI/XML to midify old class to as following.

class EASYCAT32(EBPFTerminal):
compatibility = {(1946, 14614238)}
# input PDO
input0 = PacketDesc(1, 0,'B')
input1 = PacketDesc(1, 1,'B')
input2 = PacketDesc(1, 2,'B')
input3 = PacketDesc(1, 3,'B')
input4 = PacketDesc(1, 4,'B')
input5 = PacketDesc(1, 5,'B')
input6 = PacketDesc(1, 6,'B')
input7 = PacketDesc(1, 7,'B')
# output PDO
output0 = PacketDesc(0, 0,'B')
output1 = PacketDesc(0, 1,'B')
output2 = PacketDesc(0, 2,'B')
output3 = PacketDesc(0, 3,'B')
output4 = PacketDesc(0, 4,'B')
output5 = PacketDesc(0, 5,'B')
output6 = PacketDesc(0, 6,'B')
output7 = PacketDesc(0, 7,'B')

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 😵😵

@jinyistudio534
Copy link
Author

jinyistudio534 commented Apr 10, 2024

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):
# we would measure an increasing value on the terminal output
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

@jinyistudio534
Copy link
Author

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?

@tecki
Copy link
Owner

tecki commented Apr 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants