现在的情况是,一次只能发送7条数据,
我估计问题是,串口的输出缓冲区默认值是512字节,7条数据约为490,剩下的数据因为缓冲区满而无法写入,因此也无法送出.如是这边的问题,那应该如何解决呢,比如如何设置缓冲区的大小,及清空串口缓冲区的API是什么呢??
如果不是,又会是哪边的问题,该怎么解决呢??
我用的环境是VC6.0,我用了setOutBufferCount(),还有setOutBufferSize(),被提示无效.
多谢各位大哥帮忙!!!!!!
5 个解决方案
#1
设置缓冲区大小用:
BOOL SetupComm(HANDLE hFile, //通信设备句柄
DWORD dwInQueue, //输入缓冲区大小
DWORD dwOutQueue); //输出缓冲区大小
清空缓冲区可以用
BOOL ClearCommError(HANDLE hFile,
LPWORD lpErrors,
LPCOMSTAT lpStat);
BOOL SetupComm(HANDLE hFile, //通信设备句柄
DWORD dwInQueue, //输入缓冲区大小
DWORD dwOutQueue); //输出缓冲区大小
清空缓冲区可以用
BOOL ClearCommError(HANDLE hFile,
LPWORD lpErrors,
LPCOMSTAT lpStat);
#2
能给出具体用法吗?小弟初次尝试串口编程,有很多地方不是很熟悉
#3
清空串口缓冲区用:
PurgeComm( idComDev, PURGE_RXCLEAR);
PurgeComm( idComDev, PURGE_RXCLEAR);
#4
这是我写的一个发送函数:
size是发送字符串的长度;
int SendComm(const char *CommData,int size)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL m_wb = false;
DWORD length = 0;
COMSTAT ComStat;
LPDWORD ComError;
ClearCommBreak(m_hIDComDev);
ClearCommError(m_hIDComDev,ComError,&ComStat);
PurgeComm(m_hIDComDev,PURGE_TXCLEAR); //清空发送缓冲区
m_wb = WriteFile(m_hIDComDev, (LPSTR)CommData, size, &length, &m_OverlappedWrite);
if (WaitForSingleObject(m_OverlappedWrite.hEvent, 1000))
length = 0;
else
{
GetOverlappedResult(m_hIDComDev, &m_OverlappedWrite, &length, FALSE);
m_OverlappedWrite. Offset += length;
}
length++;
return m_wb;
}
#5
全局量定义在这:
CComDllApp theApp;
HANDLE m_hIDComDev;
OVERLAPPED m_OverlappedRead, m_OverlappedWrite;
CComDllApp theApp;
HANDLE m_hIDComDev;
OVERLAPPED m_OverlappedRead, m_OverlappedWrite;
#1
设置缓冲区大小用:
BOOL SetupComm(HANDLE hFile, //通信设备句柄
DWORD dwInQueue, //输入缓冲区大小
DWORD dwOutQueue); //输出缓冲区大小
清空缓冲区可以用
BOOL ClearCommError(HANDLE hFile,
LPWORD lpErrors,
LPCOMSTAT lpStat);
BOOL SetupComm(HANDLE hFile, //通信设备句柄
DWORD dwInQueue, //输入缓冲区大小
DWORD dwOutQueue); //输出缓冲区大小
清空缓冲区可以用
BOOL ClearCommError(HANDLE hFile,
LPWORD lpErrors,
LPCOMSTAT lpStat);
#2
能给出具体用法吗?小弟初次尝试串口编程,有很多地方不是很熟悉
#3
清空串口缓冲区用:
PurgeComm( idComDev, PURGE_RXCLEAR);
PurgeComm( idComDev, PURGE_RXCLEAR);
#4
这是我写的一个发送函数:
size是发送字符串的长度;
int SendComm(const char *CommData,int size)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL m_wb = false;
DWORD length = 0;
COMSTAT ComStat;
LPDWORD ComError;
ClearCommBreak(m_hIDComDev);
ClearCommError(m_hIDComDev,ComError,&ComStat);
PurgeComm(m_hIDComDev,PURGE_TXCLEAR); //清空发送缓冲区
m_wb = WriteFile(m_hIDComDev, (LPSTR)CommData, size, &length, &m_OverlappedWrite);
if (WaitForSingleObject(m_OverlappedWrite.hEvent, 1000))
length = 0;
else
{
GetOverlappedResult(m_hIDComDev, &m_OverlappedWrite, &length, FALSE);
m_OverlappedWrite. Offset += length;
}
length++;
return m_wb;
}
#5
全局量定义在这:
CComDllApp theApp;
HANDLE m_hIDComDev;
OVERLAPPED m_OverlappedRead, m_OverlappedWrite;
CComDllApp theApp;
HANDLE m_hIDComDev;
OVERLAPPED m_OverlappedRead, m_OverlappedWrite;