Mscomm问题,为什么我的mscomm的oncomm事件的接收中只有八个字符?我mscomm1.RThreshold:=1;其余的另外在触发oncom事件?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        MSComm1: TMSComm;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure MSComm1Comm(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      mscomm1.InBufferCount:=0;
      mscomm1.RThreshold:=1;
      mscomm1.InputLen:=0;
      Mscomm1.Settings :='9600,n,8,1';
      Mscomm1.CommPort :=1;
      try
        mscomm1.PortOpen:=true;
      except
      end;
    end;procedure TForm1.MSComm1Comm(Sender: TObject);
    var
       str:string;
       len:word;
    begin
      str:=mscomm1.Input;
      len:=mscomm1.InBufferCount;
      memo1.Lines.Add(str+inttostr(len));
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin  mscomm1.Output:='212312312312';end;end.
    //代码没
      

  2.   

    另外InputMode 设为comInputModeBinary
      

  3.   

    mscomm1.RThreshold:=1设为12就可以,不过会引发其他问题,研究中!!!