halcon 与PLC串口通信解决方案

来源:互联网 发布:数据的收集与整理 编辑:程序博客网 时间:2024/06/02 12:56
OpSystem := environment('OS')
if (OpSystem='Windows_NT')    open_serial ('COM1', SerialHandle)else    open_serial ('/dev/tty', SerialHandle)endifset_serial_param (SerialHandle, 9600, 8, 'none', 'none', 1, 1000, 'unchanged')write_serial (SerialHandle, ords('Hello world!\n\r'))while(1)   read_serial (SerialHandle, 10, Data)   if (|Data| > 0)       Read := chrt(Data)
       break   endif
endwhile
1、main主函数直接调用串口相关函数,如打开串口,设定串口参数,读写串口;
2、while(1)循环 做数据收到 读取PLC发来的接受信息,终止程序。
0 0
原创粉丝点击