ingeniamc / ingeniamotion

Motion library for Ingenia servo drives
Other
6 stars 0 forks source link

get_ifname_by_index throws an error. ingeniamotion 0.8.0 #174

Closed jeferal closed 6 months ago

jeferal commented 6 months ago

Hello. I am trying to use the ingeniamotion 0.8.0 package in a Linux environment and I find that executing the following method: motion_controller.communication.get_ifname_by_index throws an error. https://distext.ingeniamc.com/doc/ingeniamotion/0.8.0/ingeniamotion/communication.html?highlight=get_ifname_by_index#ingeniamotion.communication.Communication.get_ifname_by_index

This is a minimal example:

from ingeniamotion import MotionController
motion_controller = MotionController()
motion_controller.communication.get_interface_name_list()
['lo', 'eth0']
motion_controller.communication.get_ifname_by_index(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/ingeniamotion/communication.py", line 428, in get_ifname_by_index
    return self.__get_adapter_name(index)
  File "/usr/local/lib/python3.9/site-packages/ingeniamotion/communication.py", line 363, in __get_adapter_name
    adapter = ifaddr.get_adapters()[index]
TypeError: 'odict_values' object is not subscriptable

Thank you very much for your help in advance.

MartinALL91 commented 6 months ago

Hi @jeferal.

Thank you for pointing out the issue. We will look at it, and it will be fixed in a future release.

In the meantime, you can use one of the interfaces listed in the motion_controller.communication.get_interface_name_list() to connect to a given servo drive.

For instance:

interface_list = motion_controller.communication.get_interface_name_list()
my_interface = interface_list[0]
slave_id = 1
dict_path = "path_to_dict.xdf"
motion_controller.communication.connect_servo_ethercat(my_interface, slave_id, dict_path)
jeferal commented 6 months ago

Thank you very much for your response. Yes, for linux, this seems like an easy fix!