www.pudn.com > ChatUseIOCP.rar > DtSerialSocket.h


#pragma once 
 
#include  
#include  
 
#define DTSERIALSOCKET 
 
////////////////////////////////////////////////////////////////////////// 
/// 
///		 
///  @class			DtSerialSocket - class for serial communication. 
///  @version		1.0 
///	 @author		Jonas Gauffin 
///  @homepage		http://www.gauffin.org/cpp 
///	 
///  @brief			A class for communication through comports.  
///  
///  @since 2003-04-03	jg	File created 
///	 @since 2003-08-12	jg	fixed memset in Disconnect() 
/// 
////////////////////////////////////////////////////////////////////////// 
 
namespace Datatal 
{ 
 
 
class DtSerialSocket : 
	public DtSocketBase 
{ 
public: 
	/// @param Port The comport that we want to use. 
	void SetCommPort(DWORD dwPort); 
 
	/// @param bSet true is parity should be on. 
	void SetParity(bool bSet); 
 
	/// @param ByteSize ByteSize. 4 eller 8 bits. 
	void SetByteSize(BYTE bByteSize); 
 
	/// @param Baudrate The baudrate 1200 up to 128100 or something like that. 
	void SetBaudRate(DWORD dwBaudrate); 
 
	/// @param StopBits 1 = one stopbit, 2 = two stopbits, all other values = 1.5 stopbits. 
	void SetStopBits(DWORD dwStopBits); 
 
	/// Connect to the serial port. 
	/// Throws a CSocketException if the settings arent specified (errcode -1) or if something fails (GetLastError code). 
	/// @returns TRUE if success. 
	void Connect(); 
 
	/// Connect to the serial port. This function also loads the workerthread. 
	/// Throws a DtSocketException if something failes. 
	/// @param ComPort The comport that we want to use. 
	/// @param BaudRate The baudrate 1200 up to 128100 or something like that. 
	/// @param ByteSize ByteSize. 4 eller 8 bits. 
	/// @param bParity true is parity should be on. 
	/// @param StopBits 1 = one stopbit, 2 = two stopbits, all other values = 1.5 stopbits. 
	void Connect(int ComPort, DWORD BaudRate, BYTE ByteSize, bool bParity, DWORD StopBits); 
 
	/// Stops the workerthread and closes the port. 
	/// @returns true if we managed to close the thread and port. 
	bool Disconnect(bool bStopThread = false); 
 
	/// Returns the type of communicationclass that currently are used. 
	/// @returns The type of the current communictation. TCPIP or SERIAL 
	const char* GetTypeName() { return "SERIAL"; }; 
 
	DtSerialSocket(void); 
	~DtSerialSocket(void); 
 
private: 
	HANDLE	m_hComm;				/// Handle to our comport. 
	DWORD	m_dwComPort;			/// ComPort 
	DWORD	m_dwBaudRate;			/// Baudrate that we use. 
	DWORD	m_dwStopBits;			/// Stopbits for our port. 
	BYTE	m_bByteSize;			/// Bytesize for our port. 
	BYTE	m_bParity;				/// Parity fort our port. 
 
	virtual void ThreadFunc(HANDLE hStopEvent); 
}; 
 
};//namespace