The Canbus Interface

The functions canRead() and canWrite do CanBus I/O.

#!/usr/bin/perl

use Spectra
#
# send 2 bytes (0, 0) to the identifier 0x201
#
$ret = canWrite( 0x201, 0, 0);
#
# generate a frame with the identifier 0x181 ...
#   
$ret = canWrite( 0x181);
#
# ... and fetch the transmitted frame and split it into 
#   - the identifier ($adr)
#   - the length of the frame ($len)
#   - and the message part (@msg)
#
($adr, $len, @msg) = split ' ', canRead();

#
# loop until we find the desired pattern 
#   
while( $msg[0] != 85 ||
       $msg[1] != 85)
{
    $ret = canWrite( 0x181);
    ($adr, $len, @msg) = split ' ', canRead();
    Wait( 0.2);
}