MF4_WRITE
Python Code
from flojoy import flojoy, Stateful, DataContainer
from typing import Optional
import can
@flojoy(deps={"python-can": "4.3.1", "asammdf": "7.4.1"})
def MF4_WRITE(
MF4_writer: Stateful,
messages: Stateful,
) -> Optional[DataContainer]:
"""Write a message to a MF4 writer.
Logs CAN data to an ASAM Measurement Data File v4 (.mf4).
The MF4 Writer does not support append mode.
A writer must be created and connected to this block before any data can be written to it, use `MF4_CREATE_WRTIER` to do so.
Parameters
----------
MF4_writer : Stateful
A mf4 writer object from a MF4_CREATE_WRITER block.
messages : Stateful
A list of message in the python-can format.
Returns
-------
Optional[DataContainer]
None
"""
writer: can.io.MF4Writer = MF4_writer.obj
messages = messages.obj
for message in messages:
writer.on_message_received(message)
return Stateful(writer)
Example
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.