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',
eds='../../resources/dictionaries/eve-net-c_1.8.1.eds')
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 EtherCAT Example¶
import sys
from ingenialink.ethercat.network import EthercatNetwork
def connection_example():
net = EthercatNetwork("\\Device\\NPF_{13C5D891-C81E-46CE-8651-FADBE3C9415D}")
slaves = net.scan_slaves()
print(slaves)
if len(slaves) > 0:
servo = net.connect_to_slave(
target=slaves[0],
dictionary='../../resources/dictionaries/eve-xcr-e_eoe_1.8.1.xdf')
print(servo.read('DRV_ID_SOFTWARE_VERSION'))
net.disconnect_from_slave(servo)
if __name__ == '__main__':
connection_example()
sys.exit(0)
Slave connection through Ethernet Example¶
import sys
from ingenialink.ethernet.network import EthernetNetwork, NET_TRANS_PROT
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,
NET_TRANS_PROT.UDP)
print(servo.read('DRV_ID_SOFTWARE_VERSION'))
net.disconnect_from_slave(servo)
if __name__ == '__main__':
connection_example()
sys.exit(0)
Slave connection through Serial Example¶
import sys
from time import sleep
import ingenialink as il
from ingenialink.serial.network import SerialNetwork
def connection_example():
network = SerialNetwork()
target = "COM5"
servo = network.connect_to_slave(target,
"../../resources/dictionaries/"
"eve-core_1.8.1.xdf")
if servo:
print("Drive Connected in", target)
print("Status word: ", servo.read("DRV_STATE_STATUS", subnode=1))
network.disconnect_from_slave(servo)
if __name__ == '__main__':
connection_example()
sys.exit()