我用MSComm接收二进制数据,接收不到,求各位大哥帮忙
OleVariant RxBuff;
int bytenum;
char c1;
char c2;
AnsiString st1= " "; //保存串口传送来的字符
if(MSComm1-> InBufferCount> 0 && MSComm1-> InputMode==1)
{
RxBuff=MSComm1-> Input;
bytenum=RxBuff.ArrayHighBound(1);
int i=0;
while(i <bytenum)
{
c1=RxBuff.GetElement(i);
IntToHex(c1,c2);
st1=st1+c2;
i++;
}
}
StringGrid1->Cells[0][1]=st1;
程序为了转化为十六进制显示
inputmode 我设置为 1 了
[解决办法]
我截取出我的一段代码给你,希望你能看懂。
bCommand = Mono_Cmd_Goto;
TxBuff.PutElement(bCommand,0);
m_MSComm->Output = TxBuff;
FirstTickCount = GetTickCount();
do
{
Application->ProcessMessages() ;
SecondTickCount = GetTickCount();
if ((SecondTickCount-FirstTickCount)>5000)
{
break;
}
}while(m_MSComm->InBufferCount<1);
RxBuff = m_MSComm->Input;
ByteNum = RxBuff.ArrayHighBound(1);
if (ByteNum>=0)
{
Byte bOne = RxBuff.GetElement(0);
if (bOne==Mono_Cmd_Goto)
{
//可以设置波长
bBreak = true;
break;
}
}