Avisaro Online Documentation - Wiki
Impressum Kontakt Sitemap

PUTCAN

Description

The PUTCAN command can be used to immediately send messages onto the CAN bus. PUTCAN needs a single argument which is the name of a byte-array. The array must be big enough to hold an entire CAN frame including additional information such like header and time stamps. Or that is to say: 28 bytes are needed.

The 8 bytes CAN byte-array is arranged in this way:

4 Bytes Header This is an arbitrary header that can freely be used. It is not send over the CAN BUS

4 Bytes Frame Descriptor
This field holds information regarding to the CAN frame. It is subdivided in:

Bits 16...19 are the data lenght counter. This is the number of data bytes the frame has.

Bit 30 is the RTR bit. If this bit is one, the frame was send out with RTR=1 right after the identifier.

Bit 31 defines the frame type. If this bit is set, an extended frame will be send. Otherwise the frame is a standard frame.

Other bits are unused and should be zero

4 Bytes Message ID This field contains the message ID.

8 Bytes Data This field contains the 8 data bytes that are transmitted to the CAN bus.

4 Bytes RTC timestamp This field is only be used with received frames. It contains the time stamp from the on-board real time clock.

4 Bytes millisecond counter  This field is also only used with received frames. It contains the millisecond time stamp from a free running counter.

With exception of the data field, members of a CAN byte-array should not be modified directly. There's a convenient command named "SETCAN" that should be used to perform changes.

Example

The following example sends a CAN frame with 3 data bytes 200, 201, 202 and message ID 100:

dim a(28)
a(12) = 200
a(13) = 201
a(14) = 202
setcan a, 4, 3
setcan a, 1, 100
putcan a

Remarks

Even though, PUTCAN needs only 16 bytes of the array, it has to be as long as a GETCAN array. This enables applications to receive a frame using GETCAN, do some modifications and send it out without having to copy something. When everything's gone right, PUTCAN sets LASTERR to ERR_OK (0). If the argument of PUTCAN was wrong (e.g. it wasn't an array), PUTCAN sets LASTERR to ERR_ARGUMENT (4). PUTCAN does not buffer CAN frames. They are immediately sent to the hardware transmitter. If the transmitter is busy, PUTCAN does some retries befor giving up. In this case, LASTERR becomes ERR_REJECTED (12). The application is free to re-send the frame or ignore that error. See also the GETCAN and SETCAN pages.