用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;
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;
解决方案 »
- DBctrlgrid如何控制一行数据不参与任何操作?
- 有Treeview1,我想根据string: '1'来找到reeview1中的'仓房1'结点,并把当前选中结点设为该结点,该怎么写代码
- 为什么socketconnection 总连不上
- 我想以IE做为客户端。SQL为数据库。有什么好的建议吗?
- 两个简单的问题?望高人指点
- 请兄弟们帮忙将一个C函数声明翻译成Pascal的,40分!
- (高分)请教高手:如何将listview控件中的内容以报表方式打印出来?
- 什么情况下产生EinvalidPointer异常
- 有没有人用TDP网络协议作过开发阿 ?
- 我怎样才能定位到我想要的数据条上呀,请指教,加分
- 继承类能执行为什么父类执行的时候结果不一样?不是见鬼吧?
- 请牛人帮忙解决星号密码查看器!
應該是可以的!你的代碼, 一時看不出問題
var
recstr:String;
begin
Mscomm2.InputMode := ComInputModeText;
if Mscomm2.CommEvent = 1 then
recstr:=mscomm2.Input; //看看你接收到什么了 我刚试过 完全可以接收汉字!
end;
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;
论坛上有很多例子自己搜索一下。
我现在是能收到汉字,就是不能发送汉字!我给出的也是个发送的代码!
Mscomm2.OutPut := '你好!CSDN';