unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls, XPMan;type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
ComboBox2: TComboBox;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
XPManifest1: TXPManifest;
procedure MSComm1Comm(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.MSComm1Comm(Sender: TObject);
var
recstr : OleVariant;
begin
if Mscomm1.CommEvent=2 then
begin
recstr := Mscomm1.Input ;
Memo1.Text := Memo1.Text+recstr;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Mscomm1.Settings :=ComboBox1.Text;
if ComboBox2.Text ='com1' then // 串口只有com1和com2两种情况
Mscomm1.CommPort :=1
else
Mscomm1.CommPort :=2;
Mscomm1.PortOpen :=true; // 打开串口
Mscomm1.DTREnable :=true; // 数据终端准备好
Mscomm1.RTSEnable :=true; // 请求发送
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Mscomm1.InBufferCount :=0; // 清空接收缓冲区
Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Mscomm1.PortOpen :=false; // 关闭串口
Mscomm1.DTREnable :=false;
Mscomm1.RTSEnable :=false;
end;end.这是一个串口接收的程序,可是就是无法再窗口显示它接收的数据
大家帮我看看程序有没有什么问题
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls, XPMan;type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
ComboBox2: TComboBox;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
XPManifest1: TXPManifest;
procedure MSComm1Comm(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.MSComm1Comm(Sender: TObject);
var
recstr : OleVariant;
begin
if Mscomm1.CommEvent=2 then
begin
recstr := Mscomm1.Input ;
Memo1.Text := Memo1.Text+recstr;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Mscomm1.Settings :=ComboBox1.Text;
if ComboBox2.Text ='com1' then // 串口只有com1和com2两种情况
Mscomm1.CommPort :=1
else
Mscomm1.CommPort :=2;
Mscomm1.PortOpen :=true; // 打开串口
Mscomm1.DTREnable :=true; // 数据终端准备好
Mscomm1.RTSEnable :=true; // 请求发送
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Mscomm1.InBufferCount :=0; // 清空接收缓冲区
Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Mscomm1.PortOpen :=false; // 关闭串口
Mscomm1.DTREnable :=false;
Mscomm1.RTSEnable :=false;
end;end.这是一个串口接收的程序,可是就是无法再窗口显示它接收的数据
大家帮我看看程序有没有什么问题
我是直接读取了ComboBox1.Text的内容 虚拟串口显示 com1 com2 参数设置均为 9600-n-8-1