当前位置: 代码迷 >> WinCE >> 请教应用程序中有哪些关于串口的API
  详细解决方案

请教应用程序中有哪些关于串口的API

热度:85   发布时间:2016-04-28 12:40:54.0
请问应用程序中有哪些关于串口的API
请问应用程序中有哪些关于串口的API,CreateFile ReadFile WriteFile除外 比如我要配置波特率,新手求教
------解决方案--------------------

BOOL InitDCB()
{
DCB PortDCB;
DWORD dwError;

PortDCB.DCBlength = sizeof (DCB);     

//得到端口的默认设置信息
GetCommState (hPort, &PortDCB);

//改变DCB结构设置
PortDCB.BaudRate = GPSAUTOSETTIME_UART_BAUDRATE;   //波特率 
PortDCB.fBinary = TRUE;
PortDCB.fParity = TRUE;
PortDCB.fOutxCtsFlow = TRUE;
PortDCB.fOutxDsrFlow = FALSE;
PortDCB.fDtrControl = DTR_CONTROL_ENABLE; 
PortDCB.fDsrSensitivity = FALSE; 
//PortDCB.fTXContinueOnXoff = TRUE;    
PortDCB.fTXContinueOnXoff = FALSE;
PortDCB.fOutX = FALSE;            
PortDCB.fInX = FALSE;              
PortDCB.fErrorChar = FALSE;     
PortDCB.fNull = FALSE;           
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;  
PortDCB.fAbortOnError = FALSE;      
PortDCB.ByteSize = 8;            
PortDCB.Parity = NOPARITY;         
PortDCB.StopBits = ONESTOPBIT;        

//根据DCB结构配置端口 
if (!SetCommState (hPort, &PortDCB))
{
//不能配置串行端口
MessageBox (NULL, TEXT("Unable to configure the serial port"), 
TEXT("Error"), MB_OK);
dwError = GetLastError ();
return FALSE;
}

return TRUE;
}

//指定端口监测的事件集
SetCommMask (hPort, EV_RXCHAR);
//分配设备缓冲区
SetupComm(hPort,4096,4096);
//初始化缓冲区中的信息
PurgeComm(hPort,PURGE_TXCLEAR 
------解决方案--------------------
 PURGE_RXCLEAR);

InitDCB();

COMMTIMEOUTS CommTimeouts;
DWORD dwError;

//得到超时参数
GetCommTimeouts (hPort, &CommTimeouts);

//改变COMMTIMEOUTS结构设置
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;

//设置端口超时值 
if (!SetCommTimeouts (hPort, &CommTimeouts))
{
//不能设置超时值
MessageBox (NULL, TEXT("Unable to set the time-out parameters"), 
TEXT("Error"), MB_OK);
dwError = GetLastError ();
}

EscapeCommFunction (hPort, SETDTR);
EscapeCommFunction (hPort, SETRTS);
  相关解决方案