ClearCore Library
Loading...
Searching...
No Matches
List of all members | Public Member Functions
ClearCore::SerialUsb Class Reference

Detailed Description

ClearCore Serial USB Connector class.

This class provides support for emulated serial communications on the ClearCore's USB port.

For more detailed information on the ClearCore Connector interface, check out the ClearCore Connector System informational page.

ClearCore Serial USB Connector class. More...

#include <SerialUsb.h>

+ Inheritance diagram for ClearCore::SerialUsb:
+ Collaboration diagram for ClearCore::SerialUsb:

Public Member Functions

void Flush () override
 
void FlushInput () override
 
void PortOpen () override
 
void PortClose () override
 
int16_t CharGet () override
 Attempt to read the next character from serial channel.
 
int16_t CharPeek () override
 Attempt to get the next character from the serial channel without pulling the character out of the buffer.
 
bool SendChar (uint8_t charToSend) override
 Send an ascii character on the serial channel.
 
int32_t AvailableForRead () override
 
int32_t AvailableForWrite () override
 Determines the number of characters available in the transmit buffer.
 
void WaitForTransmitIdle () override
 
bool PortIsOpen () override
 Return whether or not the port is open.
 
bool Parity (Parities newParity) override
 Set UART transmission parity format.
 
Parities Parity () override
 Return current port UART transmission parity.
 
bool StopBits (uint8_t bits) override
 Change the number of stop bits used in UART communication.
 
bool CharSize (uint8_t size) override
 Change the number of bits in a character.
 
virtual ConnectorModes Mode () override
 Get the connector's operational mode.
 
bool Mode (ConnectorModes newMode) override
 Set the connector's operational mode.
 
Connector::ConnectorTypes Type () override
 Get connector type.
 
bool IsWritable () override
 Get R/W status of the connector.
 
 operator bool () override
 Returns whether the serial port is open and the other end is connected.
 
- Public Member Functions inherited from ClearCore::ISerial
virtual bool Speed (uint32_t bitsPerSecond)=0
 Change the baud rate for the port.
 
virtual uint32_t Speed ()=0
 Gets the baud rate of the port.
 
bool SendLine ()
 Send carriage return and newline characters.
 
bool Send (const char *buffer, size_t bufferSize)
 Send the array of characters out the port.
 
bool SendLine (const char *buffer, size_t bufferSize)
 Send the array of characters out the port. Terminate the line with carriage return and newline characters.
 
bool Send (const char *nullTermStr)
 Send a string of characters out the port.
 
bool SendLine (const char *nullTermStr)
 Send a string of characters out the port. Terminate the line with carriage return and newline characters.
 
bool Send (char theChar)
 Send a character to be printed to the serial port.
 
bool SendLine (char theChar)
 Send a character to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (double number, uint8_t precision=2)
 Send a floating point number to the serial port.
 
bool SendLine (double number, uint8_t precision=2)
 Send a floating point number to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (int8_t number, uint8_t radix=10)
 Send an 8-bit signed number to be printed to the serial port.
 
bool SendLine (int8_t number, uint8_t radix=10)
 Send an 8-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (uint8_t number, uint8_t radix=10)
 Send an 8-bit unsigned number to be printed to the serial port.
 
bool SendLine (uint8_t number, uint8_t radix=10)
 Send an 8-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (int16_t number, uint8_t radix=10)
 Send a 16-bit signed number to be printed to the serial port.
 
bool SendLine (int16_t number, uint8_t radix=10)
 Send a 16-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (uint16_t number, uint8_t radix=10)
 Send a 16-bit unsigned number to be printed to the serial port.
 
bool SendLine (uint16_t number, uint8_t radix=10)
 Send a 16-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (int32_t number, uint8_t radix=10)
 Send a 32-bit signed number to be printed to the serial port.
 
bool SendLine (int32_t number, uint8_t radix=10)
 Send a 32-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (uint32_t number, uint8_t radix=10)
 Send a 32-bit unsigned number to be printed to the serial port.
 
bool SendLine (uint32_t number, uint8_t radix=10)
 Send a 32-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters.
 
