📄 downcomm.h
字号:
#ifndef _DOWN_COMM_H_
#define _DOWN_COMM_H_
#define COMM_ERROR_SUCESS 0
#define COMM_ERROR_TIME -1
#define COMM_ERROR_USER -2
#define COMM_ERROR_CHECK -3
#define COMM_ERROR_BUSY -4
#define COMM_ERROR_DEFAULT -5
#define COMM_ERROR_OVER -6
#define COMM_ERROR_ADDRESS -7
#define COMM_ERROR_FORMAT -8
#define COMM_ERROR_ANSWER -9
#define COMM_ERROR_FILE -0xA
#define COMM_ERROR_READY -0xB
#define COMM_ERROR_CRAFT -0xC
#define COMM_ERROR_AGAIN -0xD
/*********************************/
#define COMM_COMMAND_SUCESS 0x0000
#define COMM_COMMAND_DATA 0x0001
#define COMM_COMMAND_AGAIN 0x0002
#define COMM_COMMAND_ASK 0x0003
#define COMM_COMMAND_ANSWER 0x0004
#define COMM_COMMAND_FIRST 0x0005
#define COMM_COMMAND_NEXT 0x0006
#define COMM_COMMAND_LAST 0x0007
#define COMM_COMMAND_CHECK 0x0008
#define COMM_COMMAND_KEY 0x0009
#define COMM_COMMAND_LIMITS 0x000A
#define COMM_COMMAND_CODE 0x000B
#define COMM_COMMAND_READY 0x000C
#define COMM_COMMAND_FILE 0x000D
#define COMM_COMMAND_DIR 0x000E
#define COMM_COMMAND_WORKER 0x000F
#define COMM_COMMAND_END 0x00FF
/*********************************/
#define CBR_110 110
#define CBR_300 300
#define CBR_600 600
#define CBR_1200 1200
#define CBR_2400 2400
#define CBR_4800 4800
#define CBR_9600 9600
#define CBR_14400 14400
#define CBR_19200 19200
#define CBR_38400 38400
#define CBR_56000 56000
#define CBR_57600 57600
#define CBR_115200 115200
#define CBR_128000 128000
#define CBR_256000 256000
#define NOPARITY 0
#define ODDPARITY 1
#define EVENPARITY 2
#define MARKPARITY 3
#define SPACEPARITY 4
#define ONESTOPBIT 0
#define ONE5STOPBITS 1
#define TWOSTOPBITS 2
#define DTR_CONTROL_DISABLE 0x00
#define DTR_CONTROL_ENABLE 0x01
#define DTR_CONTROL_HANDSHAKE 0x02
#define RTS_CONTROL_DISABLE 0x00
#define RTS_CONTROL_ENABLE 0x01
#define RTS_CONTROL_HANDSHAKE 0x02
#define RTS_CONTROL_TOGGLE 0x03
/*********************************/
#define COMM_INPUT_BUFFER_SIZE (8*1024)
#define MEMORY_TIME_ADDRESS 0x46CL
/************************************/
struct IPHEAD
{
BYTE chFormat[12]; //12
WORD wReceiveIPAddress; //14
WORD wSendIPAddress; //16
WORD wCommand; //18
WORD wLength; //20
IPHEAD();
};
#define FILE_PAGE_LENGTH 1024
struct FIRST_FILE_PAGE
{
DWORD dwFileLength;
char chFileName[16];
char chTargetPath[256];
};
struct NEXT_FILE_PAGE
{
WORD wPage;
char chBuffer[FILE_PAGE_LENGTH];
};
struct RECEIVE_FILE_PAGE
{
WORD wAddress;
char chFileName[256];
};
class CMotorNet
{
private:
BOOL m_bReceive;
BOOL m_bSend;
private:
void far (*m_pReceivePageFc)(int nPage);
void far (*m_pSendPageFc)(int nPage);
private:
BYTE m_byLine;
int m_nCommBase;
DWORD m_dwBaud;
WORD m_wDataBit;
WORD m_wStartBit;
WORD m_wStopBit;
WORD m_wParityStyle;
int m_nCommOverTime;
int m_nErrorCode;
DWORD m_dwCommWaittingTime;
private:
WORD m_wIPAddress;
WORD m_wOtherIPAddress;
IPHEAD m_sIPHead;
WORD m_wCommand;
private:
BOOL m_b386;
BOOL m_bRelay;
BOOL m_bSingle;
private:
BYTE m_byInputBuffer[COMM_INPUT_BUFFER_SIZE];
private:
DWORD m_dwReceiveLength;
public:
void SetCommWaittingTime(DWORD dwValue){m_dwCommWaittingTime=dwValue;};
DWORD GetCommWaittingTImer(){return(m_dwCommWaittingTime);}
void SetBaud(DWORD dwValue){m_dwBaud=dwValue;}
DWORD GetBaud(){return(m_dwBaud);}
void SetDataBit(WORD wDataBit){m_wDataBit=wDataBit;}
WORD GetDataBit(){return(m_wDataBit);}
void SetStopBit(WORD wStopBit){m_wStopBit = wStopBit;}
WORD GetStopBit(){return(m_wStopBit);}
void SetParityStyle(WORD wParityStyle){m_wParityStyle=wParityStyle;}
WORD GetParityStyle(){return(m_wParityStyle);}
void ModifyCommParity();
void ModifyCommAttrib();
public:
void SetReceivePageFc(void far (*pFc)(int nPage)){m_pReceivePageFc=pFc;}
void SetSendPageFc(void far (*pFc)(int nPage)){m_pSendPageFc=pFc;}
void SetSingle(BOOL bSingle){m_bSingle=bSingle;}
BOOL GetSingle(){return(m_bSingle);}
void Set386(BOOL b386){m_b386=b386;}
BOOL Get386(){return(m_b386);}
void SetDelayEnable(BOOL bValue){m_bRelay=bValue;}
BOOL GetDelayEnabel(){return(m_bRelay);}
public:
void SetCommOverTime(int nTime=5){m_nCommOverTime=nTime;}
void SetCommBase(int nBase=0x2f8){m_nCommBase=nBase;}
void SetCommBase(char *PComm);
void InitComm(int nBase=0x2f8,DWORD dwBaud=4800L,WORD wDataBit=8,WORD wStartBit=1,WORD wStopBit=1,WORD wParityStyle=NOPARITY);
void InitComm();
int GetCommBase(){return(m_nCommBase);}
BOOL IsCommData();
BOOL WaitCommData(DWORD dwWait);
BOOL IsBusy();
BYTE ReceiveData();
BOOL SendData(BYTE nCh);
BOOL ReceivePage(BOOL bTest=FALSE);
BOOL SendPage(BYTE *pbyData,WORD wCount,WORD wReceiveIPAddress,WORD wCommand,BOOL bTest=TRUE);
BOOL ReceiveSendAnswer(WORD wCommand);
BOOL SendReceiveAnswer(WORD wCommand);
BOOL ReceiveFile(char *pStr,DWORD dwFileLength);
BOOL SendFile(char *pStr,char *pStrTargetPath,WORD wAddress);//,WORD wSendAfterDelay=150,WORD wSendPageDelay=50);
BOOL SetChange(char *pStr,BOOL bChange);
public:
void SetIPAddress(WORD wAddress){m_wIPAddress=wAddress;}
WORD GetIPAddress(){return(m_wIPAddress);}
BYTE *GetInputBuffer(){return(m_byInputBuffer);}
WORD GetReceiveLength(){return(m_dwReceiveLength);}
WORD GetCommand(){return(m_wCommand);}
WORD GetOtherIPAddress(){return(m_wOtherIPAddress);}
public:
int GetLastCommError(){return(m_nErrorCode);};
void SetLastCommError(int nErrorCode){m_nErrorCode=nErrorCode;}
void ClearLastCommError(){m_nErrorCode=COMM_ERROR_SUCESS;}
public:
CMotorNet();
~CMotorNet();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -