00001 #ifndef LSERIE_H 00002 #define LSERIE_H 00003 00004 #include <string> 00005 #include <windows.h> 00006 #include <scol.h> 00007 00008 using namespace std; 00009 00010 class LSerie 00011 { 00012 public: 00013 //------ CONSTRUCTOR ------ 00014 LSerie(); 00015 virtual ~LSerie(); 00016 00017 int currentPort ; 00018 00019 HANDLE comport; 00020 00021 //------ OPEN AND CONFIGURE ------ 00022 bool open(int numPort, long speedInBaud); //Open the serial port COM "numPort" at the speed "speedInBaud". 00023 // bauds with and this adjustement : 8 bit / 1 stop bit / no parity). 00024 // Return: true if success. 00025 bool open(int numPort, long speedInBaud, //Open the serial port COM "numPort" at the speed "speedInBaud". 00026 int nbBit, int parity, float nbStopBit); // bauds with and this adjustement : "nbBit" bit / "nbStopBit" stop bit / "parity"). 00027 // Return: true if success. 00028 void closeCom(); //Close the serial port. 00029 bool setTimeOut(DWORD ms); //Set the time-out for receive data. Return: true if success. 00030 bool setSpeed(DWORD baudrate); //Set the speed in bauds. Return: true if success. 00031 00032 //------ SEND AND RECEIVE DATA ------ 00033 int sendData(DWORD lg, LPBYTE data); //Send table "data" of "lg" bytes. Return: number of bytes really sent. 00034 int sendData(string* data); //Send string "data". Return: number of bytes really sent. 00035 int receiveData(DWORD lg, LPBYTE data); //Receive table "data" who is limit at "lg" bytes. Return: number of bytes received. 00036 int receiveData(string* data); //Receive string "data". Return: number of bytes received. 00037 00038 //------ READ AND WRITE THE STATE OF THE CONTROL LINE ------ 00039 bool setRts(bool val); // Set the state of RTS. Return: true if success. 00040 bool setDtr(bool val); // Set the state of DTR. Return: true if success. 00041 bool setTxd(bool val); // Set the state of TXD. Return: true if success. 00042 bool getCts(); // Return: The state of CTS. 00043 bool getDtr(); // Return: The state of DTR. 00044 bool getRi(); // Return: The state of RI. 00045 bool getCd(); // Return: The state of CD. 00046 bool isConnect(); 00047 00048 string getErrorMsg(); // Return: The error message generated by the last function. 00049 00050 private: 00051 HANDLE hcom; //Fichier de sortie sur le port COM | The file stream use for acces to the serial port. 00052 _COMMTIMEOUTS ct; //={0,0,0,0,0}; //Config du Time Out | This variable contain the delay of the time-out. 00053 DCB dcb; //Config du Port | This object is use in order to configure the serial port. 00054 int bufferSize; 00055 //?????????????????????????????? 00056 COMMTIMEOUTS CommTimeouts; 00057 00058 }; 00059 00060 00061 00062 00063 #endif 00064
1.6.3