Skip to content

PEAK_CONNECT

Download Flojoy Studio to try this app
Connect to a PCAN device. Connect to a PCAN device. This blocks should be compatible with all devices that support the PCAN interface. For Windows and Linux compatibilities, the following Drviers are required: โ†’ https://www.peak-system.com/Drivers.523.0.html?&L=1 For MacOS compatibilities, the following Drivers are required: โ†’ https://mac-can.github.io/ Params: PCAN_address : str The PCAN device address to connect to. This address can be found by the PCAN_DETECT_AVAILABLE_DEVICES block. โ†’ Example: "PCAN_USBBUS1" bitrate : int The bitrate of the PCAN device. Default is 500000. Returns: out : DataContainer Optional: None
Python Code
from flojoy import flojoy, DataContainer, DeviceConnectionManager, HardwareDevice
from typing import Optional
import can


@flojoy(deps={"python-can": "4.3.1", "uptime": "3.0.1"})
def PEAK_CONNECT(
    PCAN_address: str, bitrate: int = 500000, default: Optional[DataContainer] = None
) -> Optional[DataContainer]:
    """Connect to a PCAN device.

    Connect to a PCAN device. This blocks should be compatible with all devices that support the PCAN interface.

    For Windows and Linux compatibilities, the following Drviers are required:
        โ†’ https://www.peak-system.com/Drivers.523.0.html?&L=1
    For MacOS compatibilities, the following Drivers are required:
        โ†’ https://mac-can.github.io/

    Parameters
    ----------
    PCAN_address : str
        The PCAN device address to connect to. This address can be found by the PCAN_DETECT_AVAILABLE_DEVICES block.
        โ†’ Example: "PCAN_USBBUS1"
    bitrate : int
        The bitrate of the PCAN device. Default is 500000.

    Returns
    -------
    DataContainer
        Optional: None
    """

    session = can.interface.Bus(interface="pcan", channel=PCAN_address, bitrate=bitrate)

    DeviceConnectionManager.register_connection(
        HardwareDevice(PCAN_address),
        session,
        cleanup=lambda pcan_bus: pcan_bus.shutdown(),
    )

    return None

Find this Flojoy Block on GitHub

Example App

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

This application demonstrates how to use multiple CAN blocks to connect to a PEAK-USB device and read messages from it. The PEAK-USB device is a USB-to-CAN interface that enables you to connect a computer to a CAN network. This device is used in this case to capture the messages of a particular sensor by filtering them directly at the kernel level, thus reducing the load on the CPU, and save those messages to a log file locally.

Once the app is done, the generated logs are exported to an S3 bucket to keep a record of the sensorโ€™s data for further analysis.

To replicate this application, you must connect the PEAK-USB to your computer and install the required driver (refer to the PEAK_CONNECT blocks for more information on the necessary driver for your platform). Then, simply specify the PEAK-USB channel in the required blocks, and this Flojoy application will log the messages received by the device!

Detecting channels A valuable block is the PEAK_DETECT_AVAILABLE_DEVICE. This block allows you to display the devices using the PCAN interface that are connected to your computer.