from canPDOMonitor.kvaser import Kvaser from canPDOMonitor.can import PDOConverter, FrameFormat, Format import logging import time logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) logger.info("Running PDO Converter test") # setup virtual device device = Kvaser() # set up PDO formats format = Format() format.add(FrameFormat(0x181, use7Q8=False, name=["Wave Gen Out", "Encoder Pos"])) format.add(FrameFormat(0x281)) format.add(FrameFormat(0x381)) format.add(FrameFormat(0x481)) # start PDO converter pdo_converter = PDOConverter(device, format) pdo_converter.start() for i in range(1000*60): datapoints = pdo_converter.data_queue.get() if datapoints is None: break # print(datapoints[0]) if i % 10 == 0: time.sleep(0.01)
from canPDOMonitor.kvaser import Kvaser import logging import time # Runs the kvaser for 10 seconds, printing debug info and occasionally frames # initial frame order may be wrong. Other classes must deal with it logging.basicConfig(level=logging.DEBUG) # create the device device = Kvaser() # start reading frames from hardware device.start() # read 1000 frames and print to screen for i in range(4000 * 15): frame = device.get_frame() # time.sleep(.001) if frame is not None: if not i % 4001: print(frame) else: break # stop the device to stop all threads from running device.stop()