bool Send (int number, uint8_t radix=10)
 Send an integer to be printed to the serial port.
 
bool SendLine (int number, uint8_t radix=10)
 Send an integer to be printed to the serial port.
 
- Public Member Functions inherited from ClearCore::Connector
void Reinitialize ()
 Reinitialize this connector to the power-up state.
 
int32_t ConnectorIndex ()
 Accessor for the bit index of this connector in the input register.
 
virtual int16_t State ()=0
 Get the connector's last sampled value.
 
virtual bool State (int16_t newState)=0
 Set the state of a R/W connector.
 
virtual bool IsInHwFault ()=0
 Get whether the connector is in a hardware fault state.
 
uint32_t InputRegMask ()
 Get a bit mask representing this connector.
 

Additional Inherited Members

- Public Types inherited from ClearCore::ISerial
enum  _Parities { PARITY_E = 0 , PARITY_O , PARITY_N }
 
typedef enum ClearCore::ISerial::_Parities Parities
 
- Public Types inherited from ClearCore::Connector
enum  ConnectorModes {
  INVALID_NONE , INPUT_ANALOG , INPUT_DIGITAL , OUTPUT_ANALOG ,
  OUTPUT_DIGITAL , OUTPUT_H_BRIDGE , OUTPUT_PWM , OUTPUT_TONE ,
  OUTPUT_WAVE , CPM_MODE_A_DIRECT_B_DIRECT , CPM_MODE_STEP_AND_DIR , CPM_MODE_A_DIRECT_B_PWM ,
  CPM_MODE_A_PWM_B_PWM , TTL , RS232 , SPI ,
  CCIO , USB_CDC
}
 All possible operational modes for a connector. More...
 
enum  ConnectorTypes {
  DIGITAL_IN_TYPE , DIGITAL_IN_OUT_TYPE , SHIFT_REG_TYPE , ANALOG_IN_DIGITAL_IN_TYPE ,
  ANALOG_OUT_DIGITAL_IN_OUT_TYPE , H_BRIDGE_TYPE , CPM_TYPE , SERIAL_TYPE ,
  SERIAL_USB_TYPE , CCIO_DIGITAL_IN_OUT_TYPE
}
 The different types of ClearCore connectors. More...
 

Member Function Documentation

◆ AvailableForRead()

int32_t ClearCore::SerialUsb::AvailableForRead ( )
overridevirtual

Returns number of characters waiting in the receive buffer.

Implements ClearCore::ISerial.

◆ AvailableForWrite()

int32_t ClearCore::SerialUsb::AvailableForWrite ( )
overridevirtual

Determines the number of characters available in the transmit buffer.

// There are less than 10 free characters in COM-0's transmit buffer
}
int32_t AvailableForWrite() override
Determines the number of characters available in the transmit buffer.
SerialDriver ConnectorCOM0
COM-0 connector instance.
Returns
Returns number of free characters in transmit buffer

Currently hard-coded to one packet size. While more data can be sent, this is the maximum amount of data that will be buffered. Writing anything larger will require the data pointer to remain valid during the writing.

Implements ClearCore::ISerial.

◆ CharGet()

int16_t ClearCore::SerialUsb::CharGet ( )
overridevirtual

Attempt to read the next character from serial channel.

Returns
Returns the first character in the serial buffer, or SerialBase::EOB if no data are available. If a character is found, it will be consumed and removed from the serial buffer.

Implements ClearCore::ISerial.

◆ CharPeek()

int16_t ClearCore::SerialUsb::CharPeek ( )
overridevirtual

Attempt to get the next character from the serial channel without pulling the character out of the buffer.

Returns
Returns the first character in the serial buffer, or SerialBase::EOB if no data are available. If a character is found, it will not be consumed, and will remain in the serial buffer for reading.

Implements ClearCore::ISerial.

◆ CharSize()

bool ClearCore::SerialUsb::CharSize ( uint8_t  size)
inlineoverridevirtual

Change the number of bits in a character.

For USB Serial ports, only 8-bit characters are supported.

