IGSTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

igstk::SerialCommunication Class Reference

This class implements communication over a serial port via RS-232. More...

#include <igstkSerialCommunication.h>

Inheritance diagram for igstk::SerialCommunication:
Inheritance graph
[legend]
Collaboration diagram for igstk::SerialCommunication:
Collaboration graph
[legend]

List of all members.

Public Types

enum  PortNumberType {
  PortNumber0 = 0, PortNumber1 = 1, PortNumber2 = 2, PortNumber3 = 3,
  PortNumber4 = 4, PortNumber5 = 5, PortNumber6 = 6, PortNumber7 = 7
}
 

Available port numbers.

More...
enum  BaudRateType {
  BaudRate9600 = 9600, BaudRate19200 = 19200, BaudRate38400 = 38400, BaudRate57600 = 57600,
  BaudRate115200 = 115200
}
 

Available baud rates.

More...
enum  DataBitsType { DataBits7 = 7, DataBits8 = 8 }
 

Available data bits settings.

More...
enum  ParityType { NoParity = 'N', OddParity = 'O', EvenParity = 'E' }
 

Available parity settings.

More...
enum  StopBitsType { StopBits1 = 1, StopBits2 = 2 }
 

Available stop bits settings.

More...
enum  HandshakeType { HandshakeOff = 0, HandshakeOn = 1 }
 

Available hardware handshaking settings.

More...
typedef Communication::ResultType ResultType

Public Member Functions

 igstkStandardClassBasicTraitsMacro (SerialCommunication, Communication)
 Standard traits of a basic class.
virtual void SetPortNumber (PortNumberType _arg)
 Specify which serial port to use.
virtual PortNumberType GetPortNumber ()
 Get the serial port, where the ports are numbered 0 through 3.
virtual void SetBaudRate (BaudRateType _arg)
 Set the baud rate to use.
virtual BaudRateType GetBaudRate ()
 Get the baud rate.
virtual void SetDataBits (DataBitsType _arg)
 Set the number of bits per character.
virtual DataBitsType GetDataBits ()
 Get the number of bits per character.
virtual void SetParity (ParityType _arg)
 Set the parity.
virtual ParityType GetParity ()
 Get the parity.
virtual void SetStopBits (StopBitsType _arg)
 Set the number of stop bits.
virtual StopBitsType GetStopBits ()
 Get the number of stop bits.
virtual void SetHardwareHandshake (HandshakeType _arg)
 Set whether to use hardware handshaking.
virtual HandshakeType GetHardwareHandshake ()
 Get whether hardware handshaking is enabled.
void SetCaptureFileName (const char *filename)
 Set the name of the file into which the data stream is recorded.
const char * GetCaptureFileName () const
 Get the filename into which the data stream is recorded.
virtual void SetCapture (bool _arg)
 Set whether to record the data.
virtual bool GetCapture ()
 Get whether the data is being recorded.
ResultType UpdateParameters (void)
 Update the communication parameters, in case you need to change the baud rate, handshaking, timeout, etc.
ResultType OpenCommunication (void)
 The method OpenCommunication sets up communication as per the data provided.
ResultType CloseCommunication (void)
 The method CloseCommunication closes the communication.
ResultType SetRTS (unsigned int signal)
 Set the RTS value 0 : Clear the RTS (request-to-send) signal 1 : Sends the RTS signal.
ResultType Write (const char *message, unsigned int numberOfBytes)
 Write method sends the string via the communication link.
ResultType Read (char *data, unsigned int numberOfBytes, unsigned int &bytesRead)
 Read method receives the string via the communication link.
ResultType SendBreak (void)
 Send a break in the serial communication, which by definition is a series of zeroes that lasts for a 0.3 second duration.
ResultType PurgeBuffers (void)
 Purge the contents of the buffers.
void Sleep (unsigned int milliseconds)
 Sleep for the specified number of milliseconds.
void ExportStateMachineDescription (OutputStreamType &ostr, bool skipLoops=false) const
 Declarations related to the State Machine.
void SetLogger (LoggerType *logger)
 Connect the Logger for this class.

Static Public Member Functions

static Pointer New (void)
 Customized New method that will return the implementation of SerialCommunication that is appropriate for this platform.

Protected Member Functions

LoggerTypeGetLogger () const
 Declarations related to the Logger.
 SerialCommunication ()
 ~SerialCommunication ()
virtual ResultType InternalOpenPort (void)
 Opens serial port for communication;.
virtual ResultType InternalUpdateParameters (void)
 Set communication parameters on the open port.
virtual ResultType InternalClosePort (void)
 Closes serial port.
virtual ResultType InternalSetRTS (unsigned int)
 Closes serial port.
virtual ResultType InternalWrite (const char *, unsigned int)
 write the data to the serial port.
virtual ResultType InternalRead (char *, unsigned int, unsigned int &)
 read the data from the serial port.
virtual ResultType InternalSendBreak (void)
 Send a break to the across the serial port.
virtual ResultType InternalPurgeBuffers (void)
 Purge the buffers.
virtual void InternalSleep (unsigned int)
 Sleep for the period of time specified, in milliseconds.
virtual void PrintSelf (std::ostream &os, itk::Indent indent) const
 Print object information.

Detailed Description

This class implements communication over a serial port via RS-232.

This class provides a common interface for the interactions with a serial port independently of the platform. The actual interactions are implemented on derived classes that are platform specific. This class is not intended for being instantiated directly, instead, the derived classes should be used.

igstkSerialCommunication.png

"Serial Communication State Machine Diagram"

"Serial Communication State Machine Diagram"

Definition at line 63 of file igstkSerialCommunication.h.


Member Typedef Documentation

Reimplemented from igstk::Communication.

Reimplemented in igstk::SerialCommunicationSimulator.

Definition at line 101 of file igstkSerialCommunication.h.


Member Enumeration Documentation

Available port numbers.

Enumerator:
PortNumber0 
PortNumber1 
PortNumber2 
PortNumber3 
PortNumber4 
PortNumber5 
PortNumber6 
PortNumber7 

Definition at line 68 of file igstkSerialCommunication.h.

Available baud rates.

Enumerator:
BaudRate9600 
BaudRate19200 
BaudRate38400 
BaudRate57600 
BaudRate115200 

Definition at line 78 of file igstkSerialCommunication.h.

Available data bits settings.

Enumerator:
DataBits7 
DataBits8 

Definition at line 85 of file igstkSerialCommunication.h.

Available parity settings.

Enumerator:
NoParity 
OddParity 
EvenParity 

Definition at line 89 of file igstkSerialCommunication.h.

Available stop bits settings.

Enumerator:
StopBits1 
StopBits2 

Definition at line 94 of file igstkSerialCommunication.h.

Available hardware handshaking settings.

Enumerator:
HandshakeOff 
HandshakeOn 

Definition at line 98 of file igstkSerialCommunication.h.


Constructor & Destructor Documentation

igstk::SerialCommunication::SerialCommunication ( ) [protected]
igstk::SerialCommunication::~SerialCommunication ( ) [protected]

Member Function Documentation

igstk::SerialCommunication::igstkStandardClassBasicTraitsMacro ( SerialCommunication  ,
Communication   
)

Standard traits of a basic class.

static Pointer igstk::SerialCommunication::New ( void  ) [static]

Customized New method that will return the implementation of SerialCommunication that is appropriate for this platform.

See also:
SerialCommunicationForWindows
SerialCommunicationForPosix

Reimplemented from igstk::Object.

virtual void igstk::SerialCommunication::SetPortNumber ( PortNumberType  _arg) [virtual]

Specify which serial port to use.

If communication is open, this has no effect until communication is closed and reopened.

virtual PortNumberType igstk::SerialCommunication::GetPortNumber ( ) [virtual]

Get the serial port, where the ports are numbered 0 through 3.

virtual void igstk::SerialCommunication::SetBaudRate ( BaudRateType  _arg) [virtual]

Set the baud rate to use.

Baud rates of 57600 or higher should not be used unless some sort of error checking is in place.

virtual BaudRateType igstk::SerialCommunication::GetBaudRate ( ) [virtual]

Get the baud rate.

virtual void igstk::SerialCommunication::SetDataBits ( DataBitsType  _arg) [virtual]

Set the number of bits per character.

This should usually be set to 8, since 7 bits is only valid for pure ASCII data.

virtual DataBitsType igstk::SerialCommunication::GetDataBits ( ) [virtual]

Get the number of bits per character.

virtual void igstk::SerialCommunication::SetParity ( ParityType  _arg) [virtual]

Set the parity.

The default is no parity.

virtual ParityType igstk::SerialCommunication::GetParity ( ) [virtual]

Get the parity.

virtual void igstk::SerialCommunication::SetStopBits ( StopBitsType  _arg) [virtual]

Set the number of stop bits.

The default is one stop bit.

virtual StopBitsType igstk::SerialCommunication::GetStopBits ( ) [virtual]

Get the number of stop bits.

virtual void igstk::SerialCommunication::SetHardwareHandshake ( HandshakeType  _arg) [virtual]

Set whether to use hardware handshaking.

virtual HandshakeType igstk::SerialCommunication::GetHardwareHandshake ( ) [virtual]

Get whether hardware handshaking is enabled.

void igstk::SerialCommunication::SetCaptureFileName ( const char *  filename)

Set the name of the file into which the data stream is recorded.

const char* igstk::SerialCommunication::GetCaptureFileName ( ) const

Get the filename into which the data stream is recorded.

virtual void igstk::SerialCommunication::SetCapture ( bool  _arg) [virtual]

Set whether to record the data.

