关于串口接收数据长度的一个简单问题
各位大虾好
这个程序郁闷了我一下午了,贴出来让大家看看哪里有问题
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
DynamicArray<byte> bSend;
if(txtPhone->Text.Length()!=11)
ShowMessage("手机号码位数不对!");
bSend.Length=13+txtInput->Text.Length();
bSend[0]=01;
bSend[1]=30;
for(i=0;i<11;i++)
bSend[i+2] = txtPhone->Text[i+1];
for(i=0;i<txtInput->Text.Length();i++)
{
bSend[i+13] = txtInput->Text[i+1];
}
Comm1->OutputByte(bSend);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Comm1ReceiveData(TObject *Sender)
{
TStringList * strList = new TStringList();
DynamicArray<byte> brec;
int i,j;
brec=Comm1->ReadInputByte();
j=brec.get_length();
for(i=0;i<j;i++)
{
strList->Add(brec[i]);
}
Label1->Caption = IntToStr(strList->Count);
}
strList->Count显示的始终和我想的不一样,难道接收的数据长度定义的不对?
哪位高手指点下,感激不尽啊~