2066 |
kakl |
1 |
/******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** |
|
|
2 |
* File Name : rs232.h |
|
|
3 |
* Author : MCD Application Team |
|
|
4 |
* Version : v2.2.0 |
|
|
5 |
* Date : 05/03/2010 |
|
|
6 |
* Description : Defines the RS232 class for COM communication |
|
|
7 |
******************************************************************************** |
|
|
8 |
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
|
|
9 |
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
|
|
10 |
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
|
|
11 |
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
|
|
12 |
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
|
|
13 |
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
|
|
14 |
*******************************************************************************/ |
|
|
15 |
|
|
|
16 |
#ifndef LSERIE_H |
|
|
17 |
#define LSERIE_H |
|
|
18 |
|
|
|
19 |
#include <string> |
|
|
20 |
using namespace std; |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
class CRS232 |
|
|
24 |
{ |
|
|
25 |
public: |
|
|
26 |
void SetParity(int _parity); |
|
|
27 |
BOOL isConnected; |
|
|
28 |
|
|
|
29 |
int numPort; |
|
|
30 |
long speedInBaud; |
|
|
31 |
int nbBit; |
|
|
32 |
int parity; |
|
|
33 |
float nbStopBit; |
|
|
34 |
int bEcho ; /* Echo back for LIN emulation */ |
|
|
35 |
/* 0 : Disabled , 1 : Echo Back , 2 : Listen back */ |
|
|
36 |
bool FlowControl; |
|
|
37 |
|
|
|
38 |
//------ CONSTRUCTOR ------ |
|
|
39 |
CRS232(); |
|
|
40 |
virtual ~CRS232(); |
|
|
41 |
|
|
|
42 |
//------ OPEN AND CONFIGURE ------ |
|
|
43 |
void SetComSettings(int _numPort, long _speedInBaud, int _nbBit, int _parity, float _nbStopBit); |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
bool open(); // Open the serial port COM "numPort" at the speed "speedInBaud". |
|
|
47 |
// bauds with and this adjustement : "nbBit" bit / "nbStopBit" stop bit / "parity"). |
|
|
48 |
// Return: true if success. |
|
|
49 |
void closeCom(); //Close the serial port. |
|
|
50 |
bool setTimeOut(DWORD ms); //Set the time-out for receive data. Return: true if success. |
|
|
51 |
bool setSpeed(DWORD baudrate); //Set the speed in bauds. Return: true if success. |
|
|
52 |
|
|
|
53 |
//------ SEND AND RECEIVE DATA ------ |
|
|
54 |
int sendData(DWORD lg, LPBYTE data); //Send table "data" of "lg" bytes. Return: number of bytes really sent. |
|
|
55 |
int sendData(string* data); //Send string "data". Return: number of bytes really sent. |
|
|
56 |
int receiveData(DWORD lg, LPBYTE data); //Receive table "data" who is limit at "lg" bytes. Return: number of bytes received. |
|
|
57 |
int receiveData(string* data); //Receive string "data". Return: number of bytes received. |
|
|
58 |
|
|
|
59 |
//------ READ AND WRITE THE STATE OF THE CONTROL LINE ------ |
|
|
60 |
|
|
|
61 |
bool setRts(bool val); // Set the state of RTS. Return: true if success. |
|
|
62 |
bool setDtr(bool val); // Set the state of DTR. Return: true if success. |
|
|
63 |
bool setTxd(bool val); // Set the state of TXD. Return: true if success. |
|
|
64 |
bool getCts(); // Return: The state of CTS. |
|
|
65 |
bool getDtr(); // Return: The state of DTR. |
|
|
66 |
bool getRi(); // Return: The state of RI. |
|
|
67 |
bool getCd(); // Return: The state of CD. |
|
|
68 |
|
|
|
69 |
string getErrorMsg(); // Return: The error message generated by the last function. |
|
|
70 |
|
|
|
71 |
private: |
|
|
72 |
HANDLE hcom; //Otput file to the COM port | The file stream use for acces to the serial port. |
|
|
73 |
_COMMTIMEOUTS ct; //={0,0,0,0,0}; //Config du Time Out | This variable contain the delay of the time-out. |
|
|
74 |
DCB dcb; //Port configuration struct | This object is use in order to configure the serial port. |
|
|
75 |
int bufferSize; |
|
|
76 |
}; |
|
|
77 |
|
|
|
78 |
#endif |
|
|
79 |
|
|
|
80 |
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/ |