⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs232.h

📁 ST Flash loader的2次开发接口源码
💻 H
字号:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : rs232.h
* Author             : MCD Application Team
* Version            : V1.1.1
* Date               : 06/16/2008
* Description        : Defines the CRS232 class for COM communication
*                      The enclosed software and all the related documentation
*                      are not covered by a License Agreement, if you need such
*                      License you can contact your local STMicroelectronics
*                      office.
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

#ifndef LSERIE_H
#define LSERIE_H

#include <string>
using namespace std;


class CRS232  
{
public:
	void SetParity(int _parity);
	BOOL isConnected;

	int numPort;
	long speedInBaud;
	int nbBit;
	int parity;
	float nbStopBit;

	//------ CONSTRUCTOR ------
	CRS232();									
	virtual ~CRS232();

	//------ OPEN AND CONFIGURE ------
	void SetComSettings(int _numPort, long _speedInBaud, int _nbBit, int _parity, float _nbStopBit);

	bool open();	//Open the serial port COM "numPort" at the speed "speedInBaud".
			  // bauds with and this adjustement : "nbBit" bit / "nbStopBit" stop bit / "parity").
														// Return: true if success.
	void closeCom();			                //Close the serial port.
	bool setTimeOut(DWORD ms);					//Set the time-out for receive data. Return: true if success.
	bool setSpeed(DWORD baudrate);				//Set the speed in bauds. Return: true if success.

	//------ SEND AND RECEIVE DATA ------
	int sendData(DWORD lg, LPBYTE data);		//Send table "data" of "lg" bytes.  Return: number of bytes really sent.
	int sendData(string* data);					//Send string "data".  Return: number of bytes really sent.
	int receiveData(DWORD lg, LPBYTE data);		//Receive table "data" who is limit at "lg" bytes.  Return: number of bytes received.
	int receiveData(string* data);				//Receive string "data". Return: number of bytes received.

	//------ READ AND WRITE THE STATE OF THE CONTROL LINE ------
	bool setRts(bool val);			// Set the state of RTS. Return: true if success.
	bool setDtr(bool val);			// Set the state of DTR. Return: true if success.
	bool setTxd(bool val);			// Set the state of TXD. Return: true if success.
	bool getCts();					// Return: The state of CTS.			
	bool getDtr();					// Return: The state of DTR.	
	bool getRi();					// Return: The state of RI.	
	bool getCd();					// Return: The state of CD.	
	
	string getErrorMsg();			// Return: The error message generated by the last function.

private:
	HANDLE			hcom;				//Otput file to the COM port    		| The file stream use for acces to the serial port.
	_COMMTIMEOUTS	ct;                 //={0,0,0,0,0}; //Config du Time Out	| This variable contain the delay of the time-out. 
	DCB				dcb;				//Port configuration struct				| This object is use in order to configure the serial port.
	int				bufferSize;
};

#endif 

/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE******/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -