Communication Examples

Slave connection Example

import sys
import ingenialink as il


def slave_connection():
    # Connection
    servo = None
    try:
        net, servo = il.lucky(il.NET_PROT.ETH,
                              "resources/eve-net_1.7.1.xdf",
                              address_ip='192.168.2.22',
                              port_ip=1061,
                              protocol=2)
    except Exception as e:
        print("Error trying to connect to the servo.", str(e))
    if servo is not None:
        # Try to write and read a register
        try:
            servo.write('COMMU_ANGLE_SENSOR', 3)
        except Exception as e:
            print(e)

        print('COMMU_ANGLE_SENSOR:', servo.read('COMMU_ANGLE_SENSOR'))


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

ECAT Slave connection Example

import sys
from time import time, sleep
import ingenialink as il


def slave_connection():
    # Connection
    servo = None
    net = None
    enum = il.NET_PROT.ECAT

    # SOEM Connection
    try:
        servo, net = il.servo.connect_ecat("\\Device\\NPF_{E8228BC6-D9E5-4CD0-BCDC-A9023F7977B3}",
                                           "resources/eve-net_1.7.1.xdf",
                                           1)
        if servo is not None and net is not None:
            # Read a couple of registers
            print('>> SOFTWARE_VERSION:', servo.read('DRV_ID_SOFTWARE_VERSION'))
            print('>> BUS_VOLTAGE:', servo.read('DRV_PROT_VBUS_VALUE'))

            sleep(1)
            # Disconnect the drive
            net.master_stop()
            print("Disconnected!")
        else:
            print('Could not connect to drive')
    except BaseException as e:
        print('Error while connecting to drive. Exception: {}'.format(e))


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