Connection Examples

Slave connection through CANopen Example

import sys

from ingenialink.canopen.network import CanopenNetwork, CAN_DEVICE, CAN_BAUDRATE


def connection_example():
    """Scans for nodes in a network, connects to the first found node, reads
    a register and disconnects the found servo from the network."""
    net = CanopenNetwork(device=CAN_DEVICE.IXXAT,
                         channel=0,
                         baudrate=CAN_BAUDRATE.Baudrate_1M)
    nodes = net.scan_slaves()
    print(nodes)

    if len(nodes) > 0:
        servo = net.connect_to_slave(
            target=nodes[0],
            dictionary='../../resources/dictionaries/eve-net-c_can_1.8.1.xdf')

        fw_version = servo.read('DRV_ID_SOFTWARE_VERSION')
        print(fw_version)

        net.disconnect_from_slave(servo)
    else:
        print('Could not find any nodes')


if __name__ == '__main__':
    connection_example()
    sys.exit()

Slave connection through CANopen Example (Linux)

In Linux, the CANopen network should be configured in a terminal before running the ingenialink script (administrator privileges are needed).

sudo ip link set can0 up type can bitrate 1000000
sudo ip link set can0 txqueuelen 1000

Then to establish the connection use always the SOCKETCAN device and the bitrate configured in previous step:

import sys

from ingenialink.canopen.network import CAN_BAUDRATE, CAN_DEVICE, CanopenNetwork


def connection_example(dict_path: str) -> None:
    """Scans for nodes in a network, connects to the first found node, reads
    a register and disconnects the found servo from the network.

    Args:
        dict_path: Path to the dictionary
    """
    net = CanopenNetwork(device=CAN_DEVICE.SOCKETCAN, channel=0, baudrate=CAN_BAUDRATE.Baudrate_1M)
    nodes = net.scan_slaves()
    print(nodes)

    if len(nodes) > 0:
        servo = net.connect_to_slave(target=nodes[0], dictionary=dict_path)

        fw_version = servo.read("DRV_ID_SOFTWARE_VERSION")
        print(fw_version)

        net.disconnect_from_slave(servo)
    else:
        print("Could not find any nodes")


if __name__ == "__main__":
    dict_path = "../../resources/dictionaries/eve-net-c_can_1.8.1.xdf"
    connection_example(dict_path)
    sys.exit()

Slave connection through Ethernet Example

import sys

from ingenialink.ethernet.network import EthernetNetwork


def connection_example():
    net = EthernetNetwork()
    servo = net.connect_to_slave("192.168.2.22",
                                 "../../resources/dictionaries/eve-net-c_eth_1.8.1.xdf",
                                 1061)

    print(servo.read('DRV_ID_SOFTWARE_VERSION'))

    net.disconnect_from_slave(servo)


if __name__ == '__main__':
    connection_example()
    sys.exit(0)