帮忙看一下,我这个程序怎么会接收到乱码 ( 积分: 100 )

  • 主题发起人 zhangchunzhao
  • 开始时间
Z

zhangchunzhao

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;

type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
flatMemo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
senddate:array of String;
i:longint;
sendstr:string;
begin
MSComm1.CommPort:=1; //指定端口
MSComm1.Settings:='9600,n,8,1'; //其他参数
MSComm1.OutBufferSize:=1024; //发送缓冲区
MSComm1.InputMode:=comInputModeBinary; //接收模式
MSComm1.InBufferSize:=1024; // 接收缓冲区
MSComm1.InputLen:=0; //一次读取所有数据
MSComm1.SThreshold:=0; //一次发送所有数据
if MSComm1.PortOpen=False then MSComm1.PortOpen:=true;
MSComm1.RThreshold:=16; //设置接收多少字节开产生oncomm事件
SetLength(senddate, 10);
senddate[1]:='a';
senddate[2]:='b';
senddate[3]:='m';
senddate[4]:='k';
senddate[5]:='h';
sendstr:=' ';
for i:=1 to 5 do
sendstr:=senddate+sendstr;

//showmessage(sendstr);
MSComm1.Output:=sendstr;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i:longint;
sendstr:string;
restr:string;
redate:String;
begin
// showmessage(inttostr(MSComm1.InBufferCount));
redate:=MSComm1.Input;
//showmessage(reda te);
restr:=' ';
for i:=1 to 5 do
restr:=restr + redate+' ';
flatmemo1.Text:=restr;
MSComm1.PortOpen:=false;
end;

end.
 
Z

zhangchunzhao

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;

type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
flatMemo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
senddate:array of String;
i:longint;
sendstr:string;
begin
MSComm1.CommPort:=1; //指定端口
MSComm1.Settings:='9600,n,8,1'; //其他参数
MSComm1.OutBufferSize:=1024; //发送缓冲区
MSComm1.InputMode:=comInputModeBinary; //接收模式
MSComm1.InBufferSize:=1024; // 接收缓冲区
MSComm1.InputLen:=0; //一次读取所有数据
MSComm1.SThreshold:=0; //一次发送所有数据
if MSComm1.PortOpen=False then MSComm1.PortOpen:=true;
MSComm1.RThreshold:=16; //设置接收多少字节开产生oncomm事件
SetLength(senddate, 10);
senddate[1]:='a';
senddate[2]:='b';
senddate[3]:='m';
senddate[4]:='k';
senddate[5]:='h';
sendstr:=' ';
for i:=1 to 5 do
sendstr:=senddate+sendstr;

//showmessage(sendstr);
MSComm1.Output:=sendstr;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i:longint;
sendstr:string;
restr:string;
redate:String;
begin
// showmessage(inttostr(MSComm1.InBufferCount));
redate:=MSComm1.Input;
//showmessage(reda te);
restr:=' ';
for i:=1 to 5 do
restr:=restr + redate+' ';
flatmemo1.Text:=restr;
MSComm1.PortOpen:=false;
end;

end.
 
Z

zhangchunzhao

Unregistered / Unconfirmed
GUEST, unregistred user!
高手们,帮我看一下,小弟在这里谢过了。
 
顶部