WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
CAN API Functions

Classes

struct  HAL_CANMessage
struct  HAL_CANReceiveMessage

Macros

#define HAL_CAN_SEND_PERIOD_NO_REPEAT   0
 Flag for sending a CAN message once.
#define HAL_CAN_SEND_PERIOD_STOP_REPEATING   -1
 Flag for stopping periodic CAN message sends.
#define HAL_CAN_IS_FRAME_REMOTE   0x40000000
 Mask for "is frame remote" in message ID.
#define HAL_CAN_IS_FRAME_11BIT   0x80000000
 Mask for "is frame 11 bits" in message ID.

Enumerations

enum  HAL_CANDeviceType : int32_t {
  HAL_CAN_DEV_BROADCAST = 0 , HAL_CAN_DEV_ROBOT_CONTROLLER = 1 , HAL_CAN_DEV_MOTOR_CONTROLLER = 2 , HAL_CAN_DEV_RELAY_CONTROLLER = 3 ,
  HAL_CAN_DEV_GYRO_SENSOR = 4 , HAL_CAN_DEV_ACCELEROMETER = 5 , HAL_CAN_DEV_DISTANCE_SENSOR = 6 , HAL_CAN_DEV_ENCODER = 7 ,
  HAL_CAN_DEV_POWER_DISTRIBUTION = 8 , HAL_CAN_DEV_PNEUMATICS = 9 , HAL_CAN_DEV_MISCELLANEOUS = 10 , HAL_CAN_DEV_IO_BREAKOUT = 11 ,
  HAL_CAN_DEV_SERVO_CONTROLLER = 12 , HAL_CAN_DEV_COLOR_SENSOR = 13 , HAL_CAN_DEV_FIRMWARE_UPDATE = 31
}
 The CAN device type. More...
enum  HAL_CANManufacturer : int32_t {
  HAL_CAN_MAN_BROADCAST = 0 , HAL_CAN_MAN_NI = 1 , HAL_CAN_MAN_LM = 2 , HAL_CAN_MAN_DEKA = 3 ,
  HAL_CAN_MAN_CTRE = 4 , HAL_CAN_MAN_REV = 5 , HAL_CAN_MAN_GRAPPLE = 6 , HAL_CAN_MAN_MS = 7 ,
  HAL_CAN_MAN_TEAM_USE = 8 , HAL_CAN_MAN_KAUAI_LABS = 9 , HAL_CAN_MAN_COPPERFORGE = 10 , HAL_CAN_MAN_PWF = 11 ,
  HAL_CAN_MAN_STUDICA = 12 , HAL_CAN_MAN_THRIFTYBOT = 13 , HAL_CAN_MAN_REDUX_ROBOTICS = 14 , HAL_CAN_MAN_ANDYMARK = 15 ,
  HAL_CAN_MAN_VIVID_HOSTING = 16 , HAL_CAN_MAN_VERTOS_ROBOTICS = 17 , HAL_CAN_MAN_SWYFT_ROBOTICS = 18 , HAL_CAN_MAN_LUMYN_LABS = 19 ,
  HAL_CAN_MAN_BRUSHLAND_LABS = 20
}
 The CAN manufacturer ID. More...
