我用一段代码测试如下:
void __fastcall TForm1::YbCommDevice1CommNotify(TObject *Sender,
int NotifyType)
{
AnsiString s;
if(NotifyType & EV_RXCHAR) //如果 NotifyType 的 RXCHAR 位为 1
{
unsigned char Buf[8192];
int n = YbCommDevice1->Read(Buf,8192);
if (n==0) return;
for(int i=0;i s += IntToHex(Buf[i],2);
Edit1->Text = s;
if(s=="238A") Edit1->Text = 1;
if(s=="2BAA") Edit2->Text = 1;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char testCommand[2], *EndPtr;
YbCommDevice1->PortNo = 1;
YbCommDevice1->Active = true;
YbCommDevice2->PortNo = 2;
YbCommDevice2->Active = true;
testCommand[0] = strtol("23", &EndPtr, 16);
testCommand[1] = strtol("8A", &EndPtr, 16);
YbCommDevice2->Write(testCommand,2);
testCommand[0] = strtol("2B", &EndPtr, 16);
testCommand[1] = strtol("AA", &EndPtr, 16);
YbCommDevice2->Write(testCommand,2);
}
//---------------------------------------------------------------------------
如果连续两次Write的话,好像OnCommNotify反应不过来,出来的结果是Edit1的文本为:238A2BAA,而不是238A和2BAA,请问这该如何是好?周五晚上我就有这种情况,我后来弄了个1秒的延时才可以。多谢!
--------------------next---------------------
阅读(1269) | 评论(0) | 转发(0) |