Esempio n. 1
0
def setUpChannel(channel=0,
                 openFlags=canlib.canOPEN_ACCEPT_VIRTUAL,
                 bitrate=canlib.canBITRATE_500K,
                 bitrateFlags=canlib.canDRIVER_NORMAL):
    cl = canlib.canlib()
    ch = cl.openChannel(channel, openFlags)
    print("Using channel: %s, EAN: %s" %
          (ch.getChannelData_Name(), ch.getChannelData_EAN()))
    ch.setBusOutputControl(bitrateFlags)
    ch.setBusParams(bitrate)
    ch.busOn()
    return ch
Esempio n. 2
0
    cl = canlib.canlib()
    ch = cl.openChannel(channel, openFlags)
    print("Using channel: %s, EAN: %s" %
          (ch.getChannelData_Name(), ch.getChannelData_EAN()))
    ch.setBusOutputControl(bitrateFlags)
    ch.setBusParams(bitrate)
    ch.busOn()
    return ch


def tearDownChannel(ch):
    ch.busOff()
    ch.close()


cl = canlib.canlib()
print("canlib version: %s" % cl.getVersion())

channel_0 = 0

ch0 = setUpChannel(channel=0)

msgId = 0x4F0
msg = [0x00, 0x00, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00]
flg = canlib.canMSG_EXT
ch0.write(msgId, msg, flg)

msgId = 0x4F1
msg = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10]
flg = canlib.canMSG_EXT
ch0.write(msgId, msg, flg)
Esempio n. 3
0
import socket
import sys
import time
import binascii

import canlib.canlib as canlib

syncpattern = "S"

# Create the TCP/IP socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
can = canlib.canlib()
can.initializeLibrary()

num_channels = can.getNumberOfChannels()
print("Found %d channels" % num_channels)
for ch in range(0, num_channels):
    print("%d. %s (%s / %s)" %
          (ch, can.getChannelData_Name(ch), can.getChannelData_EAN(ch),
           can.getChannelData_Serial(ch)))
print("Using CAN channel 0 currently.")

# Bind socket to port
server_address = ('localhost', 10000)
print >> sys.stderr, 'Starting up on %s port %s' % server_address
s.bind(server_address)

s.listen(1)

# We are now listening and waiting to accept a connection
connection, client_address = s.accept()