package socketcan

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A CAN socket: This is a file descriptor on which CAN message frames can be sent and received.

type t

A CAN socket for sending and receiving CAN message frames.

type error_flag =
  1. | CAN_ERR_TX_TIMEOUT
  2. | CAN_ERR_LOSTARB
  3. | CAN_ERR_CRTL
  4. | CAN_ERR_PROT
  5. | CAN_ERR_TRX
  6. | CAN_ERR_ACK
  7. | CAN_ERR_BUSOFF
  8. | CAN_ERR_BUSERROR
  9. | CAN_ERR_RESTARTED

error flags for configuring a CAN socket

val create : string -> (t, [> `EUnix of Unix.error ]) Result.result

create s opens the can-interface named s (e.g. "can0")

val close : t -> unit

close s closes the socket s.

val set_receive_filter : t -> Filter.t list -> (t, [> `EUnix of Unix.error ]) Result.result

set_receive_filter s fs adds the list of input filters fs to the socket s; the socket will then only receive frames the can-id of which matches any of the given filters; Calling set_receive_filter s [] -- with an empty filter list -- will filter out all incoming messages! The original socket is modified and returned for convenience.

val set_error_flags : t -> error_flag list -> (t, [> `EUnix of Unix.error ]) Result.result

set_error_flags s es will alter the socket s such that all errors as selected in es will now be sent as CAN frames to the socket. The original socket is modified and returned for convenience.

val receive : t -> (Frame.t, [> `EUnix of Unix.error ]) Result.result

receive s will blocking wait for the next frame on the socket s; the returned frame is a copy and will not be altered by subsequent calls to receive. The timestamp of the frame is set to the (not necessarily monotonic) system time indicating the time of arrival of the frame.

val send : t -> Frame.t -> (int, [> `EUnix of Unix.error ]) Result.result

send s f will send the frame f on the socket s; this call will block if the interface is not ready.

val fd : t -> Unix.file_descr

fs s will return a Unix-file-descriptor of the socket s; this file-descriptor can then be used with e.g. Unix.select.

OCaml

Innovation. Community. Security.