Database 版 (精华区)

发信人: mengy (LEAR DLLS 命令时,将从内存中清除), 信区: Database
标  题: 串口通信实例
发信站: 哈工大紫丁香 (2000年12月30日19:13:11 星期六), 转信

 串口通信实例 

下列代码是一个控制串口的实例:
ole1:MSCOMM32控件;
SuperTracker:是一个接在串口上的设备;
chr()中的值是该设备的指令。

para nnn
serr=0
thisform.ole1.output=chr(2)+chr(6)+chr(3)
ltime=datetime()
do whil thisform.ole1.InBufferCount=0
if datetime()-ltime>12
=msg("警告","得不到SuperTracker的控制信号。","!O")
thisform.ole1.portopen=.f.
serr=1
retu
endif
enddo
mscomm=thisform.ole1.input
if str(mscomm(1),1)+str(mscomm(2),1)+str(mscomm(3),1)<>'263'
=msg("警告","得不到SuperTracker的控制信号。","!O")
thisform.ole1.portopen=.f.
serr=1
retu
endif
do case
case nnn=1
thisform.ole1.output=chr(2)+chr(35)+chr(83)+chr(3)
case nnn=2
thisform.ole1.output=chr(2)+chr(35)+chr(85)+chr(3)
case nnn=3
thisform.ole1.output=chr(2)+chr(35)+chr(66)+chr(3)
endcase
ltime=datetime()
do whil thisform.ole1.InBufferCount=0
if datetime()-ltime>20
=msg("警告","得不到SuperTracker的控制信号。","!O")
thisform.ole1.portopen=.f.
serr=1
retu
endif
enddo
mscomm=thisform.ole1.input
if str(mscomm(1),1)+str(mscomm(2),1)+str(mscomm(3),1)<>'263'
do case
case nnn=1
=msg("警告","SuperTracker无法进卡。","!O")
case nnn=2
=msg("警告","SuperTracker卡在里面。","!O")
case nnn=3
=msg("警告","SuperTracker卡在出口处。","!O")
endcase
thisform.ole1.portopen=.f.
serr=1
retu
endif

 
转载自Foxpro爱好者天堂(文/dbin) 
 
返回首页
 

 

 
--

       大海无边天做岸
               山登绝顶我为风

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.121]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.752毫秒