各位大哥,我是刚开始学做串口的,下面这段代码为什么不能把 'abcdefghijklmnopqrstuvwxyz' 输出到MEMO1中去啊。
是哪里漏了什么么?谢谢了。procedure TForm1.FormCreate(Sender: TObject);
begin
    if MSComm1.PortOpen then MSComm1.PortOpen := false;//关闭端口
  MSComm1.CommPort := 1;//设置端口1
  MSComm1.InBufferSize := 512;//设置接收缓冲区为512个字节
  MSComm1.OutBufferSize := 512;//设置发送缓冲区为512个字节
  MSComm1.Settings := '9600,n,8,1';//9600波特率,无校验,8位数据位,1位停止位
  MSComm1.InputLen := 0;//读取缓冲区全部内容(26个字节)
  MSComm1.InBufferCount := 0;// 清除接收缓冲区
  MSComm1.OutBufferCount:=0;// 清除发送缓冲区
  MSComm1.RThreshold := 26;//设置接收26个字节产生OnComm 事件
  MSComm1.InputMode := comInputModeText;//文本方式
//  MSComm1.InputMode := comInputModeBinary;//二进制方式
  MSComm1.PortOpen := true;//打开端口
  mscomm1.RTSEnable:=true;
  mscomm1.DTREnable:=true;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  mscomm1.Output:='abcdefghijklmnopqrstuvwxyz';
end;procedure TForm1.MSComm1Comm(Sender: TObject);
begin
  case mscomm1.CommEvent of
    2:memo1.Text:=memo1.Text+mscomm1.Input;
  end;
end;

解决方案 »

  1.   

    只需设置 端口,MSComm1.RThreshold :=1;MSComm1.Settings := '9600,n,8,1'就可以了,其他默认,试试看
      

  2.   

    使用MScomm控件不要设置那么多的啊 
    还有下面的代码看着不怎么对劲  把错误代码贴下
    因为我正好在做短信包
      

  3.   

    var
      inbuff:array of Byte;
      i:integer;
      tempstr:string;
    begin
      If MScomm1.CommEvent=2 Then
         Begin
         sleep(100);
         Setlength(inbuff,MScomm1.InBufferCount);//设置接收数组的长度
         Inbuff:=MScomm1.Input;//将串口接收的数据置入动态数组
         Tempstr:='';
         For i:=0 To length(inbuff)-1 do
           Tempstr:=Tempstr+inttostr(inbuff[i])+'';
         memo2.Lines.Add(Tempstr);
         End;
    end;
    也许会对你有帮助 自己看
      

  4.   

    楼主能否把代码发给我看看?[email protected]
    不胜感激了。