PB编程实时读取电子称(RS232 COM串口)

biaosun 2019-02-28 05:01:11
PB编程实时读取电子称(RS232 COM串口)?

下面是通过BUTTON的CLICKED事件,可以读出来。如何实时读取数据?

string ls_text,ls_flag
dec ldec_wt

ls_text = serial_port1.read(2000)
if isnull(ls_text) or ls_text='' or len(trim(ls_text))=0 then
return
end if
ls_text = trim(ls_text)
if pos(ls_text,'GGU')>0 then
ls_text =trim(mid(ls_text,1,pos(ls_text,'GGU')-1))
end if
if pos(ls_text,'GGS')>0 then
ls_text =trim(mid(ls_text,1,pos(ls_text,'GGS')-1))
end if
if pos(ls_text,'+')>0 then
ls_text =trim(mid(ls_text,pos(ls_text,'+')+1))
end if
if pos(ls_text,'+')>0 then
ls_text =trim(mid(ls_text,2))
end if
if isnumber(mid(ls_text,1,7)) then
ldec_wt = dec(mid(ls_text,1,7))
//清空
serial_port1.write('')
sle_1.text = string(ldec_wt)
if ls_flag='N' then
st_2.text = 'g'
else
st_2.text = 'g'
end if
else
setnull(ldec_wt)
end if
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjl8008 2019-03-01
  • 打赏
  • 举报
回复
用timer定时读取端口,实例变量保存读到的内容,当有结束符号时处理,处理完清空实例变量,开始下一读取过程

680

社区成员

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

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