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,
                              "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_{43144EC3-59EF-408B-8D9B-4867F1324D62}",
            "resources/eve-net_1.7.1.xdf",
             1, use_eoe_comms=0)
        # servo2, net2 = il.servo.connect_ecat(
        #     "\\Device\\NPF_{43144EC3-59EF-408B-8D9B-4867F1324D62}",
        #     "resources/eve-net_1.7.1.xdf",
        #     2, use_eoe_comms=0)
        # servo3, net3 = il.servo.connect_ecat(
        #     "\\Device\\NPF_{43144EC3-59EF-408B-8D9B-4867F1324D62}",
        #     "resources/eve-net_1.7.1.xdf",
        #     3, use_eoe_comms=0)
        if servo is not None and net is not None:
                # and \
                # servo2 is not None and net2 is not None and \
                # servo3 is not None and net3 is not None:
            # Read a couple of registers
            while(True):
               start = time()
               result = net.read_string_sdo(0x5A01, 0x01, 4, slave=3)
               result1 = net.read_sdo(0x2106, 0x00, il.REG_DTYPE.S16.value, slave=1)
               net.write_sdo(0x5D00, 0x00, il.REG_DTYPE.FLOAT.value, -23.1255,
                             slave=1)
               result2 = net.read_sdo(0x5D00, 0x00, il.REG_DTYPE.FLOAT.value,
                                slave=1)
               # net.write_sdo(0x2106, 0x00, il.REG_DTYPE.S16.value, 12, subnode=1)

               # print('>> BUS_VOLTAGE node 1:',
               #       servo.read('DRV_PROT_VBUS_VALUE'))


            #    print('>> BUS_VOLTAGE node 2:',
            #          servo2.read('DRV_PROT_VBUS_VALUE'))
            #    servo.enable()
            #    servo2.enable()

            #    servo.disable()
            #    servo2.disable()
               end = time()
               print(end - start)

            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)