急!请问各位大虾!重谢

faye_xuanyue 2006-07-13 09:54:18
我用的是VICTOR控件接受数据,请问如何将接受到的数据转换成十进制数显示

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
int t;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
try
{
YbCommDevice1->PortNo = 1; //COM1
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
ShowMessage("YbCommDevice1: "+e.Message);
}
t = 0;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::SetClick(TObject *Sender)
{
YbCommDevice1->SettingsDialog(this,true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
unsigned char Buf[8192]; //收到的字节数不会超过串口缓存的容量, 所以分配一个缓存容量相同的Buf
int n = YbCommDevice1->Read(Buf,8192); //收到 n 个字节
AnsiString s;

for(int i=0; i<n; i++)
s += IntToHex(Buf[i],2) + " ";
s = s.Trim();

if(!s.IsEmpty())
Memo1->Lines->Add(s);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Send1Click(TObject *Sender)
{
int nBytes = 0;
char Buffer[1000], *EndPtr;
AnsiString t,s = Edit1->Text.Trim();
while(s.Length()>0)
{
int p = s.Pos(' '); //空格
if(p>0)
{
t = s.SubString(1,p-1);
s = s.SubString(p+1,s.Length()).Trim();
Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //十六进制字符串转成字节
}
else //还剩下最后一个字节
{
t = s;
s = "";
Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //十六进制字符串转成字节
}
}
YbCommDevice1->Write(Buffer,nBytes);


}
我用的是VICTOR控件接受数据,请问如何将接受到的数据转换成十进制数显示
...全文
201 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
faye_xuanyue 2006-07-13
  • 打赏
  • 举报
回复
我知道了
faye_xuanyue 2006-07-13
  • 打赏
  • 举报
回复
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
int t;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
try
{
YbCommDevice1->PortNo = 1; //COM1
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
ShowMessage("YbCommDevice1: "+e.Message);
}
t = 0;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::SetClick(TObject *Sender)
{
YbCommDevice1->SettingsDialog(this,true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
unsigned char Buf[8192]; //收到的字节数不会超过串口缓存的容量, 所以分配一个缓存容量相同的Buf
int n = YbCommDevice1->Read(Buf,8192); //收到 n 个字节
AnsiString s;

for(int i=0; i<n; i++) 〈
s += IntToHex(Buf[i],2) + " "; 〈-————在这个位置怎么改
s = s.Trim(); 〈

if(!s.IsEmpty())
Memo1->Lines->Add(s);
}
//---------------------------------------------------------------------------
faye_xuanyue 2006-07-13
  • 打赏
  • 举报
回复
没太看明白啊!能不能说的更详细些啊 谢谢
jiangshx 2006-07-13
  • 打赏
  • 举报
回复
UCHAR a=0x31;
AnsiString str;
char chr;
str=IntToHex(a,2);
Edit1->Text=str; //显示31
str=a;
Edit2->Text=str; //显示49
chr=a;
Edit3->Text=chr; //显示1

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