PB编程实时读取电子称(RS232 COM串口)
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