Button1发送数据只能点一次,第二次就不发送了;
另外,我用其他工具发送数据,Memo1没反应呀。
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
ShowMessage("YbCommDevice1: "+e.Message);
}
//端口:1 偶校验 停止位为1 数据位为7
YbCommDevice1->PackageInterval = 50; //间隔为 50 毫秒, 根据实际情况设置
YbCommDevice1->PackageSize = 4096; //产生一次事件最多能够接收的字节数, 根据实际情况设置
YbCommDevice1->PackageType = cptFrameTimeout; //用判断时间间隔的方法接收数据
YbCommDevice1->UsePackage = true;
AnsiString s = "L1S#06001*";
YbCommDevice1->WritePackage(s.c_str(), s.Length());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::YbCommDevice1Package(TObject *Sender,
int NotifyType)
{
if(NotifyType & EV_RXCHAR)
{
const int BufSize = 4096;
char Buf[BufSize+1]; //多一个文本结束符
AnsiString s;
int n = YbCommDevice1->ReadPackage(Buf, BufSize);
if(n>0) //收到字节数
{
Buf[n] = 0; //添加一个文本结束符 '\0'
s+=Buf;
Memo1->Lines->Add(s);
}
}
}
//---------------------------------------------------------------------------
--------------------next---------------------
阅读(1078) | 评论(0) | 转发(0) |