码迷,mamicode.com
首页 > 其他好文 > 详细

HALCON串口通讯程序

时间:2015-11-12 10:02:37      阅读:1903      评论:0      收藏:0      [点我收藏+]

标签:

串口通讯程序

 
* Note: This example is meant to demonstrate the use of the serial interface
* of HALCON.  On Unix machines, the output and input is from /dev/tty, i.e., the
* window from which you have started HDevelop.  On Windows NT machines,
* this program will only run if you have a device attached to COM1.
* Open the serial interface (for reading and writing).
OpSystem := environment(‘OS‘)
if (OpSystem == ‘Windows_NT‘)
    open_serial (‘COM1‘, SerialHandle)
else
*     open_serial (‘/dev/tty‘, SerialHandle)
endif
* Set the parameters of the serial interface (e.g., a character-based terminal).
set_serial_param (SerialHandle, 9600, 8, ‘none‘, ‘none‘, 1, 1000, ‘unchanged‘)
* Display a nice message on the terminal.
write_serial (SerialHandle, ords(‘11,12,1‘))
* Now read 10 characters from the terminal...
while(1)
read_serial (SerialHandle, 2, Data)
* ...and if the user typed some characters within the one second...
if (|Data| > 0)
    * ...convert the read data to a string.
    Read := chrt(Data)
    if(Read=‘A0‘)
        break
    endif
endif
wait_seconds (0.1)
endwhile
stop ()
* Finally, close the serial interface so other programs can use it.
close_serial (SerialHandle)
 

HALCON串口通讯程序

标签:

原文地址:http://www.cnblogs.com/wenluderen/p/4957964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!