bnjmnp / pysoem

Cython wrapper for the Simple Open EtherCAT Master Library
MIT License
96 stars 38 forks source link

Slave Setup #6

Closed lemmi25 closed 3 years ago

lemmi25 commented 4 years ago

Hi,

I am new to EtherCat. I got a MXU4300 from Infineon and would like to set up a simple slave master communication. My problem is that I do not understand how to implement the slave in a setup function.

I followed the instruction for the XMC4300 board here.

The mapping for receive and transmit message can be found here.

Screenshot from 2019-11-02 21-21-06

I had a look at the original SOEM as well as the PYSOEM examples (but could not find enough information). Any help on how to setup the setup funtion would be very helpful and mybe a good example for this repo because I think that the XMC4300 is a nice and cheap board.

Many thanks

bnjmnp commented 4 years ago

Hi lemmi25,

I think your example slave implementation uses fixed PDO mapping so you don't need to do anything in the setup function of your device. Thus you don't even need one.

If you only have the XMC board at you master system something like the following should work:

import pysoem

master = pysoem.Master()

master.open('<put in you network id here!>')

master.config_init()

assert len(master.slaves) == 1

assert master.slaves[0].name == 'XMC_ESC'

master.config_map()

assert master.state_check(pysoem.SAFEOP_STATE, 50000) == pysoem.SAFEOP_STATE

for _ in range(1000):
    print(master.slaves[0].input)

master.state = pysoem.INIT_STATE
master.write_state()

master.close()

(Please don't use thees asserts in production code, it's just for the purpose of this demonstration)

You should see some bit changes in the printed input values if you push the button on the XMC board, like described in the Infineon PDF on page 56.

If you got there you may easily figure out how to wire outputs to turn on end off the LED on the board. Therefore take a look at the minimal_example.py or basic_example.py, as my example above dose not show how to bring the slave into operational (OP) state.

lemmi25 commented 4 years ago

Hi,

many thanks for the detailed answer. I still have one problem if I use your example I see nothing as blank lines. Even if I push a button.

If I use the minimal_example.py I can not get the Slave into operation mode (can send code later, maybe your first answer will resolve my problem).

Many thanks again.

bnjmnp commented 4 years ago

Did you find out anything new? Maybe (I was wrong and) the XMC example uses selectable PDO mapping instead of fixed PDO mapping. If so you need to write to object 0x1C12 and 0x1C13 before calling config_map(). How are objects 0x1C12 and 0x1C13 define?

bnjmnp commented 3 years ago

Closed due to inactivity of the original author on this topic.