Frames
In CANBus.jl, send/receive messages are represented in CANBus.Frames module. For CAN frame, Frame is used, or for CAN FD frame, FDFrame is used.
Base type
CANBus.Frames.AbstractFrame — Type
Abstract type for Frames.
Frame
CANBus.Frames.Frame — Type
Frame(id::Integer, data::AbstractVector;
timestamp::Float64=0, is_extended::Bool=false,
is_remote_frame::Bool=false, is_error_frame::Bool=false)Frame struct represents classic (MAX 8bytes) CAN frame.
id: arbitration iddata: Vector of Integer with length <= 8. If input has element > 255, throws error.
kwargs:
timestamp: When receive, arrive time stamp is set in this field. When transmission, this field is not cared.- The time stamp is unixtime in sedoncs with fractional part.
is_extended: Flag which arbitration id is extended. default=falseis_remote_frame: Flag which indicates remote frame. default=falseis_error_frame: Flag which indicates error frame. Cared in RX only. default=false
frame = CANBus.Frame(0x5, [1, 2, 3, 4, 5, 6, 7, 8]; is_extended=true)FDFrame
CANBus.Frames.FDFrame — Type
FDFrame(id::Integer, data::AbstractVector;
timestamp::Float64=0, is_extended::Bool=false,
bitrate_switch::Bool=true, error_state::Bool=false, is_error_frame::Bool=false)FDFrame struct represents CAN FD (MAX 64bytes) frame.
id: arbitration iddata: Vector of Integer. Length must be in CAN FD DLC standard. Elements must not be > 255.
kwargs:
timestamp: When receive, arrive time stamp is set in this field. When transmission, this field is not cared.- The time stamp is unixtime in sedoncs with fractional part.
is_extended: Flag which arbitration id is extended. default=falsebitrate_switch: Flag to usebitrate_switch. default=trueerror_state: Flag corresponds toerror_state_indicator. Cared in RX only. default=falseis_error_frame: Flag which indicates error frame. Cared in RX only. default=false
References
Base.length — Method
Base.length(msg::T) where {T<:CANBus.Frames.AbstractFrame}Return length of data field.
Compatibility with CANalyze.jl package
Frame and FDFrame has intercompatibility with CANalyze.CANFrame and CANAlyze.CANFdFrame respectively.
For instance, Frame constructor has a converter from CANalyze.CANFrame struct, you can use it like below:
using CANBus
using CANalyze
vector1 = VectorInterface(0, 500000, "NewApp")
frm = CANalyze.CANFrame(1, [1, 2, 3, 4, 5, 6, 7, 8])
msg = Frame(frm)
send(vector1, msg)In the opposite direction, CANalyze.CANFrame and CANalyze.CANFdFrame constructors are overridden, so that you can feed Frame and FDFrame structs to CANalyze.Decode.decode function with conversion.
frm = CANBus.Frame(0x0e, [1, 2, 3, 4]; is_extended=true)
signal = CANalyze.Signals.NamedSignal("myfloat", nothing, nothing,
CANalyze.Signals.Float32Signal(start=0; byte_order=:little_endian))
msg = CANalyze.Messages.Message(0x0e, 4, "msg1", signal)
d = CANalyze.Decode.decode(msg, CANalyze.Frames.CANFrame(frm))Converting APIs
CANBus.Frames.Frame — Method
Frame(frm::CANalyze.CANFrame)This constructor converts CANalyze.CANFrame to CANBus.Frame.
CANalyze.Frames.CANFrame — Method
CANalyze.Frames.CANFrame(frame::Frame)This constructor converts CANBus.Frame to CANalyze.CANFrame.
CANBus.Frames.FDFrame — Method
FDFrame(frm::CANalyze.CANFdFrame; bitrate_switch::Bool=true)This constructor converts CANalyze.CANFdFrame to CANBus.FDFrame.
CANalyze.Frames.CANFdFrame — Method
CANalyze.Frames.CANFdFrame(frame::FDFrame)This constructor converts CANBus.FDFrame to CANalyze.CANFdFrame.