enum  HAL_CANFlags : int32_t { HAL_CAN_NO_FLAGS = 0x0 , HAL_CAN_FD_BITRATESWITCH = 0x1 , HAL_CAN_FD_DATALENGTH = 0x2 }
enum  HAL_CANBusMap : int32_t {
  HAL_CAN_BUS_S0 = 0 , HAL_CAN_BUS_S1 = 1 , HAL_CAN_BUS_S2 = 2 , HAL_CAN_BUS_S3 = 3 ,
  HAL_CAN_BUS_S4 = 4 , HAL_CAN_BUS_D0 = 5 , HAL_CAN_BUS_D1 = 6 , HAL_CAN_BUS_D2 = 7 ,
  HAL_CAN_BUS_D3 = 8 , HAL_CAN_BUS_D4 = 9 , HAL_CAN_BUS_D5 = 10 , HAL_CAN_BUS_D6 = 11 ,
  HAL_CAN_BUS_D7 = 12 , HAL_CAN_BUS_D8 = 13 , HAL_CAN_BUS_D9 = 14 , HAL_CAN_BUS_D10 = 15 ,
  HAL_CAN_BUS_D11 = 16 , HAL_CAN_BUS_D12 = 17 , HAL_CAN_BUS_D13 = 18 , HAL_CAN_BUS_D14 = 19 ,
  HAL_CAN_BUS_D15 = 20 , HAL_CAN_BUS_D16 = 21 , HAL_CAN_BUS_D17 = 22 , HAL_CAN_BUS_D18 = 23 ,
  HAL_CAN_BUS_D19 = 24
}

Functions

HAL_CANHandle HAL_InitializeCAN (int32_t busId, HAL_CANManufacturer manufacturer, int32_t deviceId, HAL_CANDeviceType deviceType, int32_t *status)
 Initializes a CAN device.
void HAL_CleanCAN (HAL_CANHandle handle)
 Frees a CAN device.
void HAL_WriteCANPacket (HAL_CANHandle handle, int32_t apiId, const struct HAL_CANMessage *message, int32_t *status)
 Writes a packet to the CAN device with a specific ID.
void HAL_WriteCANPacketRepeating (HAL_CANHandle handle, int32_t apiId, const struct HAL_CANMessage *message, int32_t repeatMs, int32_t *status)
 Writes a repeating packet to the CAN device with a specific ID.
void HAL_WriteCANRTRFrame (HAL_CANHandle handle, int32_t apiId, const struct HAL_CANMessage *message, int32_t *status)
 Writes an RTR frame of the specified length to the CAN device with the specific ID.
void HAL_StopCANPacketRepeating (HAL_CANHandle handle, int32_t apiId, int32_t *status)
 Stops a repeating packet with a specific ID.
void HAL_ReadCANPacketNew (HAL_CANHandle handle, int32_t apiId, struct HAL_CANReceiveMessage *message, int32_t *status)
 Reads a new CAN packet.
void HAL_ReadCANPacketLatest (HAL_CANHandle handle, int32_t apiId, struct HAL_CANReceiveMessage *message, int32_t *status)
 Reads a CAN packet.
void HAL_ReadCANPacketTimeout (HAL_CANHandle handle, int32_t apiId, struct HAL_CANReceiveMessage *message, int32_t timeoutMs, int32_t *status)
 Reads a CAN packet.

Detailed Description

Macro Definition Documentation

◆ HAL_CAN_IS_FRAME_11BIT

#define HAL_CAN_IS_FRAME_11BIT   0x80000000

Mask for "is frame 11 bits" in message ID.

◆ HAL_CAN_IS_FRAME_REMOTE

#define HAL_CAN_IS_FRAME_REMOTE   0x40000000

Mask for "is frame remote" in message ID.

◆ HAL_CAN_SEND_PERIOD_NO_REPEAT

#define HAL_CAN_SEND_PERIOD_NO_REPEAT   0

Flag for sending a CAN message once.

◆ HAL_CAN_SEND_PERIOD_STOP_REPEATING

#define HAL_CAN_SEND_PERIOD_STOP_REPEATING   -1

Flag for stopping periodic CAN message sends.

Enumeration Type Documentation

◆ HAL_CANBusMap

