package socketcan
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Socketcan.Socket
A CAN socket: This is a file descriptor on which CAN message frames can be sent and received.
val create : string -> (t, [> `EUnix of Unix.error ]) Result.resultcreate s opens the can-interface named s (e.g. "can0")
val create_exn : string -> tcreate_exn s is identical to create s but will raise a Unix_error exception in case of an error.
val close : t -> unitclose s closes the socket s.
val set_receive_filter :
t ->
Filter.t list ->
(t, [> `EUnix of Unix.error ]) Result.resultset_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.resultset_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.resultreceive 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.
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.resultsend s f will send the frame f on the socket s; this call will block if the interface is not ready.
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_descrfs s will return a Unix-file-descriptor of the socket s; this file-descriptor can then be used with e.g. Unix.select.