Aria  2.8.0
ArSerialConnection Class Reference

Utility for connecting to and communicating with devices through a serial port. More...

#include <ArSerialConnection.h>

Inherits ArDeviceConnection.

Public Types

enum  Open {
  OPEN_COULD_NOT_OPEN_PORT = 1, OPEN_COULD_NOT_SET_UP_PORT, OPEN_INVALID_BAUD_RATE, OPEN_COULD_NOT_SET_BAUD,
  OPEN_ALREADY_OPEN
}
 
- Public Types inherited from ArDeviceConnection
enum  Status {
  STATUS_NEVER_OPENED = 1, STATUS_OPEN, STATUS_OPEN_FAILED, STATUS_CLOSED_NORMALLY,
  STATUS_CLOSED_ERROR
}
 

Public Member Functions

 ArSerialConnection (bool is422=false)
 Constructor.
 
virtual bool close (void)
 
int getBaud (void)
 Gets what the current baud rate is set to. More...
 
bool getCTS (void)
 Sees how the CTS line is set (true = high)
 
bool getDCD (void)
 Sees how the DCD line is set (true = high)
 
bool getDSR (void)
 Sees how the DSR line is set (true = high)
 
bool getHardwareControl (void)
 Gets whether the hardware control lines are enabled or disabled. More...
 
virtual const char * getOpenMessage (int messageNumber)
 
const char * getPort (void)
 Gets the port this is using. More...
 
bool getRing (void)
 Sees how the Ring line is set (true = high)
 
virtual int getStatus (void)
 
virtual ArTime getTimeRead (int index)
 
int internalOpen (void)
 
virtual bool isTimeStamping (void)
 
int open (const char *port=NULL)
 Opens the serial port. More...
 
virtual bool openSimple (void)
 
virtual int read (const char *data, unsigned int size, unsigned int msWait=0)
 
bool setBaud (int baud)
 Sets the BAUD rate to use when connection is opened, or change the baud rate if already opened. More...
 
bool setHardwareControl (bool hardwareControl)
 Sets whether to enable or disable the hardware control lines. More...
 
void setPort (const char *port=NULL)
 Sets the port this connection will use. More...
 
virtual int write (const char *data, unsigned int size)
 
virtual ~ArSerialConnection ()
 Destructor also closes the connection.
 
- Public Member Functions inherited from ArDeviceConnection
 ArDeviceConnection ()
 constructor More...
 
void debugBytesRead (int bytesRead)
 Notifies the device connection that some bytes were read (should call with 0 if it read but got no bytes)
 
void debugEndPacket (bool goodPacket, int type=0)
 Notifies the device connection that the end of a packet was read, which will cause log messages if set to do so.
 
void debugStartPacket (void)
 Notifies the device connection that the start of a packet is trying to be read.
 
const char * getDeviceName (void) const
 Gets the device type (what this is connecting to)
 
const char * getPortName (void) const
 Gets the port name.
 
const char * getPortType (void) const
 Gets the port type.
 
const char * getStatusMessage (int messageNumber) const
 Gets the description string associated with the status. More...
 
void setDeviceName (const char *deviceName)
 Sets the device type (what this is connecting to)
 
virtual int writePacket (ArBasePacket *packet)
 Writes data to connection. More...
 
virtual ~ArDeviceConnection ()
 destructor also forces a close on the connection
 

Protected Member Functions

int baudToRate (int baud)
 
void buildStrMap (void)
 
int rateToBaud (int rate)
 
void startTimeStamping (void)
 
- Protected Member Functions inherited from ArDeviceConnection
void buildStrMap (void)
 
void setPortName (const char *portName)
 Sets the port name.
 
void setPortType (const char *portType)
 Sets the port type.
 

Protected Attributes

int myBaudRate
 
bool myHardwareControl
 
bool myIs422
 
int myPort
 
std::string myPortName
 
int myStatus
 