enum HAL_CANBusMap : int32_t
Enumerator
HAL_CAN_BUS_S0 
HAL_CAN_BUS_S1 
HAL_CAN_BUS_S2 
HAL_CAN_BUS_S3 
HAL_CAN_BUS_S4 
HAL_CAN_BUS_D0 
HAL_CAN_BUS_D1 
HAL_CAN_BUS_D2 
HAL_CAN_BUS_D3 
HAL_CAN_BUS_D4 
HAL_CAN_BUS_D5 
HAL_CAN_BUS_D6 
HAL_CAN_BUS_D7 
HAL_CAN_BUS_D8 
HAL_CAN_BUS_D9 
HAL_CAN_BUS_D10 
HAL_CAN_BUS_D11 
HAL_CAN_BUS_D12 
HAL_CAN_BUS_D13 
HAL_CAN_BUS_D14 
HAL_CAN_BUS_D15 
HAL_CAN_BUS_D16 
HAL_CAN_BUS_D17 
HAL_CAN_BUS_D18 
HAL_CAN_BUS_D19 

◆ HAL_CANDeviceType

enum HAL_CANDeviceType : int32_t

The CAN device type.

Teams should use HAL_CAN_DEV_MISCELLANEOUS

Enumerator
HAL_CAN_DEV_BROADCAST 

Broadcast.

HAL_CAN_DEV_ROBOT_CONTROLLER 

Robot controller.

HAL_CAN_DEV_MOTOR_CONTROLLER 

Motor controller.

HAL_CAN_DEV_RELAY_CONTROLLER 

Relay controller.

HAL_CAN_DEV_GYRO_SENSOR 

Gyro sensor.

HAL_CAN_DEV_ACCELEROMETER 

Accelerometer.

HAL_CAN_DEV_DISTANCE_SENSOR 

Distance sensor.

HAL_CAN_DEV_ENCODER 

Encoder.

HAL_CAN_DEV_POWER_DISTRIBUTION 

Power distribution.

HAL_CAN_DEV_PNEUMATICS 

Pneumatics.

HAL_CAN_DEV_MISCELLANEOUS 

Miscellaneous.

HAL_CAN_DEV_IO_BREAKOUT 

IO breakout.

HAL_CAN_DEV_SERVO_CONTROLLER 

Servo controller.

HAL_CAN_DEV_COLOR_SENSOR 

Color Sensor.

HAL_CAN_DEV_FIRMWARE_UPDATE 

Firmware update.

◆ HAL_CANFlags

enum HAL_CANFlags : int32_t
Enumerator
HAL_CAN_NO_FLAGS 

Placeholder for no flags.

HAL_CAN_FD_BITRATESWITCH 

Mask for if frame will do FD bit rate switching.

Only matters to send.

HAL_CAN_FD_DATALENGTH 

Mask for is frame will contain an FD length.

◆ HAL_CANManufacturer

enum HAL_CANManufacturer : int32_t

The CAN manufacturer ID.

Teams should use HAL_CAN_MAN_TEAM_USE.

Enumerator
HAL_CAN_MAN_BROADCAST 

Broadcast.

HAL_CAN_MAN_NI 

National Instruments.

HAL_CAN_MAN_LM 

Luminary Micro.

HAL_CAN_MAN_DEKA 

DEKA Research and Development Corp.

HAL_CAN_MAN_CTRE 

Cross the Road Electronics.

HAL_CAN_MAN_REV 

REV robotics.

HAL_CAN_MAN_GRAPPLE 

Grapple.

HAL_CAN_MAN_MS 

MindSensors.

HAL_CAN_MAN_TEAM_USE 

Team use.

HAL_CAN_MAN_KAUAI_LABS 

Kauai Labs.

HAL_CAN_MAN_COPPERFORGE 

Copperforge.

HAL_CAN_MAN_PWF 

Playing With Fusion.

HAL_CAN_MAN_STUDICA 

Studica.

HAL_CAN_MAN_THRIFTYBOT 

TheThriftyBot.

HAL_CAN_MAN_REDUX_ROBOTICS 

Redux Robotics.

HAL_CAN_MAN_ANDYMARK 

AndyMark.

HAL_CAN_MAN_VIVID_HOSTING 

Vivid-Hosting.

HAL_CAN_MAN_VERTOS_ROBOTICS 

Vertos Robotics.

HAL_CAN_MAN_SWYFT_ROBOTICS 

SWYFT Robotics.

