MSCOMM控件的串口通信,可以正常发送,但是接收不到?请高手指点

puxidong 2006-03-01 05:05:39
大虾,好。我在PB9中用MSCOMM控件做串口通信测试,可以正常发送,但是接收时(采用COM1的2/3脚短路)总是接收不到信息。下面是我的代码,请高手指点,谢谢。
...全文
287 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
张三san 2006-04-04
  • 打赏
  • 举报
回复
把ole_1.object.portopen=false 去掉
把第二次出现的语句ole_1.object.portopen=true去掉
moyo 2006-04-03
  • 打赏
  • 举报
回复
LZ的开发环境是什么样的?
接收不到数据,那一定是你的代码有问题。

我估计是你串口接收缓冲区里的数据被你清空了:
你用了:ole_1.object.portopen=false。这时候就被清空了。

wfliu 2006-03-02
  • 打赏
  • 举报
回复
参考下面:
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=205255
puxidong 2006-03-01
  • 打赏
  • 举报
回复
在按钮的CLICKED事件下面写的发送代码如下:
string str
long cport=1
if rb_1.checked=true then cport=1
if rb_2.checked=true then cport=2
if rb_3.checked=true then cport=3
if rb_4.checked=true then cport=4
ole_1.object.commport=cport
ole_1.object.portopen=true
str=""
str=str+char(27)+char(91)+char(72)
str=str+sle_1.text+"~r~n"
str=str+char(27)+char(91)+char(66)
str=str+sle_2.text+"~r~n"
mle_1.text=str+"~r~n"
ole_1.object.output=str
ole_1.object.portopen=false
在另一按钮的CLICKED事件以及OLE的ONCOMM事件下面写的接收代码如下:
string str
long cport=1
if rb_1.checked=true then cport=1
if rb_2.checked=true then cport=2
if rb_3.checked=true then cport=3
if rb_4.checked=true then cport=4
ole_1.object.commport=cport
ole_1.object.portopen=true
str=ole_1.object.input
if str="" then

else
mle_2.text=str
messagebox("提示信息","能从串口接收数据!")
end if
ole_1.object.portopen=false
OLE控件除开RTHRESHOLD属性设为1外其他都采用默认设置,请高手指点谢谢!

681

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