串行链路#
什么是串行链路?#
VEXlink 使一个 EXP Brain 能够与另一个 EXP Brain 通信,从而实现点对点连接并在多个机器人之间创建通信网格。它支持无线和有线通信,有线连接建议使用改进的智能电缆,以防止电源布线问题。对于无线通信,每个机器人都需要一个连接到智能端口的 V5 机器人无线电,VEXlink 无线电可以与 V5 控制器的 VEXnet 无线电一起使用,后者应连接到编号最高的智能端口,以避免冲突。
VEXlink 中的 SerialLink 类允许在机器人之间发送数据流,传输和接收机器人都需要理解流的内容,此类通常用作更高层软件的一部分,根据需要对数据包进行编码和解码。
要创建 VEXlink,两个 EXP Brains 都必须连接到 V5 机器人无线电。
初始化 SerialLink 类#
使用以下构造函数创建 VEXlink:
The serial_link
constructor creates a serial_link object.
范围 |
描述 |
---|---|
|
VEXlink 无线电连接到的有效 智能端口。 |
|
此链接的名称。建议此唯一字符串足够长,以便在 vexos 进行哈希处理时能够创建唯一的 ID。不合适的链接名称可能是通用名称,例如“vexlink”,因为它可能会被其他团队使用。 |
|
The type of link, either |
|
Whether or not it is a wired link. Set to |
// Construct a VEXlink "seriallink" with the serial_link class.
serial_link seriallink = serial_link(PORT1, "Link", linkType::manager);
This seriallink
object will be used in all subsequent examples throughout this API documentation when referring to serial_link class methods.
类方法#
send()#
The send(buffer)
method sends a buffer through the serial link.
参数 |
描述 |
---|---|
缓冲 |
字符串或字节数组。要发送的消息。 |
**返回:**表示发送消息的长度的整数。
// Send the string 'test'.
seriallink.send('test');
receive()#
The receive(length, timeout)
method receives data from the serial link.
参数 |
描述 |
---|---|
长度 |
等待的最大数据量。 |
暂停 |
函数返回之前的超时值(以毫秒为单位)。 |
**返回:**表示接收数据长度的整数。
// Wait for 128 bytes of data for 1000mS.
int buffer = seriallink.receive(128, 1000);
已收到()#
The received(callback)
method registers a callback function for when data is received.
参数 |
描述 |
---|---|
打回来 |
接收到数据时调用的回调函数。 |
**返回:**无。