rs232.h
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:2k
- #ifndef _RS232_H_
- #define _RS232_H_
- //=============================================================================
- #include "windows.h"
- //-----------------------------------------------
- #define THREAD_BUFSIZE 4096 // thread buffer size
- #define UART_BUFSIZE (4096+1024)
- #define UART_WRAPPOS (4096)
- //-----------------------------------------------
- class CRS232
- {
- public:
- // for Thread management
- /*
- HANDLE m_hThreadOrg;
- HANDLE m_hThread;
- UINT8 ThreadBuffer[ THREAD_BUFSIZE ];
- */
- public:
- bool m_bConnected;
- int m_PortNo;
- HANDLE m_hPort;
- OVERLAPPED m_osRead,m_osWrite;
- // for UART RX buffer management
- UINT8 RXBuf[UART_BUFSIZE];
- UINT16 pos_read;
- UINT16 pos_write;
- UINT16 pos_wrap;
- // For debug logging
- bool LogEnable;
- char LogString[8196];
- char *LogStrPtr;
- public:
- CRS232( void );
- ~CRS232( );
- int PutData2Buf( void *data, int len); // for debug simulation
- int ReadUartData(void);
- //public:
- /*
- port_no = 1~99 (COM1~CM99);
- baudrate = 9600L, 57600L, 115200L, 230400L, 460800L, 921600L
- data_bit = 4~8
- stop_bit = 0(1bit), 1(1.5bit), 2(2bit)
- parity = 0(no),1(odd),2(even),3(mark),4(space)
- ena_dts_rts = 0(disable), 1(enable)
- ena_rts_cts = 0(disable), 1(enable)
- ena_xon_xoff = 0(disable), 1(enable)
- */
- bool Open( int port_no=1, long baudrate=115200, int data_bit=8,
- int stop_bit=0, int parity=0, int ena_dts_rts=0, int ena_rts_cts=0, int ena_xon_xoff=0);
- bool Close( void );
- int SendData( void *buf, int len );
- int ReadData( void *buf, int maxlen );
- bool IsConnected( void );
- bool IsRxDataReady( void );
- void LogRXQposition(void);
- };
- //=============================================================================
- #endif