virtual bool igstk::SerialCommunication::GetCapture ( ) [virtual]

Get whether the data is being recorded.

ResultType igstk::SerialCommunication::UpdateParameters ( void  )

Update the communication parameters, in case you need to change the baud rate, handshaking, timeout, etc.

after opening the port

ResultType igstk::SerialCommunication::OpenCommunication ( void  ) [virtual]

The method OpenCommunication sets up communication as per the data provided.

Reimplemented from igstk::Communication.

ResultType igstk::SerialCommunication::CloseCommunication ( void  ) [virtual]

The method CloseCommunication closes the communication.

Reimplemented from igstk::Communication.

ResultType igstk::SerialCommunication::SetRTS ( unsigned int  signal)

Set the RTS value 0 : Clear the RTS (request-to-send) signal 1 : Sends the RTS signal.

ResultType igstk::SerialCommunication::Write ( const char *  message,
unsigned int  numberOfBytes 
) [virtual]

Write method sends the string via the communication link.

Reimplemented from igstk::Communication.

ResultType igstk::SerialCommunication::Read ( char *  data,
unsigned int  numberOfBytes,
unsigned int &  bytesRead 
) [virtual]

Read method receives the string via the communication link.

The data will always be null-terminated, so ensure that 'data' is at least numberOfBytes+1 in size.

Reimplemented from igstk::Communication.

ResultType igstk::SerialCommunication::SendBreak ( void  )

Send a break in the serial communication, which by definition is a series of zeroes that lasts for a 0.3 second duration.

Some devices interpret this as a "reset" signal because the device is guaranteed to see it even if the baud rate, parity, or data bits are not matched between the host and the device.

ResultType igstk::SerialCommunication::PurgeBuffers ( void  )

Purge the contents of the buffers.

This is used if the device connected to the serial port has just been reset after an error, and the contents of the serial port buffers has to be thrown out before communication can continue.

void igstk::SerialCommunication::Sleep ( unsigned int  milliseconds)

Sleep for the specified number of milliseconds.

This is useful after a reset of a device on the other end of the serial port, if the device is known to take a certain amount of time to initialize.

void igstk::SerialCommunication::ExportStateMachineDescription ( OutputStreamType &  ostr,
bool  skipLoops = false 
) const

Declarations related to the State Machine.

LoggerType* igstk::SerialCommunication::GetLogger ( ) const [protected]

Declarations related to the Logger.

Reimplemented from igstk::Object.

void igstk::SerialCommunication::SetLogger ( LoggerType logger)

Connect the Logger for this class.

Reimplemented from igstk::Object.

virtual ResultType igstk::SerialCommunication::InternalOpenPort ( void  ) [inline, protected, virtual]

Opens serial port for communication;.

Reimplemented in igstk::SerialCommunicationForPosix, igstk::SerialCommunicationForWindows, and igstk::SerialCommunicationSimulator.

Definition at line 216 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalUpdateParameters ( void  ) [inline, protected, virtual]

Set communication parameters on the open port.

Reimplemented in igstk::SerialCommunicationForPosix, igstk::SerialCommunicationForWindows, and igstk::SerialCommunicationSimulator.

Definition at line 219 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalClosePort ( void  ) [inline, protected, virtual]
virtual ResultType igstk::SerialCommunication::InternalSetRTS ( unsigned int  ) [inline, protected, virtual]

Closes serial port.

Reimplemented in igstk::SerialCommunicationForPosix, and igstk::SerialCommunicationForWindows.

Definition at line 225 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalWrite ( const char *  ,
unsigned int   
) [inline, protected, virtual]

write the data to the serial port.

Reimplemented in igstk::SerialCommunicationForPosix, igstk::SerialCommunicationForWindows, and igstk::SerialCommunicationSimulator.

Definition at line 228 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalRead ( char *  ,
unsigned int  ,
unsigned int &   
) [inline, protected, virtual]

read the data from the serial port.

Reimplemented in igstk::SerialCommunicationForPosix, igstk::SerialCommunicationForWindows, and igstk::SerialCommunicationSimulator.

Definition at line 232 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalSendBreak ( void  ) [inline, protected, virtual]

Send a break to the across the serial port.

Reimplemented in igstk::SerialCommunicationForPosix, igstk::SerialCommunicationForWindows, and igstk::SerialCommunicationSimulator.

Definition at line 236 of file igstkSerialCommunication.h.

virtual ResultType igstk::SerialCommunication::InternalPurgeBuffers ( void  ) [inline, protected, virtual]
virtual void igstk::SerialCommunication::InternalSleep ( unsigned int  ) [inline, protected, virtual]

Sleep for the period of time specified, in milliseconds.

Reimplemented in igstk::SerialCommunicationForPosix, and igstk::SerialCommunicationSimulator.

Definition at line 242 of file igstkSerialCommunication.h.

virtual void igstk::SerialCommunication::PrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const [protected, virtual]

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