发表于:2007/4/29 16:11:00
#0楼
////////////////////////////读计数器命令/////////////////////////////////////////
UINT ReadCountOrder(LPVOID pParam)
{
CView2* pV2=(CView2*)pParam;
CString order;
BYTE str[17]={'@','0','0','R','C','0','0','0','0','0','0','0','1',0,0,'*',13};
pV2->Xor(str,12);
for(int i=0;i<17;i++)
{
order+=str[i];
}
OVERLAPPED m_osWrite;
memset(&m_osWrite,0,sizeof(OVERLAPPED));
m_osWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesWrite=17;
DWORD dwErrorFlags;
BOOL bReadOrderStat;
COMSTAT ComStat;
while(1)
{
ClearCommError(pV2->hCom1,&dwErrorFlags,&ComStat);
PurgeComm(pV2->hCom1, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
bReadOrderStat=WriteFile(pV2->hCom1,order,dwBytesWrite,&dwBytesWrite,&m_osWrite);
if(!bReadOrderStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osWrite.hEvent,1000);
}
}
dwErrorFlags=GetLastError();
Sleep(500);
}
return 0;
}
//////////////////////////////////////读计数器数据////////////////////////
UINT ReadCountData(LPVOID pParam)
{
CView2* pV2=(CView2*)pParam;
char readdata[17];
OVERLAPPED m_osRead;
memset(&m_osRead,0,sizeof(OVERLAPPED));
m_osRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesRead=17;
DWORD dwErrorFlags;
BOOL bReadDataStat;
COMSTAT ComStat;
while(1)
{
memset(readdata,'\0',17);
ClearCommError(pV2->hCom1,&dwErrorFlags,&ComStat);
PurgeComm(pV2->hCom1, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
Sleep(500);
bReadDataStat=ReadFile(pV2->hCom1,readdata,dwBytesRead,&dwBytesRead,&m_osRead);//读数据
WaitForSingleObject(m_osRead.hEvent,INFINITE);
ResetEvent(m_osRead.hEvent);
if(!bReadDataStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osRead.hEvent,1000);
}
}
else
{
TRACE(readdata);
TRACE("数据");
}
}
return 0;
}
上面是我读计数器的两个线程,可是没有响应贞阿?ReadFile读的数据是空串,那位大虾知道什么原因阿
UINT ReadCountOrder(LPVOID pParam)
{
CView2* pV2=(CView2*)pParam;
CString order;
BYTE str[17]={'@','0','0','R','C','0','0','0','0','0','0','0','1',0,0,'*',13};
pV2->Xor(str,12);
for(int i=0;i<17;i++)
{
order+=str[i];
}
OVERLAPPED m_osWrite;
memset(&m_osWrite,0,sizeof(OVERLAPPED));
m_osWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesWrite=17;
DWORD dwErrorFlags;
BOOL bReadOrderStat;
COMSTAT ComStat;
while(1)
{
ClearCommError(pV2->hCom1,&dwErrorFlags,&ComStat);
PurgeComm(pV2->hCom1, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
bReadOrderStat=WriteFile(pV2->hCom1,order,dwBytesWrite,&dwBytesWrite,&m_osWrite);
if(!bReadOrderStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osWrite.hEvent,1000);
}
}
dwErrorFlags=GetLastError();
Sleep(500);
}
return 0;
}
//////////////////////////////////////读计数器数据////////////////////////
UINT ReadCountData(LPVOID pParam)
{
CView2* pV2=(CView2*)pParam;
char readdata[17];
OVERLAPPED m_osRead;
memset(&m_osRead,0,sizeof(OVERLAPPED));
m_osRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesRead=17;
DWORD dwErrorFlags;
BOOL bReadDataStat;
COMSTAT ComStat;
while(1)
{
memset(readdata,'\0',17);
ClearCommError(pV2->hCom1,&dwErrorFlags,&ComStat);
PurgeComm(pV2->hCom1, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
Sleep(500);
bReadDataStat=ReadFile(pV2->hCom1,readdata,dwBytesRead,&dwBytesRead,&m_osRead);//读数据
WaitForSingleObject(m_osRead.hEvent,INFINITE);
ResetEvent(m_osRead.hEvent);
if(!bReadDataStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osRead.hEvent,1000);
}
}
else
{
TRACE(readdata);
TRACE("数据");
}
}
return 0;
}
上面是我读计数器的两个线程,可是没有响应贞阿?ReadFile读的数据是空串,那位大虾知道什么原因阿