📄 commport.h
字号:
// CommPort.h: interface for the CCommPort class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _CLASS_CCommPort_h_
#define _CLASS_CCommPort_h_
#include <dos.H>
class CCommPort
{
public:
CCommPort();
~CCommPort();
int sio_open(unsigned short int mPortBasicAddr,short int mInterruptIRQNo,long int mBaudRate,unsigned short int BufferSize);
void sio_write(char const *buf, int len);
void sio_write(char const *str);
void sio_putch(char const ch);
void sio_fflush();
unsigned char sio_havechar();
signed short sio_getch();
// void SetSpeed(unsigned long newRate){};
unsigned char GetModemStatus();
void sio_close();
protected:
unsigned char *mData;
void interrupt (*m_PortOldIntHandle)(...);//旧的中断函数
unsigned char m_PortIndex;//255无效。
unsigned short int m_PortAddr; //端口基地址
unsigned short int m_InterruptNo; //端口中断向量号
unsigned short int mHead,mTail;
unsigned short int mBufferSize;
protected:
virtual void ReceiveNewChar(unsigned char newChar);
virtual void ModemStatusChange(short int ModemSignal);
private:
void COM_ISR();
static void interrupt COM_ISR_0(...);
static void interrupt COM_ISR_1(...);
static void interrupt COM_ISR_2(...);
static void interrupt COM_ISR_3(...);
static void interrupt COM_ISR_4(...);
static void interrupt COM_ISR_5(...);
};
inline void CCommPort::ReceiveNewChar(unsigned char newChar)
{
if(!mData) return;
mData[mTail++]=newChar;
if(mTail==mBufferSize) mTail=0;
if(mHead==mTail)
{ mHead++;
if(mHead==mBufferSize) mHead=0;
}
}
inline unsigned char CCommPort::sio_havechar()
{
return (mHead!=mTail);
}
inline unsigned char CCommPort::GetModemStatus()
{
return inportb(m_PortAddr+6);
}
inline void CCommPort::sio_fflush()
{
mHead=mTail=0;
}
inline void CCommPort::ModemStatusChange(short int ModemSignal)
{
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -