Exemplo n.º 1
0
def setUpChannel(channel=0,
                 openFlags=canlib.Open.ACCEPT_VIRTUAL,
                 bitrate=canlib.canBITRATE_1M,
                 outputControl=canlib.Driver.NORMAL):
    ch = canlib.openChannel(channel, openFlags)
    print("Using channel: %s, EAN: %s" % (
        canlib.ChannelData(channel).channel_name,
        canlib.ChannelData(channel).card_upc_no))
    ch.setBusOutputControl(outputControl)
    ch.setBusParams(bitrate)
    ch.busOn()
    return ch
Exemplo n.º 2
0
def set_channelConnection(
        channel=0,
        openFlags=canlib.Open.ACCEPT_VIRTUAL,
        bitrate=111111,  #canlib.canBITRATE_125K,
        outputControl=canlib.Driver.NORMAL,
        sjw=4,
        tseg1=5,
        tseg2=6):
    ch = canlib.openChannel(channel, openFlags)
    print("Using channel: %s, EAN: %s" %
          (canlib.ChannelData(channel).device_name,
           canlib.ChannelData(channel).card_upc_no))
    ch.setBusOutputControl(outputControl)
    ch.setBusParams(freq=bitrate, sjw=sjw, tseg1=tseg1, tseg2=tseg2)
    ch.busOn()
    return ch
def openChannel(channel=0,
                openFlags=canlib.canOPEN_ACCEPT_VIRTUAL,
                bitrate=canlib.canBITRATE_500K,
                bitrateFlags=canlib.canDRIVER_NORMAL):
    #  cl = canlib.canlib()
    ch = canlib.openChannel(channel, openFlags)
    num_channels = canlib.getNumberOfChannels()
    print("num_channels:%d" % num_channels)
    print(
        "%d. %s (%s / %s)" % (num_channels, canlib.ChannelData(0).channel_name,
                              canlib.ChannelData(0).card_upc_no,
                              canlib.ChannelData(0).card_serial_no))
    ch.setBusOutputControl(bitrateFlags)
    ch.setBusParams(bitrate)
    ch.busOn()
    #  print("somethin wrong***************************************")
    return ch
Exemplo n.º 4
0
 def __str__(self):
     if self.__interface == 'Kvaser':
         num_channels = canlib.getNumberOfChannels()
         for ch in range(0, num_channels):
             chdata = canlib.ChannelData(ch)
             chdataname = chdata.channel_name  #device_name
             #chdata_EAN = chdata.card_upc_no
             #chdata_serial = chdata.card_serial_no
             return f'Using {chdataname}, Bitrate:{self.__bitrate}'
     if self.__interface == 'AnaGate':
         ret = analib.wrapper.dllInfo()  # DLL version
         return f'{self.__ch}, Bitrate:{self.__bitrate}'
     else:
         return f'{self.__ch.channel_info}, Bitrate:{self.__bitrate}'
Exemplo n.º 5
0
def find_channel(ch_num):
    return_channel_num = 99
    num = canlib.getNumberOfChannels() # 연결되어 있는 모든 채널들을 가져온다

    for channel in range(0, num):
        chdata = canlib.ChannelData(channel)

        print("%d, %s, %s, %s" % (channel, chdata.channel_name, chdata.card_upc_no, chdata.card_serial_no))
        ean = canlib.getChannelData_EAN(channel)

        if '11111-1' in ean :   # ex) 11111-1은 Kvaser Device Guide에서 연결된 CAN Device EAN '00-00000-11111-1'의 11111-1을 확인 후 기입한다.
            return_channel_num = channel + ch_num
            break

    return return_channel_num
Exemplo n.º 6
0
def init(channel_number=0, bitrate=500):
    channel_number = 0
    # Specific CANlib channel number may be specified as first argument
    if len(sys.argv) == 2:
        channel_number = int(sys.argv[1])
    print("Opening channel %d" % (channel_number))
    # Use ChannelData to get some information about the selected channel
    chd = canlib.ChannelData(channel_number)
    print("%d. %s (%s / %s) " % (channel_number, chd.channel_name,
                                 chd.card_upc_no, chd.card_serial_no))
    # Open CAN channel, virtual channels are considered ok to use
    ch = canlib.openChannel(channel_number, canlib.canOPEN_ACCEPT_VIRTUAL)
    ch.iocontrol.local_txecho = False
    print("Setting bitrate to 500 kb/s")
    ch.setBusParams(canlib.canBITRATE_500K)
    # print("Going on bus")
    # ch.busOn()
    return ch