HAL_CAN_MAN_LUMYN_LABS 

Lumyn Labs.

HAL_CAN_MAN_BRUSHLAND_LABS 

Brushland Labs.

Function Documentation

◆ HAL_CleanCAN()

void HAL_CleanCAN ( HAL_CANHandle handle)

Frees a CAN device.

Parameters
handlethe CAN handle

◆ HAL_InitializeCAN()

HAL_CANHandle HAL_InitializeCAN ( int32_t busId,
HAL_CANManufacturer manufacturer,
int32_t deviceId,
HAL_CANDeviceType deviceType,
int32_t * status )

Initializes a CAN device.

These follow the FIRST standard CAN layout. https://docs.wpilib.org/en/stable/docs/software/can-devices/can-addressing.html

Parameters
[in]busIdthe bus id
[in]manufacturerthe can manufacturer
[in]deviceIdthe device ID (0-63)
[in]deviceTypethe device type
[out]statusError status variable. 0 on success.
Returns
the created CAN handle

◆ HAL_ReadCANPacketLatest()

void HAL_ReadCANPacketLatest ( HAL_CANHandle handle,
int32_t apiId,
struct HAL_CANReceiveMessage * message,
int32_t * status )

Reads a CAN packet.

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

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to read (0-1023)
[out]messagethe message received.
[out]statusError status variable. 0 on success.

◆ HAL_ReadCANPacketNew()

void HAL_ReadCANPacketNew ( HAL_CANHandle handle,
int32_t apiId,
struct HAL_CANReceiveMessage * message,
int32_t * status )

Reads a new CAN packet.

This will only return properly once per packet received. Multiple calls without receiving another packet will return an error code.

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to read (0-1023)
[out]messagethe message received.
[out]statusError status variable. 0 on success.

◆ HAL_ReadCANPacketTimeout()

void HAL_ReadCANPacketTimeout ( HAL_CANHandle handle,
int32_t apiId,
struct HAL_CANReceiveMessage * message,
int32_t timeoutMs,
int32_t * status )

Reads a CAN packet.

The will return the last packet received until the packet is older then the requested timeout. Then it will return an error code.

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to read (0-1023)
[out]messagethe message received.
[out]timeoutMsthe timeout time for the packet
[out]statusError status variable. 0 on success.

◆ HAL_StopCANPacketRepeating()

void HAL_StopCANPacketRepeating ( HAL_CANHandle handle,
int32_t apiId,
int32_t * status )

Stops a repeating packet with a specific ID.

This ID is 10 bits.

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to stop repeating (0-1023)
[out]statusError status variable. 0 on success.

◆ HAL_WriteCANPacket()

void HAL_WriteCANPacket ( HAL_CANHandle handle,
int32_t apiId,
const struct HAL_CANMessage * message,
int32_t * status )

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

This ID is 10 bits.

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to write (0-1023)
[in]messagethe message
[out]statusError status variable. 0 on success.

◆ HAL_WriteCANPacketRepeating()

void HAL_WriteCANPacketRepeating ( HAL_CANHandle handle,
int32_t apiId,
const struct HAL_CANMessage * message,
int32_t repeatMs,
int32_t * status )

Writes a repeating packet to the CAN device with a specific ID.

This ID is 10 bits.

The device will automatically repeat the packet at the specified interval

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to write (0-1023)
[in]messagethe message
[in]repeatMsthe period to repeat in ms
[out]statusError status variable. 0 on success.

◆ HAL_WriteCANRTRFrame()

void HAL_WriteCANRTRFrame ( HAL_CANHandle handle,
int32_t apiId,
const struct HAL_CANMessage * message,
int32_t * status )

Writes an RTR frame of the specified length to the CAN device with the specific ID.

By spec, the length must be equal to the length sent by the other device, otherwise behavior is unspecified.

Parameters
[in]handlethe CAN handle
[in]apiIdthe ID to write (0-1023)
[in]messagethe message
[out]statusError status variable. 0 on success.