CdefSlave

class pysoem.CdefSlave

Represents a slave device

Do not use this class in application code. Instances are created by a Master instance on a successful config_init(). They then can be obtained by slaves list

add_emergency_callback(callback)

Get notified on EMCY messages from this slave.

Parameters:

callback – Callable which must take one argument of an Emergency instance.

amend_mbx(mailbox, start_address, size)

Change the start address and size of a mailbox.

Note that the slave must me in INIT state to do that.

Parameters:
  • mailbox (str) – Ether ‘out’, or ‘in’ to specify which mailbox to update.

  • start_address (int) – New start address for the mailbox.

  • size (int) – New size of the mailbox.

Added in version 1.0.6.

property config_func

Slaves callback function that is called during config_map.

When the state changes from Pre-Operational state to Operational state.

dc_sync(act, sync0_cycle_time, sync0_shift_time=0, sync1_cycle_time=None)

Activate or deactivate SYNC pulses at the slave.

Parameters:
  • act (bool) – True = active, False = deactivate

  • sync0_cycle_time (int) – Cycltime SYNC0 in ns

  • sync0_shift_time (int) – Optional SYNC0 shift time in ns

  • sync1_cycle_time (int) – Optional cycltime for SYNC1 in ns. This time is a delta time in relation to SYNC0. If CylcTime1 = 0 then SYNC1 fires at the same time as SYNC0.

eeprom_read(word_address, timeout=20000)

Read 4 byte from EEPROM

Default timeout: 20000 us

Parameters:
  • word_address (int) – EEPROM address to read from

  • timeout (int, optional) – Timeout value in us

Returns:

EEPROM data

Return type:

bytes

eeprom_write(word_address, data, timeout=20000)

Write 2 byte (1 word) to EEPROM

Default timeout: 20000 us

Parameters:
  • word_address (int) – EEPROM address to write to

  • data (bytes) – data (only 2 bytes are allowed)

  • timeout (int, optional) – Timeout value in us

Raises:
foe_read(filename, password, size, timeout=200000, *, release_gil=None)

Read given filename from device using FoE

Parameters:
  • filename (string) – name of the target file

  • password (int) – password for target file

  • size (int) – maximum file size

  • timeout (int) – Timeout value in us

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

foe_write(filename, password, data, timeout=200000, *, release_gil=None)

Write given data to device using FoE

Parameters:
  • filename (string) – name of the target file

  • password (int) – password for the target file, accepted range: 0 to 2^32 - 1

  • data (bytes) – data

  • timeout (int) – Timeout value in us

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

get_max_watchdog_time()

Get the maximum watchdog timeout.

Returns:

The maximum watchdog timeout in ms.

Return type:

float

get_watchdog(wd_type)

Get the watchdog time of the PDI or Process Data watchdog.

Parameters:

wd_type (str) – Either ‘pdi’, or ‘processdata’ to specify the watchdog time to be read.

Returns:

The watchdog time in ms.

Return type:

float

property id

Product Code of the slave, read out from the slaves SII during config_init.

property man

Vendor ID of the slave, read out from the slaves SII during config_init.

mbx_receive()

Read out the slaves out mailbox - to check for emergency messages.

Added in version 1.0.4.

Returns:

Work counter

Return type:

int

Raises:

Emergency – if an emergency message was received

property name

Name of the slave, read out from the slaves SII during config_init.

reconfig(timeout=500)

Reconfigure slave.

Parameters:

timeout – local timeout

Returns:

Slave state

Return type:

int

recover(timeout=500)

Recover slave.

Parameters:

timeout – local timeout

Returns:

>0 if successful

Return type:

int

property rev

Revision Number of the slave, read out from the slaves SII during config_init.

sdo_read(index, subindex, size=0, ca=False, *, release_gil=None)

Read a CoE object.

When leaving out the size parameter, objects up to 256 bytes can be read. If the size of the object is expected to be bigger, increase the size parameter.

Parameters:
  • index (int) – Index of the object.

  • subindex (int) – Subindex of the object.

  • size (int, optional) – The size of the reading buffer.

  • ca (bool, optional) – complete access.

  • release_gil (bool, optional) – True to read a CoE object releasing the GIL. Defaults to False.

Returns:

The content of the sdo object.

Return type:

bytes

Raises:
  • SdoError – if write fails, the exception includes the SDO abort code

  • MailboxError – on errors in the mailbox protocol

  • PacketError – on packet level error

  • WkcError – if working counter is not higher than 0, the exception includes the working counter

sdo_write(index, subindex, data, ca=False, *, release_gil=None)

Write to a CoE object.

Parameters:
  • index (int) – Index of the object.

  • subindex (int) – Subindex of the object.

  • data (bytes) – data to be written to the object.

  • ca (bool, optional) – complete access.

  • release_gil (bool, optional) – True to write to a CoE object releasing the GIL. Defaults to False.

Raises:
  • SdoError – if write fails, the exception includes the SDO abort code

  • MailboxError – on errors in the mailbox protocol

  • PacketError – on packet level error

  • WkcError – if working counter is not higher than 0, the exception includes the working counter

set_watchdog(wd_type, wd_time_ms)

Change the watchdog time of the PDI or Process Data watchdog.

Warning

This is experimental.

Parameters:
  • wd_type (str) – Ether ‘pdi’, or ‘processdata’ to specify the watchdog time to be updated.

  • wd_time_ms (float) – Watchdog time in ms.

At the default watchdog time divider the precision is 0.1 ms.

Added in version 1.0.6.

property setup_func

Alternative callback function that is called during config_map.

More precisely the function is called during the transition from Pre-Operational to Safe-Operational state. Use this instead of the config_func. The difference is that the callbacks signature is fn(CdefSlave: slave).

Added in version 1.1.0.

property state

Request a new state.

After a new state has been set, write_state must be called.

state_check(expected_state, timeout=2000)

Wait for the slave to reach the state that was requested.

write_state()

Write slave state.

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