ArStrMap myStrMap
 
bool myTakingTimeStamps
 
- Protected Attributes inherited from ArDeviceConnection
int myDCDebugBytesRead
 
ArTime myDCDebugFirstByteTime
 
ArTime myDCDebugLastByteTime
 
long long myDCDebugNumBadPackets
 
long long myDCDebugNumGoodPackets
 
bool myDCDebugPacketStarted
 
ArTime myDCDebugStartTime
 
int myDCDebugTimesRead
 
std::string myDCDeviceName
 
std::string myDCPortName
 
std::string myDCPortType
 

Additional Inherited Members

- Static Public Member Functions inherited from ArDeviceConnection
static bool debugShouldLog (bool shouldLog)
 Makes all device connections so that they'll dump data.
 
- Static Protected Attributes inherited from ArDeviceConnection
static ArTime ourDCDebugFirstTime
 
static bool ourDCDebugShouldLog = false
 
static ArStrMap ourStrMap
 
static bool ourStrMapInited = false
 

Detailed Description

Utility for connecting to and communicating with devices through a serial port.

Examples:
dpptuExample.cpp.

Member Enumeration Documentation

◆ Open

Enumerator
OPEN_COULD_NOT_OPEN_PORT 

Could not open the port.

OPEN_COULD_NOT_SET_UP_PORT 

Could not set up the port.

OPEN_INVALID_BAUD_RATE 

Baud rate is not valid.

OPEN_COULD_NOT_SET_BAUD 

Baud rate valid, but could not set it.

OPEN_ALREADY_OPEN 

Connection was already open.

Member Function Documentation

◆ getBaud()

int ArSerialConnection::getBaud ( void  )

Gets what the current baud rate is set to.

Returns
the current baud rate of the connection

◆ getHardwareControl()

bool ArSerialConnection::getHardwareControl ( void  )

Gets whether the hardware control lines are enabled or disabled.

Returns
true if hardware control of lines is enabled, false otherwise

◆ getPort()

const char * ArSerialConnection::getPort ( void  )

Gets the port this is using.

See also
ArUtil::COM1, ArUtil::COM2, ArUtil::COM3, ArUtil::COM4
Returns
The serial port to connect to
The seiral port to connect to

◆ open()

int ArSerialConnection::open ( const char *  port = NULL)

Opens the serial port.

Returns
0 on success. Return one of the error codes in the ArSerialConnection::Open enumeration on error.
See also
ArUtil::COM1, ArUtil::COM2, ArUtil::COM3, ArUtil::COM4
Parameters
portThe serial port to connect to, or NULL which defaults to COM1 for windows and /dev/ttyS0 for linux
Returns
0 for success, otherwise one of the open enums
See also
getOpenMessage

◆ setBaud()

bool ArSerialConnection::setBaud ( int  baud)

Sets the BAUD rate to use when connection is opened, or change the baud rate if already opened.

Parameters
baudthe baud rate to set the connection to
Returns
true if rate was sucessfully set, false otherwise (unsupported rate, system error changing rate on port, etc.)
See also
getBaud()

◆ setHardwareControl()

bool ArSerialConnection::setHardwareControl ( bool  hardwareControl)

Sets whether to enable or disable the hardware control lines.

Parameters
hardwareControltrue to enable hardware control of lines
Returns
true if the set succeeded

◆ setPort()

void ArSerialConnection::setPort ( const char *  port = NULL)

Sets the port this connection will use.

See also
ArUtil::COM1, ArUtil::COM2, ArUtil::COM3, ArUtil::COM4
Parameters
portThe serial port to connect to, or NULL which defaults to COM1 for windows and /dev/ttyS0 for linux
See also
getOpenMessage
Parameters
portThe serial port to connect to, or NULL which defaults to COM1 for windows and /dev/ttyS0 for linux
Returns
0 for success, otherwise one of the open enums
See also
getOpenMessage

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