3.2. Multi-device Communication¶
-
multi_comm_ctrl.
set_group
(send_group, recv_group_list)¶ Description: Sets the group number of the device to
send_group
, and the device can receive messages from the group numbers registered inrecv_group_list
. If the ``recv_group_list’’ parameter is not used, messages from group 0 will be received by default.Parameters: - send_group (int) – The sending group number of the current device. The default group number is 0.
- recv_group_list (list/tuple) – The current list of groups that receive messages, whose type can be list or tuple
Returns: None
Example: multi_comm_ctrl.set_group(1, (1,2,3))
Example description: Set the current sending group number to 1 and receive messages from groups 1, 2, and 3. If the receiving group includes the sending group, you will receive the messages you send.
-
multi_comm_ctrl.
send_msg
(msg, group)¶ Description: Send a message via multi-device communication. Sending groups for this message can be set separately.
Parameters: - msg (int) – The message that needs to be sent
- group (int) – An optional parameter, which specifies the current message sending group number. If you do not specify this parameter, the previously set group number will be used by default.
Returns: None
Example: multi_comm_ctrl.send_msg('RoboMaster EP', 3)
Example description: Send the
'RoboMaster EP'
message to group 3
-
multi_comm_ctrl.
recv_msg
(timeout)¶ Description: Receive messages (valid when recv_callback is not registered). You can set a timeout period. Parameters: timeout (int) – The waiting time, which indicates the waiting time of the receiving function, whose accuracy is 1 second. The default value of this parameter is 72 seconds. Returns: <msg_group>, <msg>
, which is the group number of the message sender and the content of the messageExample: group, recv_msg = multi_comm_ctrl.recv_msg(30)
Example description: Receive the message with a waiting time of 30 seconds, where “group” is the group number of the message sender, and “msg” is the content of the received message
-
multi_comm_ctrl.
register_recv_callback
(callback)¶ Description: Registers the callback function for receiving messages. When a message is received, the callback function is run automatically. Parameters: callback (function) – The callback function to be registered. The prototype of the callback function is def callback(msg)
, where the type of themsg
parameter is the(msg_group, msg)
tuple.Returns: None Example:
1 2 3 4 5 6 | #Define a function and register it as a callback function for receiving messages
def recv_callback(msg):
pass
multi_comm_ctrl.register_recv_callback(recv_callback)
|
Hint
For a description of the module, refer to Multi-device Communication.