00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef CSERIALPORT_H
00030 #define CSERIALPORT_H
00031
00032 #include <mrpt/config.h>
00033 #include <mrpt/utils/CStream.h>
00034 #include <queue>
00035
00036 #include <mrpt/hwdrivers/link_pragmas.h>
00037
00038 namespace mrpt
00039 {
00040 namespace hwdrivers
00041 {
00042 using namespace mrpt::utils;
00063 class HWDLLIMPEXP CSerialPort : public CStream
00064 {
00065 friend class PosixSignalDispatcherImpl;
00066 public:
00072 CSerialPort( const std::string &portName, bool openNow = true );
00073
00076 virtual ~CSerialPort();
00077
00081 void setSerialPortName( const std::string &COM_name )
00082 {
00083 #ifdef MRPT_OS_WINDOWS
00084 if (hCOM) THROW_EXCEPTION("Cannot change serial port while open");
00085 #else
00086 if (hCOM>=0) THROW_EXCEPTION("Cannot change serial port while open");
00087 #endif
00088 m_serialName = COM_name;
00089 }
00090
00094 void open();
00095
00098 void close();
00099
00102 bool isOpen();
00103
00107 void purgeBuffers();
00108
00117 void setConfig(
00118 int baudRate,
00119 int parity = 0,
00120 int bits = 8,
00121 int nStopBits = 1,
00122 bool enableFlowControl=false);
00123
00127 void setTimeouts(
00128 int ReadIntervalTimeout,
00129 int ReadTotalTimeoutMultiplier,
00130 int ReadTotalTimeoutConstant,
00131 int WriteTotalTimeoutMultiplier,
00132 int WriteTotalTimeoutConstant );
00133
00134
00138 size_t Read(void *Buffer, size_t Count);
00139
00144 size_t Write(const void *Buffer, size_t Count);
00145
00146
00154 size_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning)
00155 {
00156 MRPT_TRY_START
00157 MRPT_UNUSED_PARAM(Origin);
00158 MRPT_UNUSED_PARAM(Offset);
00159 THROW_EXCEPTION("Method not applicable to serial communications port CStream!");
00160 MRPT_TRY_END
00161 }
00162
00165 size_t getTotalBytesCount()
00166 {
00167 MRPT_TRY_START
00168 THROW_EXCEPTION("Method not applicable to serial communications port CStream!");
00169 MRPT_TRY_END
00170 }
00171
00174 size_t getPosition()
00175 {
00176 MRPT_TRY_START
00177 THROW_EXCEPTION("Method not applicable to serial communications port CStream!");
00178 MRPT_TRY_END
00179 }
00180
00181 protected:
00182
00185 std::string m_serialName;
00186 int m_baudRate;
00187 int m_totalTimeout_ms,m_interBytesTimeout_ms;
00188
00189 #ifdef MRPT_OS_WINDOWS
00190
00191 void *hCOM;
00192 #else
00193
00196 int hCOM;
00197 #endif
00198
00199 };
00200
00201 }
00202 }
00203
00204 #endif