您的位置:首页 > 其它

halcon 与PLC串口通信解决方案

2016-03-29 22:39 337 查看
OpSystem := environment('OS')
if (OpSystem='Windows_NT')
open_serial ('COM1', SerialHandle)
else
open_serial ('/dev/tty', SerialHandle)
endif

set_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发来的接受信息,终止程序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: