Halcon串口配置

open_serial( : : PortName : SerialHandle)

打开串口

close_serial( : : SerialHandle : )

关闭串口

set_serial_param( : : SerialHandle, BaudRate, DataBits, FlowControl, Parity, StopBits, TotalTimeOut, InterCharTimeOut : )

配置串口
TotalTimeOut:总超时间隔,包含接收第一个字节的等待超时和接收两个字节之间的等待超时
InterCharTimeOut :接收两个字节之间的等待超时,这个数值要小于总超时间隔
如果TotalTimeOut和InterCharTimeOut 其中的一个设置为-1,则read_serial会一直等待到读取到NumCharacters个字节后才返回

read_serial( : : SerialHandle, NumCharacters : Data)

NumCharacters:读NumCharacters个字节后返回,如果到达等待超时时间,直接返回


tuple_chr — Convert a tuple of integer numbers into strings of length 1.
将整数元组转换成单个元素长度为1的字符串元组
tuple_chrt — Convert a tuple of integer numbers into strings.
将整数元组转换成字符串元组
tuple_chrt配合read_serial使用

tuple_chr ( [72, 101, 108, 108, 111, 10, 13], Chr)
tuple_chrt ( [72, 101, 108, 108, 111, 10, 13], Chrt)
Chr := ['H', 'e', 'l', 'l', 'o', '\n', '\r']
Chrs := ['Hello\n\r']


write_serial( : : SerialHandle, Data : )

一次性写完所有数据后返回,无超时等待机制


tuple_ord — Convert a tuple of strings of length 1 into a tuple of integer numbers.
将单个元素长度为1的字符串元组转换成整数元组
tuple_ords — Convert a tuple of strings into a tuple of integer numbers.
将字符串元组转换成整数元组
tuple_ords 配合write_serial使用

tuple_ords (['Hello', '\n\r'], Ords)
tuple_ord (['H', 'e', 'l', 'l', 'o', '\n', '\r'], Ord)
Ords := [72, 101, 108, 108, 111, 10, 13]
Ord := [72, 101, 108, 108, 111, 10, 13]

总的Demo

open_serial ('COM1', SerialHandle)
* Set the parameters of the serial interface (e.g., a character-based terminal).
set_serial_param (SerialHandle, 9600, 8, 'none', 'none', 1, 2000, 100)
* 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, 100, 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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值