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.

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

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

val create_exn : string -> t

create_exn s is identical to create s but will raise a Unix_error exception in case of an error.

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.t 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 receive_exn : t -> Frame.t

receive_exn s works exactly like receive s but will raise a Unix_error exception in case of an error.

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 send_exn : t -> Frame.t -> int

send_exn s f works exactly like send s f but will raise a Unix_error exception in case of an error.

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.