用MSComm控件实现对串口的操作。当对串口进行发送时,只能发送英文字符和数字,汉字却无法发送,但却又能正确接收汉字,以下是发送代码,请各位大虾看看有何问题,敬请指教!谢谢!
procedure TForm1.Button3Click(Sender: TObject); //单击按钮开始发送
begin
if mscomm2.portopen then
      mscomm2.portopen:=false;
Mscomm2.CommPort :=1;
Mscomm2.Settings :='9600,n,8,1';
mscomm2.PortOpen:=true;
mscomm2.RTSEnable:=true;
mscomm2.Output:=memo1.Lines.Text;
end;procedure TForm1.MSComm2Comm(Sender: TObject);  //oncomm事件
var
recstr:Olevariant;
begin
recstr:=memo1.Lines.Text;
 if Mscomm2.CommEvent = 1 then
     mscomm2.Output:=recstr;
end;

解决方案 »

  1.   

    >>当对串口进行发送时,只能发送英文字符和数字,汉字却无法发送,
    應該是可以的!你的代碼, 一時看不出問題
      

  2.   

    procedure TForm1.MSComm2Comm(Sender: TObject);  //oncomm事件
    var
    recstr:String;
    begin
      Mscomm2.InputMode := ComInputModeText;
     if Mscomm2.CommEvent = 1 then
         recstr:=mscomm2.Input;     //看看你接收到什么了  我刚试过 完全可以接收汉字!
    end;
      

  3.   

    另外,你的事件判断有问题。
    if Mscomm2.CommEvent = 1 then的意思是在传输缓冲区中有比Sthreshold数少的字符
    通常的做法应该是
    if Mscomm2.CommEvent = 2 then 意思是收到Rthreshole个字符,并且持续到用Input方法删除接收缓冲区数据为止
    故程序通常为
    procedure TForm1.MSComm2Comm(Sender: TObject);  //oncomm事件
    var
    recstr:String;
    begin
      Mscomm2.InputMode := ComInputModeText;
     if Mscomm2.CommEvent = 2 then
       begin
         Sleep(200); 
         recstr:=mscomm2.Input;     //看看你接收到什么了  我刚试过 完全可以接收汉字!
         
      end;
    end;
      

  4.   

    检查一下 MSComm32 是不是二进制模式,文本模式可能对中文有问题。另外,最好使用数组方式来发送接受,这样不受 \0 的影响。
    论坛上有很多例子自己搜索一下。
      

  5.   

    TO:  suuare(督察)
    我现在是能收到汉字,就是不能发送汉字!我给出的也是个发送的代码!
      

  6.   

    汉字的发送同一般数据的发送
    Mscomm2.OutPut := '你好!CSDN';