Exemplo n.º 7
0
    def __init__(self):
        # Initialize existence of thread, declare canlib object, open a channel handle (0), set channel parameters
        QtCore.QThread.__init__(self)
        # Create canlib object
        # Print out current canlib driver version to console
        print("CANlib version: " + str(canlib.dllversion()))
        # Open a channel that accepts connected physical CAN device, default to virtual channel if none found
        self.handle1 = canlib.openChannel(0, canlib.canOPEN_ACCEPT_VIRTUAL)
        self.h1data = canlib.ChannelData(0)
        # Print out current channel name and data to console
        print("Using channel: " + str(self.h1data.channel_name) + ", EAN: " +
              str(self.h1data.card_upc_no))
        # Set the can bus control to normal
        self.handle1.setBusOutputControl(canlib.canDRIVER_NORMAL)
        # Set CAN bit-rate to 125k (GCM default bit-rate)
        self.handle1.setBusParams(canlib.canBITRATE_125K)
        # Turn channel bus ON
        self.handle1.busOn()

        self.actively_dumping = True  # Flag for 'self.run' method
Exemplo n.º 8
0
# def is_odd(n):
    # return n % 2 == 1

# L = list(filter(is_odd, range(1, 20)))

# print(list(filter(lambda x: x%2==1,range(1,20))))


# import time, functools

# def metric(fn):
    # print('%s executed in %s ms' % (fn.__name__, 10.24))
    # return fn
    
# @metric
# def fast(x, y):
    # time.sleep(0.0012)
    # return x + y
    
# print(fast(11,22))

from canlib import canlib

num_channels = canlib.getNumberOfChannels()
print("Found %d channels" % num_channels)
for ch in range(0, num_channels):
    chdata = canlib.ChannelData(ch)
    print("%d. %s (%s / %s)" % (ch, chdata.channel_name,
                                chdata.card_upc_no,
                                chdata.card_serial_no))
Exemplo n.º 9
0
# 01_canlib_buson_off.py
from canlib import canlib
from canlib.canlib import ChannelData

channel = 0
chd = canlib.ChannelData(channel)
print("CANlib version: v{}".format(chd.dll_product_version))
print("canlib dll version: v{}".format(chd.dll_file_version))
print("Using channel: {ch}, EAN: {ean}".format(ch=chd.device_name,
                                               ean=chd.card_upc_no))

ch1 = canlib.openChannel(channel, canlib.canOPEN_ACCEPT_VIRTUAL)
ch1.setBusOutputControl(canlib.canDRIVER_NORMAL)
ch1.setBusParams(canlib.canBITRATE_1M)
ch1.busOn()
ch1.busOff()
Exemplo n.º 10
0
 def __str__(self):
     chdataname = canlib.ChannelData(self.__channel).device_name
     chdata_EAN = canlib.ChannelData(self.__channel).card_upc_no
     return 'Using {:s}, EAN: {:s}'.format(chdataname, str(chdata_EAN))
Exemplo n.º 11
0
#! /usr/bin/env python3
###############################################################################################################
###############################################################################################################
# 文件名称:kavser_test.py
# 文件功能:CAN 总线测试程序
# 备注信息:
##############################################################################################################
##############################################################################################################

import sys 
sys.path.append('/usr/local/lib/python3.5/dist-packages/')
import canlib.canlib as canlib
#  cl = canlib.canlib()
num_channels = canlib.getNumberOfChannels()
print("Found %d channels" % num_channels)
for ch in range(0, num_channels):
    #  print("%d. %s (%s / %s)" % (ch, cl.getChannelData_Name(ch),
    print("%d. %s (%s / %s)" % (ch, canlib.ChannelData(ch).channel_name,
        canlib.ChannelData(ch).card_upc_no,
        canlib.ChannelData(ch).card_serial_no))
Exemplo n.º 12
0
import sys
# sys.path.append("C:/temp/Canlib_SDK_v5.9/Samples/Python")

# This software is furnished as Redistributable under the Kvaser Software Licence
# https://www.kvaser.com/canlib-webhelp/page_license_and_copyright.html

from canlib import canlib, Frame

channel_number = 0
# Specific CANlib channel number may be specified as first argument
if len(sys.argv) == 2:
    channel_number = int(sys.argv[1])

print("Opening channel %d" % (channel_number))
# Use ChannelData to get some information about the selected channel
chd = canlib.ChannelData(channel_number)
print("%d. %s (%s / %s) " %
      (channel_number, chd.channel_name, chd.card_upc_no, chd.card_serial_no))

# If the channel have a custom name, print it
# if chd.custom_name != '':
# print("Customized Channel Name: %s " % (chd.custom_name))

# Open CAN channel, virtual channels are considered ok to use
ch = canlib.openChannel(channel_number, canlib.canOPEN_ACCEPT_VIRTUAL)

#Add by hzc
ch.iocontrol.local_txecho = False

print("Setting bitrate to 500 kb/s")
ch.setBusParams(canlib.canBITRATE_500K)