18 #ifndef __igstkSerialCommunication_h
19 #define __igstkSerialCommunication_h
23 #pragma warning ( disable : 4355 )
26 #include "itkObject.h"
27 #include "itkEventObject.h"
29 #include "itkStdStreamLogOutput.h"
180 unsigned int &bytesRead );
199 void Sleep(
unsigned int milliseconds );
245 virtual void PrintSelf( std::ostream& os, itk::Indent indent )
const;
270 unsigned int m_SleepPeriod;
276 const char *m_OutputData;
279 unsigned int m_BytesToWrite;
282 unsigned int m_BytesToRead;
285 unsigned int m_BytesRead;
288 typedef std::map<int, InputType> IntegerInputMapType;
291 std::string m_CaptureFileName;
294 std::ofstream m_CaptureFileStream;
297 unsigned int m_CaptureMessageNumber;
306 unsigned int m_RTSSignal;
309 itk::StdStreamLogOutput::Pointer m_CaptureFileOutput;
315 IntegerInputMapType m_ResultInputMap;
318 igstkDeclareStateMacro( Idle );
319 igstkDeclareStateMacro( AttemptingToOpenPort );
320 igstkDeclareStateMacro( PortOpen );
321 igstkDeclareStateMacro( AttemptingToUpdateParameters );
322 igstkDeclareStateMacro( ReadyForCommunication );
323 igstkDeclareStateMacro( AttemptingToClosePort );
324 igstkDeclareStateMacro( AttemptingToRead );
325 igstkDeclareStateMacro( AttemptingToWrite );
326 igstkDeclareStateMacro( AttemptingToSendBreak );
327 igstkDeclareStateMacro( AttemptingToPurgeBuffers );
328 igstkDeclareStateMacro( AttemptingToSetRTS );
329 igstkDeclareStateMacro(
Sleep );
332 igstkDeclareInputMacro( Success );
333 igstkDeclareInputMacro( Failure );
334 igstkDeclareInputMacro( Timeout );
335 igstkDeclareInputMacro( OpenPort );
336 igstkDeclareInputMacro( ClosePort );
338 igstkDeclareInputMacro(
Read );
339 igstkDeclareInputMacro(
Write );
342 igstkDeclareInputMacro(
Sleep );
343 igstkDeclareInputMacro(
SetRTS );
346 void OpenPortSuccessProcessing(
void );
349 void OpenPortFailureProcessing(
void );
352 void ClosePortSuccessProcessing(
void );
355 void ClosePortFailureProcessing(
void );
358 void SuccessProcessing(
void );
361 void FailureProcessing(
void );
364 void TimeoutProcessing(
void );
370 void AttemptToOpenPortProcessing(
void );
373 void AttemptToUpdateParametersProcessing(
void );
376 void AttemptToClosePortProcessing(
void );
379 void AttemptToSetRTSProcessing(
void );
382 void AttemptToWriteProcessing(
void );
385 void AttemptToReadProcessing(
void );
388 void AttemptToSendBreakProcessing(
void );
391 void AttemptToPurgeBuffersProcessing(
void );
394 void SleepProcessing(
void );
397 const InputType &MapResultToInput(
int condition );
402 #endif // __igstkSerialCommunication_h
ResultType Read(char *data, unsigned int numberOfBytes, unsigned int &bytesRead)
Read method receives the string via the communication link.
virtual ResultType InternalSendBreak(void)
Send a break to the across the serial port.
#define igstkStateMachineMacro()
This is the StateMachine Macro to be used with non-templated classes.
#define igstkGetMacro(name, type)
Get built-in type.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print object information.
virtual ResultType InternalSetRTS(unsigned int)
Closes serial port.
virtual void InternalSleep(unsigned int)
Sleep for the period of time specified, in milliseconds.
::itk::SmartPointer< Self > Pointer
virtual ResultType InternalClosePort(void)
Closes serial port.
static Pointer New(void)
Customized New method that will return the implementation of SerialCommunication that is appropriate ...
virtual ResultType InternalPurgeBuffers(void)
Purge the buffers.
ResultType Write(const char *message, unsigned int numberOfBytes)
Write method sends the string via the communication link.
ResultType UpdateParameters(void)
Update the communication parameters, in case you need to change the baud rate, handshaking, timeout, etc.
virtual ResultType InternalRead(char *, unsigned int, unsigned int &)
read the data from the serial port.
defines standard system-wide macros, constants, and other common parameters in the IGSTK Library...
BaudRateType
Available baud rates.
ResultType PurgeBuffers(void)
Purge the contents of the buffers.
virtual ResultType InternalOpenPort(void)
Opens serial port for communication;.
const char * GetCaptureFileName() const
Get the filename into which the data stream is recorded.
ResultType CloseCommunication(void)
The method CloseCommunication closes the communication.
::itk::SmartPointer< Self > Pointer
Class Communication is the base class for communication between the tracker class and the hardware tr...
StopBitsType
Available stop bits settings.
Communication::ResultType ResultType
PortNumberType
Available port numbers.
ResultType OpenCommunication(void)
The method OpenCommunication sets up communication as per the data provided.
#define igstkLoggerMacro()
Macro that defines all the standard elements related to the Logger.
void Sleep(unsigned int milliseconds)
Sleep for the specified number of milliseconds.
virtual ResultType InternalWrite(const char *, unsigned int)
write the data to the serial port.
This class implements communication over a serial port via RS-232.
DataBitsType
Available data bits settings.
#define igstkSetMacro(name, type)
Set built-in type.
HandshakeType
Available hardware handshaking settings.
igstkStandardClassBasicTraitsMacro(SerialCommunication, Communication)
Standard traits of a basic class.
void SetCaptureFileName(const char *filename)
Set the name of the file into which the data stream is recorded.
ResultType SetRTS(unsigned int signal)
Set the RTS value 0 : Clear the RTS (request-to-send) signal 1 : Sends the RTS signal.
ParityType
Available parity settings.
ResultType SendBreak(void)
Send a break in the serial communication, which by definition is a series of zeroes that lasts for a ...
virtual ResultType InternalUpdateParameters(void)
Set communication parameters on the open port.