NAME

CANBUS - Perl extension for sending and receiving CANBUS messages using the Linux CANBUS driver.

SYNOPSIS

 use CANBUS;
 CANBUS::setup('can0') ;
 CANBUS::send($id,\@data) ;
 @data = CANBUS::receive() ; 

DESCRIPTION

CANBUS::setup($interface) ;

Open a socket, bind it to the interface

May require that the interface is brought up first, e.g. sudo ip link set can0 type can bitrate 250000 sudo ip link set can0 up

CANBUS::send($id,\@data) ;

Send data from an array passed by reference to a named ID, using the configured interface

@data = CANBUS::receive() ;

Read data from the configured interface and place it on the stack. There may be a variable number of data words.

CANBUS::teardown() ;

Close the socket for the configured interface.

EXAMPLE

my $if = 'can0' ;
my $id = 1 ;
CANBUS::setup($if) ;           # open interface
my @data = (0x09,0x81,1,0,0) ; # get battery voltage
CANBUS::send($id,\@data) ;     # send the message
while (1) {
  @data = CANBUS::receive() ; 
  if ($data[0] == 0x500) { last ; }  # ignore broadcasts, wait for a reply
}
CANBUS::teardown() ;

EXPORT

None by default.

SEE ALSO

The can-utils package, cansend, candump

AUTHOR

Andrew Daviel, <advax@daviel.org>

COPYRIGHT AND LICENSE

Copyright (C) 2026 by Andrew Daviel

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.38.4 or, at your option, any later version of Perl 5 you may have available.