WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
frc::CAN Class Reference

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

#include <frc/CAN.h>

Public Member Functions

 CAN (int busId, int deviceId)
 Create a new CAN communication interface with the specific device ID.
 
 CAN (int busId, int deviceId, int deviceManufacturer, int deviceType)
 Create a new CAN communication interface with a specific device ID, manufacturer and device type.
 
 CAN (CAN &&)=default
 
CANoperator= (CAN &&)=default
 
void WritePacket (int apiId, const HAL_CANMessage &message)
 Write a packet to the CAN device with a specific ID.
 
void WritePacketRepeating (int apiId, const HAL_CANMessage &message, int repeatMs)
 Write a repeating packet to the CAN device with a specific ID.
 
void WriteRTRFrame (int apiId, const HAL_CANMessage &message)
 Write an RTR frame to the CAN device with a specific ID.
 
int WritePacketNoError (int apiId, const HAL_CANMessage &message)
 Write a packet to the CAN device with a specific ID.
 
int WritePacketRepeatingNoError (int apiId, const HAL_CANMessage &message, int repeatMs)
 Write a repeating packet to the CAN device with a specific ID.
 
int WriteRTRFrameNoError (int apiId, const HAL_CANMessage &message)
 Write an RTR frame to the CAN device with a specific ID.
 
void StopPacketRepeating (int apiId)
 Stop a repeating packet with a specific ID.
 
bool ReadPacketNew (int apiId, HAL_CANReceiveMessage *data)
 Read a new CAN packet.
 
bool ReadPacketLatest (int apiId, HAL_CANReceiveMessage *data)
 Read a CAN packet.
 
bool ReadPacketTimeout (int apiId, int timeoutMs, HAL_CANReceiveMessage *data)
 Read a CAN packet.
 

Static Public Attributes

static constexpr HAL_CANManufacturer kTeamManufacturer = HAL_CAN_Man_kTeamUse
 Team manufacturer.
 
static constexpr HAL_CANDeviceType kTeamDeviceType
 Team device type.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CAN() [1/3]

frc::CAN::CAN ( int busId,
int deviceId )

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
busIdThe bus id
deviceIdThe device id

◆ CAN() [2/3]

frc::CAN::CAN ( int busId,
int deviceId,
int deviceManufacturer,
int deviceType )

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
busIdThe bus id
deviceIdThe device ID
deviceManufacturerThe device manufacturer
deviceTypeThe device type

◆ CAN() [3/3]

frc::CAN::CAN ( CAN && )
default

Member Function Documentation

◆ operator=()

CAN & frc::CAN::operator= ( CAN && )
default

◆ ReadPacketLatest()

bool frc::CAN::ReadPacketLatest ( int apiId,
HAL_CANReceiveMessage * data )

Read a CAN packet.

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

Parameters
apiIdThe API ID to read.
dataStorage for the received data.
Returns
True if the data is valid, otherwise false.

◆ ReadPacketNew()

bool frc::CAN::ReadPacketNew ( int apiId,
HAL_CANReceiveMessage * data )

Read a new CAN packet.

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

Parameters
apiIdThe API ID to read.
dataStorage for the received data.
Returns
True if the data is valid, otherwise false.

◆ ReadPacketTimeout()

bool frc::CAN::ReadPacketTimeout ( int apiId,
int timeoutMs,
HAL_CANReceiveMessage * data )

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
apiIdThe API ID to read.
timeoutMsThe timeout time for the packet
dataStorage for the received data.
Returns
True if the data is valid, otherwise false.

◆ StopPacketRepeating()

void frc::CAN::StopPacketRepeating ( int apiId)

Stop a repeating packet with a specific ID.

This ID is 10 bits.

Parameters
apiIdThe API ID to stop repeating

◆ WritePacket()

void frc::CAN::WritePacket ( int apiId,
const HAL_CANMessage & message )

Write a packet to the CAN device with a specific ID.

This ID is 10 bits.

Parameters
apiIdThe API ID to write.
messagethe CAN message.

◆ WritePacketNoError()

int frc::CAN::WritePacketNoError ( int apiId,
const HAL_CANMessage & message )

Write a packet to the CAN device with a specific ID.

This ID is 10 bits.

Parameters
apiIdThe API ID to write.
messagethe CAN message.

◆ WritePacketRepeating()

void frc::CAN::WritePacketRepeating ( int apiId,
const HAL_CANMessage & message,
int repeatMs )

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
apiIdThe API ID to write.
messagethe CAN message.
repeatMsThe period to repeat the packet at.

◆ WritePacketRepeatingNoError()

int frc::CAN::WritePacketRepeatingNoError ( int apiId,
const HAL_CANMessage & message,
int repeatMs )

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
apiIdThe API ID to write.
messagethe CAN message.
repeatMsThe period to repeat the packet at.

◆ WriteRTRFrame()

void frc::CAN::WriteRTRFrame ( int apiId,
const HAL_CANMessage & message )

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
apiIdThe API ID to write.
messagethe CAN message.

◆ WriteRTRFrameNoError()

int frc::CAN::WriteRTRFrameNoError ( int apiId,
const HAL_CANMessage & message )

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
apiIdThe API ID to write.
messagethe CAN message.

Member Data Documentation

◆ kTeamDeviceType

HAL_CANDeviceType frc::CAN::kTeamDeviceType
staticconstexpr
Initial value:
=
@ HAL_CAN_Dev_kMiscellaneous
Miscellaneous.
Definition CANAPITypes.h:44

Team device type.

◆ kTeamManufacturer

HAL_CANManufacturer frc::CAN::kTeamManufacturer = HAL_CAN_Man_kTeamUse
staticconstexpr

Team manufacturer.


The documentation for this class was generated from the following file: