CAN software control
This page contains all the available CAN software control functions in Engee.
|
To work with the CAN software control functions in Engee, install the hardware support package as specified in article. After that, perform:
|
Structure of the CAN message
Base.@kwdef struct CanMessage
timestamp::Float64 # метка времени
arbitration_id::Int64 # ID сообщения (11 или 29 бит)
is_extended_id::UInt8 # 1 — 29-битный ID
is_remote_frame::UInt8 # 1 — RTR
is_error_frame::UInt8 # 1 — кадр ошибки
is_fd::UInt8 # 1 — CAN FD
bitrate_switch::UInt8 # 1 — переключение скорости
error_state_indicator::UInt8
dlc::Int64 # длина данных (0–8 Classic, 0–64 FD)
data::Union{Vector{UInt8}, Int64}
end
Examples
Interface virtual
can = CAN.Can()
CAN.set_bus_settings(can, "virtual", "virtual_0", 500.0, true)
CAN.set_bus_settings(can, "virtual", "virtual_1", 500.0, true)
CAN.create_bus(can, "virtual", "virtual_0", 500.0, true)
CAN.create_bus(can, "virtual", "virtual_1", 500.0, true)
CAN.set_filters(can, "virtual_0", 0, 0)
data_field = rand(UInt8, 8)
message = CanMessage(
timestamp = rand(Float64),
arbitration_id = rand(UInt32),
is_extended_id = 0,
is_remote_frame = 0,
is_error_frame = 0,
is_fd = 0,
bitrate_switch = 0,
error_state_indicator = 0,
dlc = length(data_field),
data = data_field,
)
CAN.send(can, "virtual_0", message, true)
msg = CAN.recv(can, "virtual_1", 0.0)
println("Отправлено: $data_field")
println("Получено: $(msg.data)")
CAN.destroy_bus(can, "virtual_0")
CAN.close(can)
CAN FD
CAN.set_bus_settings(can, "socketcan", "can0", 500.0, true, true, 2000.0)
CAN.create_bus(can, "socketcan", "can0", 500.0, true, true, 2000.0)
fd_message = CanMessage(
timestamp = time(), arbitration_id = 0x123,
is_extended_id = 0, is_remote_frame = 0, is_error_frame = 0,
is_fd = 1, bitrate_switch = 1, error_state_indicator = 0,
dlc = 64, data = rand(UInt8, 64),
)
CAN.send(can, "can0", fd_message)