示例#1
0
def get_iface(module_name, instance_name = None, param = None):
    module = canio2.make_module(module_name)
    ids = module.ids()
    if param ==None : param = '1000K'
    if instance_name: 
        return module.make_iface(instance_name, param)
    if len(ids) == 0: # no ifaces
        return None
    if len(ids) == 1: # there is only one iface
        return module.make_iface(ids[0],param)
    # otherwise
    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)
示例#2
0
def get_iface(module_name, instance_name = None, param = None):
    module = canio2.make_module(module_name)
    ids = module.ids()
    if param ==None : param = '1000K'
    if instance_name: 
        return module.make_iface(instance_name, param)
    if len(ids) == 0: # no ifaces
        return None
    if len(ids) == 1: # there is only one iface
        return module.make_iface(ids[0],param)
    # otherwise
    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)
示例#3
0
文件: example_3.py 项目: JIRL/canio2
###############################################################################
# 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
示例#4
0
###############################################################################
# Example:
# Send/Receive CAN message via IXXAT CAN interface
###############################################################################
import canio2

# 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')
# CAN msg
m = canio2.CANMsg()
m.id = 0x1
m.rtr = 0
m.len = 2
m.data0 = 1
m.data1 = 2
# Send m, timeout - 100 ms
iface.send(m, 100)
# Recv CAN msg, timeout 3 s
if iface.recv(m, 3000) == True:
    print(m)
else:
    print('RX timeout')