串口接收的十六进制字符串转换为十进制数字显示
如接收EB CC A0 FF ...
显示为235 204 160 255 ...
对C++ Builder 6 完全不懂。希望大侠能给个代码。感谢!
void __fastcall TForm1::MSComm1Comm(TObject *Sender)
{
char szBuf[500]={0};
int i, j;
OleVariant RxBuff;
switch (MSComm1-> CommEvent)
{
case comEvReceive:
if (MSComm1-> InBufferCount > 0) {
RxBuff= MSComm1-> Input;
j= RxBuff.ArrayHighBound(1);
for (i=0; i <=j; i++)
szBuf[i]= RxBuff.GetElement(i);
szBuf[i]= NULL;
//ifdef _DEBUG
Memo1->Text= Memo1->Text+AnsiString(szBuf);//显示在这里
//RichEdit1-> Lines-> Add(AnsiString(szBuf));
//#endif
}
break;
}
}
Memo1->Text= Memo1->Text + " " + IntToStr(StrToInt(String("0x") + szBuf));
TStringList *lst = new TStringList;
lst->Delimiter = ' ';
lst->DelimitedText = szBuf;
for (int i = 0; i < lst->Count; i++)
{
Memo1->Lines->Text = Memo1->Lines->Text
+ " " + IntToStr(StrToInt(String("0x") + lst->Strings[i]));
}
delete lst;