HALCON串口通讯程序

时间:2023-03-09 15:37:07
HALCON串口通讯程序

串口通讯程序

* 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)