serial.hdev

* 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('Hello world!\n\r'))
* Now read 10 characters from the terminal...
read_serial (SerialHandle, 10, 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)
endif
* Finally, close the serial interface so other programs can use it.
close_serial (SerialHandle)

你可能感兴趣的:(笔记,学习)