Implements ClearCore::ISerial.

◆ Flush()

void ClearCore::SerialUsb::Flush ( )
overridevirtual

Flush the serial port's transmit buffer

// Flush COM-0's transmit buffer
void Flush() override

Blocks until data in the write buffer is sent.

Implements ClearCore::ISerial.

◆ FlushInput()

void ClearCore::SerialUsb::FlushInput ( )
overridevirtual

Flush the serial port's receive buffer

// Flush COM-0's receive buffer
void FlushInput() override

Implements ClearCore::ISerial.

◆ IsWritable()

bool ClearCore::SerialUsb::IsWritable ( )
inlineoverridevirtual

Get R/W status of the connector.

Returns
True if the port is open.

Implements ClearCore::Connector.

◆ Mode() [1/2]

virtual ConnectorModes ClearCore::SerialUsb::Mode ( )
inlineoverridevirtual

◆ Mode() [2/2]

bool ClearCore::SerialUsb::Mode ( ConnectorModes  newMode)
inlineoverridevirtual

Set the connector's operational mode.

Parameters
[in]newModeThe new mode to be set. The only valid mode is USB_CDC.
Returns
Returns false if the mode is invalid or setup fails.

Implements ClearCore::Connector.

◆ operator bool()

ClearCore::SerialUsb::operator bool ( )
overridevirtual

Returns whether the serial port is open and the other end is connected.

ClearCore uses the virtual serial port DTR flag to recognize that the USB host is connected and listening. If DTR is not asserted, no characters will be sent by the SerialUsb Send functions.

while (!ConnectorUsb) {
continue;
}
ConnectorUsb.Send("USB Serial is now connected and host is listening.");
bool Send(const char *buffer, size_t bufferSize)
Send the array of characters out the port.
Definition ISerial.h:173
void PortOpen() override
SerialUsb ConnectorUsb
USB connector instance.
Returns
Returns true if the port is open and DTR is asserted.

Implements ClearCore::ISerial.

◆ Parity() [1/2]

Parities ClearCore::SerialUsb::Parity ( )
inlineoverridevirtual

Return current port UART transmission parity.

Returns
Returns transmission parity enumeration.

Implements ClearCore::ISerial.

◆ Parity() [2/2]

bool ClearCore::SerialUsb::Parity ( Parities  newParity)
inlineoverridevirtual

Set UART transmission parity format.

Returns
Returns true if port accepted the format change request.

Implements ClearCore::ISerial.

◆ PortClose()

void ClearCore::SerialUsb::PortClose ( )
overridevirtual

Shut down the port

// Close COM-0's serial port
void PortClose() override

Implements ClearCore::ISerial.

◆ PortIsOpen()

bool ClearCore::SerialUsb::PortIsOpen ( )
overridevirtual

Return whether or not the port is open.

// COM-0's port is currently open
}
bool PortIsOpen() override
Return whether or not the port is open.
Returns
True if the port is open, and false otherwise.

Implements ClearCore::ISerial.

◆ PortOpen()

void ClearCore::SerialUsb::PortOpen ( )
overridevirtual

◆ SendChar()

bool ClearCore::SerialUsb::SendChar ( uint8_t  charToSend)
overridevirtual

Send an ascii character on the serial channel.

Parameters
[in]charToSendThe character to be sent
Returns
success
Note
No characters will be sent if DTR is not asserted.

Implements ClearCore::ISerial.

◆ StopBits()

bool ClearCore::SerialUsb::StopBits ( uint8_t  bits)
inlineoverridevirtual

Change the number of stop bits used in UART communication.

For USB Serial ports, only 1 stop bit is supported.

Implements ClearCore::ISerial.

◆ Type()

Connector::ConnectorTypes ClearCore::SerialUsb::Type ( )
inlineoverridevirtual

Get connector type.

Returns
The type of the current connector.

Implements ClearCore::Connector.

◆ WaitForTransmitIdle()

void ClearCore::SerialUsb::WaitForTransmitIdle ( )
overridevirtual

Wait for transmission idle.

Implements ClearCore::ISerial.


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