WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::CAN Class Reference

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

#include <CAN.h>

Inheritance diagram for frc::CAN:
frc::ErrorBase

Public Member Functions

 CAN (int deviceId)
 Create a new CAN communication interface with the specific device ID. More...
 
 CAN (int deviceId, int deviceManufacturer, int deviceType)
 Create a new CAN communication interface with a specific device ID, manufacturer and device type. More...
 
 ~CAN () override
 Closes the CAN communication.
 
 CAN (CAN &&rhs)
 
CANoperator= (CAN &&rhs)
 
void WritePacket (const uint8_t *data, int length, int apiId)
 Write a packet to the CAN device with a specific ID. More...
 
void WritePacketRepeating (const uint8_t *data, int length, int apiId, int repeatMs)
 Write a repeating packet to the CAN device with a specific ID. More...
 
void StopPacketRepeating (int apiId)
 Stop a repeating packet with a specific ID. More...
 
bool ReadPacketNew (int apiId, CANData *data)
 Read a new CAN packet. More...
 
bool ReadPacketLatest (int apiId, CANData *data)
 Read a CAN packet. More...
 
bool ReadPacketTimeout (int apiId, int timeoutMs, CANData *data)
 Read a CAN packet. More...
 
bool ReadPeriodicPacket (int apiId, int timeoutMs, int periodMs, CANData *data)
 Read a CAN packet. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Static Public Attributes

static constexpr
HAL_CANManufacturer 
kTeamManufacturer = HAL_CAN_Man_kTeamUse
 
static constexpr HAL_CANDeviceType kTeamDeviceType
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static const ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

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

frc::CAN::CAN ( int  deviceId)
explicit

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
deviceIdThe device id
frc::CAN::CAN ( 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
deviceIdThe device ID
deviceManufacturerThe device manufacturer
deviceTypeThe device type

Member Function Documentation

bool frc::CAN::ReadPacketLatest ( int  apiId,
CANData 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.
bool frc::CAN::ReadPacketNew ( int  apiId,
CANData 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.
bool frc::CAN::ReadPacketTimeout ( int  apiId,
int  timeoutMs,
CANData 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.
bool frc::CAN::ReadPeriodicPacket ( int  apiId,
int  timeoutMs,
int  periodMs,
CANData 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. The period parameter is used when you know the packet is sent at specific intervals, so calls will not attempt to read a new packet from the network until that period has passed. We do not recommend users use this API unless they know the implications.

Parameters
apiIdThe API ID to read.
timeoutMsThe timeout time for the packet
periodMsThe usual period for the packet
dataStorage for the received data.
Returns
True if the data is valid, otherwise false.
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
void frc::CAN::WritePacket ( const uint8_t *  data,
int  length,
int  apiId 
)

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

This ID is 10 bits.

Parameters
dataThe data to write (8 bytes max)
lengthThe data length to write
apiIdThe API ID to write.
void frc::CAN::WritePacketRepeating ( const uint8_t *  data,
int  length,
int  apiId,
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
dataThe data to write (8 bytes max)
lengthThe data length to write
apiIdThe API ID to write.
repeatMsThe period to repeat the packet at.

Member Data Documentation

constexpr HAL_CANDeviceType frc::CAN::kTeamDeviceType
static
Initial value:
=
HAL_CAN_Dev_kMiscellaneous

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