CAN

class wpilib.CAN(*args, **kwargs)

Bases: wpilib.ErrorBase

High level class for interfacing with CAN devices conforming to the standard CAN spec.

No packets that can be sent gets blocked by the RoboRIO, so all methods work identically in all robot modes.

All methods are thread save, however the buffer objects passed in by the user need to not be modified for the duration of their calls.

Overloaded function.

  1. __init__(self: wpilib._wpilib.CAN, deviceId: int) -> None

Create a new CAN communication interface with the specific device ID. This uses the team manufacturer and device types. The device ID is 6 bits (0-63)

Parameters

deviceId – The device id

  1. __init__(self: wpilib._wpilib.CAN, deviceId: int, deviceManufacturer: int, deviceType: int) -> None

Create a new CAN communication interface with a specific device ID, manufacturer and device type. The device ID is 6 bits, the manufacturer is 8 bits, and the device type is 5 bits.

Parameters
  • deviceId – The device ID

  • deviceManufacturer – The device manufacturer

  • deviceType – The device type

kTeamDeviceType = <CANDeviceType.kMiscellaneous: 10>
kTeamManufacturer = <CANManufacturer.kTeamUse: 8>
readPacketLatest(self: wpilib.CAN, apiId: int, data: wpilib.CANData) → bool

Read a CAN packet. The will continuously return the last packet received, without accounting for packet age.

Parameters
  • apiId – The API ID to read.

  • data – Storage for the received data.

Returns

True if the data is valid, otherwise false.

readPacketNew(self: wpilib.CAN, apiId: int, data: wpilib.CANData) → bool

Read a new CAN packet. This will only return properly once per packet received. Multiple calls without receiving another packet will return false.

Parameters
  • apiId – The API ID to read.

  • data – Storage for the received data.

Returns

True if the data is valid, otherwise false.

readPacketTimeout(self: wpilib.CAN, apiId: int, timeoutMs: int, data: wpilib.CANData) → bool

Read a CAN packet. The will return the last packet received until the packet is older then the requested timeout. Then it will return false.

Parameters
  • apiId – The API ID to read.

  • timeoutMs – The timeout time for the packet

  • data – Storage for the received data.

Returns

True if the data is valid, otherwise false.

stopPacketRepeating(self: wpilib.CAN, apiId: int) → None

Stop a repeating packet with a specific ID. This ID is 10 bits.

Parameters

apiId – The API ID to stop repeating

writePacket(self: wpilib.CAN, data: buffer, apiId: int) → None

Write a packet to the CAN device with a specific ID. This ID is 10 bits.

Parameters
  • data – The data to write (8 bytes max)

  • length – The data length to write

  • apiId – The API ID to write.

writePacketNoError(self: wpilib.CAN, data: int, length: int, apiId: int) → int

Write a packet to the CAN device with a specific ID. This ID is 10 bits.

Parameters
  • data – The data to write (8 bytes max)

  • length – The data length to write

  • apiId – The API ID to write.

writePacketRepeating(self: wpilib.CAN, data: buffer, apiId: int, repeatMs: int) → None

Write a repeating packet to the CAN device with a specific ID. This ID is 10 bits. The RoboRIO will automatically repeat the packet at the specified interval

Parameters
  • data – The data to write (8 bytes max)

  • length – The data length to write

  • apiId – The API ID to write.

  • repeatMs – The period to repeat the packet at.

writePacketRepeatingNoError(self: wpilib.CAN, data: int, length: int, apiId: int, repeatMs: int) → int

Write a repeating packet to the CAN device with a specific ID. This ID is 10 bits. The RoboRIO will automatically repeat the packet at the specified interval

Parameters
  • data – The data to write (8 bytes max)

  • length – The data length to write

  • apiId – The API ID to write.

  • repeatMs – The period to repeat the packet at.

writeRTRFrame(self: wpilib.CAN, length: int, apiId: int) → None

Write an RTR frame to the CAN device with a specific ID. This ID is 10 bits. The length by spec must match what is returned by the responding device

Parameters
  • length – The length to request (0 to 8)

  • apiId – The API ID to write.

writeRTRFrameNoError(self: wpilib.CAN, length: int, apiId: int) → int

Write an RTR frame to the CAN device with a specific ID. This ID is 10 bits. The length by spec must match what is returned by the responding device

Parameters
  • length – The length to request (0 to 8)

  • apiId – The API ID to write.