MessageLink#
What is a Message Link?#
VEXlink enables an EXP Brain to communicate with another EXP Brain, allowing for point-to-point connections and the creation of communication meshes between multiple robots. It supports both wireless and wired communication, with wired connections recommending a modified smart cable to prevent power routing issues. For wireless communication, each robot needs a V5 Robot Radio connected to a Smart Port, and the VEXlink Radio can be used alongside a V5 Controller’s VEXnet radio, which should be connected to the highest numbered Smart Port to avoid conflicts.
The MessageLink class within VEXlink facilitates sending simple messages, such as “play” and “stop,” with minimal data to the connected robot.
Initializing the MessageLink Class#
A VEXlink is created by using the following constructor:
MessageLink(port, name, linktype, wired)
This constructor uses four parameters:
Parameter |
Description |
---|---|
|
A valid Smart Port that the VEXlink Radio is connected to. |
|
The name of this link. It is recommended that this unique string is long enough that when hashed by vexos it will create a unique ID. A bad link name would be something generic such as “vexlink” as it may be used by another team. |
|
The type of link, either |
|
Optional. Whether or not it is a wired link. Set to |
# Construct a VEXlink "link" with the MessageLink class.
link = MessageLink(Ports.PORT1, "Link", VexlinkType.MANAGER)
This link
object will be used in all subsequent examples throughout this API documentation when referring to MessageLink class methods.
Class Methods#
is_linked()#
The is_linked()
method returns the VEXlink’s current status.
Returns: True
if the VEXlink is active and connected to the paired Brain. False
if it is not.
send()#
The send(message, index, value)
method sends a message through the VEXlink.
Parameters |
Description |
---|---|
message |
The message to send. |
index |
Optional. An integer, such as a port number. |
value |
Optional. A float. |
Returns: The length of transmitted data or None
if there is an error.
# Send the message 'test' with no parameters.
link.send('test')
# Send the message 'test' with parameters.
link.send('test', 1, 3.14)
receive()#
The receive(timeout)
method receives a message from the VEXlink.
Parameters |
Description |
---|---|
timeout |
Optional. The timeout duration for receiving the message in milliseconds before the function returns. |
Returns: The received message or None
if there is an error.
received()#
The received(callback, arg)
method registers a callback function for when a message is received. If the message is omitted then the callback function will be called for all messages.
Parameters |
Description |
---|---|
callback |
The callback function to be called when a message is received. |
arg |
Optional. A tuple of arguments to pass to the callback function. |
Returns: None.
# Define a function message_received()
def message_received():
# The Brain will print that the message was received by
# the Message Link on the Brain's screen.
Brain.screen.print("message received")
# Run message_received() when a message is received.
link.received(message_received)
installed()#
The installed()
method checks if the VEXlink is connected.
Returns: True
if the VEXlink is connected. False
if it is not.