WriteToPort("#@"); //向串口发数据
Sleep(200); //等待接收数据,另还有什么更好的方法判断接收完毕!
char* sTempbuf=new char[6];
strcpy(sTempbuf,m_Buf);
int result=strcmp(sTempbuf,TempBuf);
delete [] sTempbuf; //程序运行到这要出错,为什么?
if(result==0)
{
strcpy(TempBuf,cNewPaswd);
TestBuf[0]='……';
WriteToPort(TestBuf); //再向串口发数据,但好象没运行。为什么?
Sleep(100); //同上
if (m_bThreadAlive) //关闭监听线程
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE("Thread ended\n");
delete [] m_writebuf; //全局指针销毁
}
if(m_Buf[0]==TempBuf[5])
{
m_Buf.Empty();
return 1;
}
else
{
m_Buf.Empty();
return 0;
}
}
else
{
if (m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE("Thread ended\n");
delete [] m_writebuf;
}
m_Buf.Empty();
return 0;
}
大家帮帮找找问题,谢谢了!
Sleep(200); //等待接收数据,另还有什么更好的方法判断接收完毕!
char* sTempbuf=new char[6];
strcpy(sTempbuf,m_Buf);
int result=strcmp(sTempbuf,TempBuf);
delete [] sTempbuf; //程序运行到这要出错,为什么?
if(result==0)
{
strcpy(TempBuf,cNewPaswd);
TestBuf[0]='……';
WriteToPort(TestBuf); //再向串口发数据,但好象没运行。为什么?
Sleep(100); //同上
if (m_bThreadAlive) //关闭监听线程
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE("Thread ended\n");
delete [] m_writebuf; //全局指针销毁
}
if(m_Buf[0]==TempBuf[5])
{
m_Buf.Empty();
return 1;
}
else
{
m_Buf.Empty();
return 0;
}
}
else
{
if (m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE("Thread ended\n");
delete [] m_writebuf;
}
m_Buf.Empty();
return 0;
}
大家帮帮找找问题,谢谢了!
会不会出现缓冲区溢出的现象
delete [] sTempbuf; //程序运行到这要出错,为什么?
这句怎么都会出错?
谢谢哈!
我现在想解决的问题是连续发2次但第2次好象没发,开始以为是等待时间不够,但加大后还是不行,如果我在第2个WRITEPORT前加个AfxMessageBox弹个消息框却可以完成第2次发送。????????
否则程序运行到这就要出错。
debug assertion failed!
afx.inl出错!
delete sTempbuf; //程序运行到这要出错,为什么?
本身的错误,和串口无关。
因为就常接触到的这几类通信中,发送是我们可以控制的,
而接收是不可控制的,必须另起监听线程来进行操作
参考MSDN->Platform SDK->base service->HardWare->communication resource->communication reference