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.这是一个串口接收的程序,可是就是无法再窗口显示它接收的数据
大家帮我看看程序有没有什么问题

解决方案 »

  1.   

    在用 串口调试器 向我编写的串口接收器发送时, 虚拟串口显示 com1 com2 均打开 ,参数设置 9600 n 8 1 一致 ,而且com1 发送数据量和com2接收数据量一致。 我认为com1发送的数据com2已经接收到了 可能在显示这一块出现了问题 但我没法查出原因 还请大家不吝赐教
      

  2.   

    Mscomm1.Settings :=ComboBox1.Text;
    我是直接读取了ComboBox1.Text的内容 虚拟串口显示 com1 com2 参数设置均为 9600-n-8-1 
      

  3.   

    测试:发送端采用 网上下载的 串口调试助手,9600,n,8,1 Com2接收端就用楼主的程序,设置 9600,n,8,1 Com1接收正常。
      

  4.   

    软件就是我说的那些,源码就用的你的。硬件:本机双串口,Com2串口调试助手发送,Com1就现采用你的程序接收。
      

  5.   

    你用两个现成的串口调试助手,一个Com1发送,一个Com2接收,先看看你的硬件有没问题
      

  6.   

    朋友 咱QQ 聊吧 我QQ 号码 已经通过社区消息发给你了