n = 0 for i in ids: n+=1 print('[{0}] {1}'.format(n, i)) n = input('Select iface (1-{0}):'.format(len(ids))) return module.make_iface(ids[n-1],param) #------------------------------------------------------------------------------ # MAIN #------------------------------------------------------------------------------ if __name__ == '__main__': iface = get_iface('ixxat') io_service = canio2.IOService(iface) NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) waiter = canio2.TriggersWaiter(io_service) print 'Resetting node...' if node.reset(5000) == False: print 'Boot Timeout' sys.exit(1) print 'Node state after reset: ' + str(node.state) node.state = CANopenNode.STATES.OPERATIONAL print 'Node state : ' + str(node.state) print('* Drive Initialization.') print('\tClear Faults.') node.wu16(0x6040,0x80) print('\tMotor parameters Setup.') node.wu16(0x6402,1) # motor type
############################################################################### # Example: # CANopen node reset ############################################################################### import canio2 from canio2 import CANopenNode # CAN module (CAN iface type) initialization module = canio2.make_module('ixxat') # CAN iface creation. Pass iface id and bitrate to make_iface method. iface = module.make_iface('HW104122','1000K') # io_service object is a link between low and high levels io_service = canio2.IOService(iface) # CANopen Node object initialization NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) if node.reset(5000) == False: print 'Error: Boot Timeout' else: print 'Boot OK' print 'State:', node.state
############################################################################### # Example: # CANopen node 'device type' reading ############################################################################### import canio2 from canio2 import CANopenNode # CAN module (CAN iface type) initialization module = canio2.make_module('ixxat') # CAN iface creation. Pass iface id (or '*') and bitrate to make_iface method. iface = module.make_iface('HW104122','1000K') # io_service object is a link between low and high levels io_service = canio2.IOService(iface) # CANopen Node object initialization NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) device_type= node.ru32(0x1000,0) print 'Device Type:',hex(device_type)
############################################################################### # Example: # CANopen node reset ############################################################################### import canio2 from canio2 import CANopenNode # CAN module (CAN iface type) initialization module = canio2.make_module('ixxat') # CAN iface creation. Pass iface id and bitrate to make_iface method. iface = module.make_iface('HW104122', '1000K') # io_service object is a link between low and high levels io_service = canio2.IOService(iface) # CANopen Node object initialization NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) if node.reset(5000) == False: print 'Error: Boot Timeout' else: print 'Boot OK' print 'State:', node.state
print('Available IDs:') n = 0 for i in ids: n+=1 print('[{0}] {1}'.format(n, i)) n = input('Select iface (1-{0}):'.format(len(ids))) return module.make_iface(ids[n-1],param) #------------------------------------------------------------------------------ # MAIN #------------------------------------------------------------------------------ if __name__ == '__main__': iface = get_iface('ixxat', None, '1000K') io_service = canio2.IOService(iface) n = CANopenNode(NODE_ID, io_service) waiter = canio2.TriggersWaiter(io_service) print('Resetting node...') if n.reset(6000) == False: print 'Boot Timeout' sys.exit(1) print('Node state after reset: ' + str(n.state)) n.state = CANopenNode.STATES.OPERATIONAL time.sleep(0.1) if n.state == CANopenNode.STATES.OPERATIONAL: print('Node state : OPERATIONAL') else: raise Exception('Can\'t setup operational mode') try: # Initialisation
############################################################################### # Example: # CANopen node 'device type' reading ############################################################################### import canio2 from canio2 import CANopenNode # CAN module (CAN iface type) initialization module = canio2.make_module('ixxat') # CAN iface creation. Pass iface id (or '*') and bitrate to make_iface method. iface = module.make_iface('HW104122', '1000K') # io_service object is a link between low and high levels io_service = canio2.IOService(iface) # CANopen Node object initialization NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) device_type = node.ru32(0x1000, 0) print 'Device Type:', hex(device_type)
print('[{0}] {1}'.format(n, i)) n = input('Select iface (1-{0}):'.format(len(ids))) return module.make_iface(ids[n - 1], param) #------------------------------------------------------------------------------ # init #------------------------------------------------------------------------------ iface = get_iface('ixxat') io_service = canio2.IOService(iface) #------------------------------------------------------------------------------ # Main #------------------------------------------------------------------------------ NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) print 'Node state:', node.state print 'Setting state to:', CANopenNode.STATES.STOPPED node.state = CANopenNode.STATES.STOPPED print 'Node state: ', node.state print 'Setting state to:', CANopenNode.STATES.PRE_OPERATIONAL node.state = CANopenNode.STATES.PRE_OPERATIONAL print 'Node state:', node.state print 'Setting state to:', CANopenNode.STATES.OPERATIONAL node.state = CANopenNode.STATES.OPERATIONAL print 'Node state: ', node.state