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

📄 commport.h

📁 fax engine 传真引擎 relay fax 的开源项目 商业软件使用 高质量 高可靠
💻 H
字号:
/*****************************************************************************
* RelayFax Open Source Project
* Copyright 1996-2004 Alt-N Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the RelayFax Open 
* Source License.  A copy of this license is available in file LICENSE 
* in the top-level directory of the distribution.
*
* RelayFax is a registered trademark of Alt-N Technologies, Ltd.
*
* Individual files and/or contributed packages may be copyright by
* other parties and subject to additional restrictions.
*****************************************************************************/

////////////////////////////////////////////////////////////////////////////////
//
// The purpose of CCommPort is to encapsulate all the Win32 communication API
//
////////////////////////////////////////////////////////////////////////////////

#ifndef COMMPORT_H
#define COMMPORT_H

#define	READBUF_SIZE	4096				// must be big enough for largest training seq
#define	WRITEBUF_SIZE	4096
#define MAX_WRITE		WRITEBUF_SIZE


#define		NUL			0x00
#define		DLE			0x10
#define		ETX			0x03
#define		XON			0x11
#define     DC2			0x12
#define		XOFF		0x13
#define     CAN			0x18
#define		SPACE		0x20
#define     SUB			0x1a



#define DIS_V27_FALLBACK		0x00
#define DIS_V27					0x04
#define DIS_V29					0x08
#define DIS_V27_V29				0x0c
#define DIS_V27_V29_V33			0x0e
#define DIS_V27_V29_V33_V17		0x0d


#define MAX_CLS1SPEEDS	10

typedef struct tagCls1Speed {
	char cDCSBits;	
	int ModStr1;
	int ModStr2;
	LONG dwSpeed;
	int ndx;
} CLS1SPEEDS;


class CWriteBuffer
{
public:
	char Buffer[MAX_WRITE];
	unsigned long Bytes;
};


class CCommPort  
{
public:
	CCommPort();
	virtual ~CCommPort();

	virtual bool ConnectPort( string& sErr );
	virtual void DisconnectPort( void );

	virtual bool DoRead( void );
	virtual void DoReadLoop( void );
	virtual bool DoWrite( char* szChars, unsigned long nBytes, bool bCrLf = true );
	virtual void FillWriteQueue( char* szChars, unsigned long nBytes, bool bCrLf = true );
    virtual bool WritePacket( char* szChars, unsigned long nBytes );
	virtual void DoWriteLoop( void );
	virtual bool DoWaitCommEvent( void );
	virtual void DoWaitCommEventLoop( void );

	// Methods called by CModem from message loop
	virtual void ReadEventSignalled(void);
	virtual void WriteEventSignalled(void);
	virtual void WaitCommEventSignalled(void);

	// methods to be overridden
	virtual void OnCommEvent(void);
	virtual void OnConnect(void);
	virtual bool OnDisconnect(void);
	virtual void OnRead(void);
	virtual void OnWrite(void);
	virtual void OnReadLine(void);

	// public methods
	void SetCommParam( DWORD BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits );
	void SetFlowControl( bool bDSRFlowControl, bool bCTSFlowControl, bool bSoftFlowControl );
	void ParseIntoLines(void);
	void InitLineParser(void) { m_nLineBuffPtr = 0; m_bEolFlag = false; };
	void EnableDebugLog( bool bDebugLog, LPCSTR szLogDir ) { m_bDebugLog = bDebugLog; m_sLogDir = szLogDir; };

	void EnableSoftFlowControl( bool bEnable );
	void OpenDebugLog(void);
	void CloseDebugLog(void);
	void WriteDebugLog( bool bRead );

	static char s_HexDigits[16];

protected:
	char m_szReadBuff[READBUF_SIZE+1];
	char m_szWriteBuff[WRITEBUF_SIZE+1];

	deque<CWriteBuffer*> m_WriteQueue;

	OVERLAPPED m_CommEventOverlapped;
	DWORD m_CommEvent;

	OVERLAPPED m_ReadOverlapped;
	DWORD m_BytesRead;

	OVERLAPPED m_WriteOverlapped;
	DWORD m_BytesWritten;
	bool m_bWriteInProgress;

	string m_sPort;
	HANDLE m_hPort;
	DCB m_dcb;

	bool m_bDSRFlowControl;
	bool m_bCTSFlowControl;
	bool m_bSoftFlowControl;

	DWORD m_BaudRate;
	BYTE m_ByteSize;
	BYTE m_Parity;
	BYTE m_StopBits;

	// Used by ParseIntoLines
	char m_szLineBuff[READBUF_SIZE+1];
	int m_nLineBuffPtr;
	bool m_bEolFlag;

	bool m_bDebugLog;
	string m_sLogDir;
	FILE* m_pLogFile;

};

extern CLS1SPEEDS cls1Speeds[MAX_CLS1SPEEDS];
extern WORD Cls1ScanTimes_normal[8];
extern WORD Cls1ScanTimes_fine[8];

extern WORD Cls2ScanTimes_normal[8];
extern WORD Cls2ScanTimes_fine[8];
extern WORD  Cls2FaxParamBitRates[6];


#endif // COMMPORT_H

⌨️ 快捷键说明

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