Network

class ingenialink.ethernet.network.EthernetNetwork(subnet: str | None = None)[source]

Network for all Ethernet communications.

Parameters:

subnet – The subnet in CIDR notation.

static close_socket(sock: socket) None[source]

Closes the established network socket.

connect_to_slave(target: str, dictionary: str, port: int = 1061, connection_timeout: float = 1, servo_status_listener: bool = False, net_status_listener: bool = False, is_eoe: bool = False) EthernetServo[source]

Connects to a slave through the given network settings.

Parameters:
  • target – IP of the target slave.

  • dictionary – Path to the target dictionary file.

  • port – Port to connect to the slave.

  • connection_timeout – Time in seconds of the connection timeout.

  • servo_status_listener – Toggle the listener of the servo for its status, errors, faults, etc.

  • net_status_listener – Toggle the listener of the network status, connection and disconnection.

  • is_eoe – True if communication is EoE. False by default.

Raises:

ILError – If the drive is not found.

Returns:

Instance of the servo connected.

Return type:

EthernetServo

disconnect_from_slave(servo: EthernetServo) None[source]

Disconnects the slave from the network.

Parameters:

servo – Instance of the servo connected.

get_servo_state(servo_id: int | str) NetState[source]

Get the state of a servo that’s a part of network.

The state indicates if the servo is connected or disconnected.

Parameters:

servo_id – The servo’s IP address.

Raises:

ValueError – if the servo ID is not a string.

Returns:

The servo’s state.

static load_firmware(fw_file: str, target: str = '192.168.2.22', ftp_user: str = '', ftp_pwd: str = '') None[source]

Loads a given firmware file to the target slave.

Warning

It is needed to disconnect the drive(disconnect_from_slave()) after loading the firmware since the Servo object’s data will become obsolete.

Parameters:
  • fw_file – Path to the firmware file to be loaded.

  • target – IP of the target slave.

  • ftp_user – FTP user to connect with.

  • ftp_pwd – FTP password for the given user.

Raises:
static load_firmware_moco(node: int, subnode: int, ip: str, port: int, moco_file: str) None[source]

Update MOCO firmware through UDP protocol.

Parameters:
  • node – Network node.

  • subnode – Drive subnode.

  • ip – Drive address IP.

  • port – Drive port.

  • moco_file – Path to the firmware file.

Raises:

ILFirmwareLoadError – The firmware load process fails with an error message.

scan_slaves() list[str][source]

Scan drives connected to the network.

Returns:

List containing the IPs of the detected drives.

scan_slaves_info() OrderedDict[str, SlaveInfo][source]

Scans for drives in the network.

Returns:

Detected drives with their information.

start_status_listener() None[source]

Start monitoring network events (CONNECTION/DISCONNECTION).

stop_status_listener() None[source]

Stops the NetStatusListener from listening to the drive.

subscribe_to_status(ip: str, callback: Callable[[NetDevEvt], Any]) None[source]

Subscribe to network state changes.

Parameters:
  • ip – IP of the drive to subscribe.

  • callback – Callback function.

unsubscribe_from_status(ip: str, callback: Callable[[NetDevEvt], Any]) None[source]

Unsubscribe from network state changes.

Parameters:
  • ip – IP of the drive to unsubscribe.

  • callback – Callback function.

property protocol: NetProt

Obtain network protocol.

servos: list[Any]

List of the connected servos in the network.

class ingenialink.ethernet.network.NetStatusListener(network: EthernetNetwork, refresh_time: float = 0.25)[source]

Network status listener thread to check if the drive is alive.

Parameters:

network – Network instance of the Ethernet communication.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. See also the module function enumerate().

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

run() None[source]

Check the network status.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

stop() None[source]

Stop the listener.

property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.