00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UT_SERIAL_H
00022 #define UT_SERIAL_H
00023
00024 #include "UT_API.h"
00025 #ifdef WIN32
00026 #include <windows.h>
00027 #include <winbase.h>
00028 #else
00029 #define _OLD_TERMIOS
00030 #include <termios.h>
00031 #endif
00032
00033 #define SERIAL_NO_PARITY 0
00034 #define SERIAL_ODD_PARITY 1
00035 #define SERIAL_EVEN_PARITY 2
00036
00037 class UT_API UT_Serial
00038 {
00039 public:
00040 explicit UT_Serial(int rate = 9600,
00041 int databits = 8,
00042 int parity = SERIAL_NO_PARITY,
00043 int stopbits = 1);
00044
00045 virtual ~UT_Serial();
00046
00047 int open(const char *port, int parms);
00048 void close();
00049
00050 int changeRate(int rate);
00051
00052 int dataAvailable();
00053 int read(void *buffer, int num);
00054 int write(const void *buffer, int num);
00055
00056 void flush();
00057
00058 private:
00059 int mySpeed;
00060 int myDataBits;
00061 int myStopBits;
00062 int myParity;
00063 int mySerialStateSaved;
00064
00065
00066 #ifdef WIN32
00067 HANDLE myFD;
00068 COMMCONFIG myPreviousState;
00069 COMMCONFIG mySerialState;
00070 int myDataAvailable;
00071 char myStoredChar;
00072 #else
00073 int myFD;
00074 struct termios myPreviousState;
00075 struct termios mySerialState;
00076 #endif
00077 };
00078
00079 #endif