📄 serialapi.h
字号:
//----------------------------------------------------------------
// description: This file includes data definitions and types
// for the Application Interface to the serial
// device driver.
//NOTE:
// THESE MUST BE USED WHEN SETTING COM PARAMETERS
//-----------------------------------------------------------------
#define COM1 0
#define COM2 1
//-----------------------------------------------------
// Definitions for COM parameters
//-----------------------------------------------------
#define COM_PARITY_NONE 0x00
#define COM_PARITY_ODD 0x08
#define COM_PARITY_EVEN 0x18
#define COM_PARITY_HIGH 0x28
#define COM_PARITY_LOW 0x38
#define COM_FIFO_DISABLED 0
#define COM_FIFO_1 1
#define COM_FIFO_4 2
#define COM_FIFO_8 3
#define COM_FIFO_14 4
#define COM_STOPBITS_1 0x00
#define COM_STOPBITS_2 0x04
#define COM_WORDSIZE_5 0x00
#define COM_WORDSIZE_6 0x01
#define COM_WORDSIZE_7 0x02
#define COM_WORDSIZE_8 0x03
#define COM_BAUD_RATE_2400 0
#define COM_BAUD_RATE_4800 1
#define COM_BAUD_RATE_9600 2
#define COM_BAUD_RATE_19200 3
#define COM_BAUD_RATE_38400 4
#define COM_BAUD_RATE_57600 5
#define COM_BAUD_RATE_115200 6
#define COM_FLOW_CONTROL_NONE 0
#define COM_FLOW_CONTROL_HARDWARE 1
//-------------------------------------------
// define ComStats function codes
//-------------------------------------------
#define COM_STATS_START 0
#define COM_STATS_STOP 1
#define COM_STATS_PRINT 2
//--------------------------------------------
//define the API return codes
//--------------------------------------------
#define COM_NORMAL 0 // normal return
#define COM_RECEIVE_BUFFER_OVERFLOW 1 //receive ring buffer full
#define COM_TRANSMIT_BUFFER_OVERFLOW 2 //transmit ring buffer full
#define COM_DEVICE_OPEN 3 //device already open
#define COM_DEVICE_TIMEOUT 4 //device timed out
#define COM_RECEIVE_TIMEOUT 5 //timer elapsed on a read with wait
#define COM_INVALID_DEVICE 6 //invalid or unsupport port
#define COM_PORT_IO_FAILURE 7 //Enable port i/o failed
#define COM_CONNECT_INTERRUPT_FAILED 8 //unable to connect to interrupt
#define COM_PORT_NOT_OPEN 9 //com port not yet open
#define COM_PORT_UNSUPPORTED_INTERRUPT 10 //isr received an unsupported inetrrupt
#define COM_PORT_UNSOLICITED_INTERRUPT 11 //isr received an unsolicited inetrrupt
#define COM_DEVICE_BUSY 12 //a com device is busy
#define COM_INVALID_COMMAND 13 //invalid command sent to RTX side
#define COM_DRIVER_UNAVAILABLE 14 //could not connect to RTX dispatcher
#define COM_INVALID_PARAMETER 15 //invalid DCB parameter
#define COM_TIMER_ACTIVE 16 //com timer already active
#define COM_CANNOT_CREATE_TIMER 17 //create timer request failed
//-------------------------------------------------
// define COM port states
//-------------------------------------------------
#define COM_STATE_IDLE 0
#define COM_STATE_OPEN 1
//---------------------------------------
// local types and data definitions
//---------------------------------------
typedef struct
{
BYTE fifoSize; //size of FIFO..default = 14
BYTE parity; //parity odd/even/none
BYTE stopBits; //0 1 or 2 stop bits
BYTE wordSize; //word size..5 - 8 bits
BYTE baudRate; //configured baud rate
BYTE flowControl; //flow control
}COM_DCB;
typedef struct //define a COM Status Block
{
WORD state;
WORD lastError;
WORD errorCount;
}CSB;
//-----------------------------------
// function prototypes
//-----------------------------------
WORD RtOpenComPort
( BYTE port,
WORD baudRate,
BYTE wordLength,
BYTE stopBits,
BYTE parity
);
WORD RtCloseComPort( BYTE port );
WORD RtReadComPort ( BYTE port, BYTE *buffer, WORD bytesToRead, WORD *bytesRead );
WORD RtWriteComPort ( BYTE port, BYTE *buffer, WORD bytesToWrite, WORD *bytesWritten );
WORD RtWaitForComData ( BYTE port, BYTE *buffer, WORD bytesToRead, WORD *bytesRead );
WORD RtGetComBufferCount ( BYTE port );
WORD RtGetComStatus ( BYTE port, CSB * csb );
WORD RtConfigComPort (BYTE port, COM_DCB * dcb );
WORD RtSetComTimer( BYTE port, DWORD quantum );
WORD RtClearComTimer( BYTE port );
WORD RtComStats( BYTE port, BYTE command );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -