Master

class pysoem.Master

Representing a logical EtherCAT master device.

For each network interface you can have a Master instance.

slaves

Gets a list of the slaves found during config_init. The slave instances are of type CdefSlave.

sdo_read_timeout

timeout for SDO read access for all slaves connected

sdo_write_timeout

timeout for SDO write access for all slaves connected

always_release_gil

true to always release the GIL

check_release_gil(release_gil)

Checks if the GIL should be released.

Parameters:

release_gil (boolean) – True if the GIL should be released, False otherwise.

close()

Close the network interface.

Signals that no new operations should start and waits for any in-flight operations to complete before closing. Uses a timeout of 5 seconds; logs a warning if timeout occurs.

config_dc()

Locate DC slaves, measure propagation delays.

Returns:

if slaves are found with DC

Return type:

bool

config_init(usetable=False, *, release_gil=None)

Enumerate and init all slaves.

Parameters:
  • usetable (bool) – True when using configtable to init slaves, False otherwise.

  • release_gil (bool, optional) – True to initialize the slaves releasing the GIL. Defaults to False.

Returns:

Working counter of slave discover datagram = number of slaves found, -1 when no slave is connected

Return type:

int

config_map()

Map all slaves PDOs in IO map.

Returns:

IO map size (sum of all PDO in an out data)

Return type:

int

config_overlap_map()

Map all slaves PDOs to overlapping IO map.

Returns:

IO map size (sum of all PDO in an out data)

Return type:

int

property dc_time

DC time in ns required to synchronize the EtherCAT cycle with SYNC0 cycles.

Note EtherCAT cycle here means the call of send_processdata and receive_processdata.

property expected_wkc

Calculates the expected Working Counter

open(ifname, ifname_red=None)

Initialize and open network interface.

On Linux the name of the interface is the same as usd by the system, e.g. eth0, and as displayed by ip addr.

On Windows the names of the interfaces look like \Device\NPF_{1D123456-1E12-1C12-12F1-1234E123453B}. Finding the kind of name that SOEM expects is not straightforward. The most practical way is to use the find_adapters() method to find your available interfaces.

Parameters:
  • ifname (str) – Interface name.

  • ifname_red (str, optional) – Interface name of the second network interface card for redundancy. Put to None if not used.

Raises:

ConnectionError – When the specified interface dose not exist or you have no permission to open the interface

read_state()

Read all slaves states.

Returns:

lowest state found

Return type:

int

receive_processdata(timeout=2000, *, release_gil=None)

Receive processdata from slaves.

Second part from send_processdata(). Received datagrams are recombined with the processdata with help from the stack. If a datagram contains input processdata it copies it to the processdata structure.

Parameters:
  • timeout (int) – Timeout in us.

  • release_gil (bool, optional) – True to receive processdata releasing the GIL. Defaults to False.

Returns

int: Working Counter

send_overlap_processdata(*, release_gil=None)

Transmit overlap processdata to slaves.

Returns:

>0 if processdata is transmitted, might only by 0 if config map is not configured properly

Return type:

int

send_processdata(*, release_gil=None)

Transmit processdata to slaves.

Uses LRW, or LRD/LWR if LRW is not allowed (blockLRW). Both the input and output processdata are transmitted. The outputs with the actual data, the inputs have a placeholder. The inputs are gathered with the receive processdata function. In contrast to the base LRW function this function is non-blocking. If the processdata does not fit in one datagram, multiple are used. In order to recombine the slave response, a stack is used.

Parameters:

release_gil (bool, optional) – True to transmit processdata releasing the GIL. Defaults to False.

Returns:

>0 if processdata is transmitted, might only by 0 if config map is not configured properly

Return type:

int

property state

Can be used to check if all slaves are in Operational state, or to request a new state for all slaves.

Make sure to call write_state(), once a new state for all slaves was set.

state_check(expected_state, timeout=50000)

Check actual slave state.

This is a blocking function. To refresh the state of all slaves read_state() should be called

Parameters:
  • expected_state (int) – Requested state

  • timeout (int) – Timeout value in us

Returns:

Requested state, or found state after timeout

Return type:

int

write_state()

Write all slaves state.

The function does not check if the actual state is changed.

Returns:

Working counter or EC_NOFRAME

Return type:

int