• VEXcode Robotics Logo VEX Robotics Logo
  • VEX API Home Button VEX API Home Button
  • VEX 123 logo in purple VEX 123 logo in white
  • VEX GO logo in lime green VEX GO logo in white
  • VEXcode AIM logo in blue VEXcode AIM logo in white
  • VEX IQ logo in blue VEX IQ logo in white
  • VEX EXP logo in red VEX EXP logo in white
  • VEX V5 logo in red VEX V5 logo in white
  • VEX CTE logo in green VEX CTE logo in white
  • VEX AIR logo in orange VEX AIR logo in white
  • VEXcode VR logo in gold VEXcode VR logo in white
Μετάβαση στο κύριο περιεχόμενο
Ctrl+K

< Back to Platform Select

  • VEX V5
  • Αναφορά API VEX V5
  • VEXlink
  • Σύνδεσμος μηνύματος
Ελληνικά
  • English
  • Español
  • 简体中文
  • VEXcode Robotics Logo

Πλοήγηση ενότητας

  • Μπλοκ
  • Πύθων
  • C++
    • Σύστημα μετάδοσης κίνησης
    • Κινητήρες και Ελεγκτές Κινητήρων
    • Ελεγκτής
    • Εγκέφαλος
    • Ανταγωνισμός
    • Συσκευές Έξυπνης Θύρας
    • Συσκευές 3 καλωδίων
    • Κονσόλα
    • Λογική
    • VEXlink
      • Σύνδεσμος μηνύματος
      • Σειριακός σύνδεσμος
    • CTE Workcell
  • Εκπαιδευτικά σεμινάρια VEXcode

Πλοήγηση πλατφόρμας

  • VEX 123 logo in purple VEX 123 logo in white
  • VEX GO logo in lime green VEX GO logo in white
  • VEXcode AIM logo in blue VEXcode AIM logo in white
  • VEX IQ logo in blue VEX IQ logo in white
  • VEX EXP logo in red VEX EXP logo in white
  • VEX V5 logo in red VEX V5 logo in white
  • VEX CTE logo in green VEX CTE logo in white
  • VEX AIR logo in orange VEX AIR logo in white
  • VEXcode VR logo in gold VEXcode VR logo in white

Σύνδεσμος μηνύματος#

  • Εισαγωγή

  • Κατασκευαστές κλάσεων

  • Καταστροφέας κλάσης

  • Παράμετροι

  • Παράδειγμα

  • Συναρτήσεις Μελών

    • είναι συνδεδεμένο

    • στέλνω

    • λαμβάνω

    • έλαβε

Εισαγωγή#

The message_link class lets two V5 Brains communicate by sending short string messages with optional small data. It’s designed for robot-to-robot coordination — like starting routines, sharing sensor results, or triggering behaviors on another robot.

Every usage of send adds a message to the linked V5 Brain’s queue, and the queue is read first-in, first-out (FIFO). If multiple messages are sent before the other V5 Brain uses receive, they will be stored and returned one at a time in the order they were sent. Because messages can queue, repeatedly sending the same status every loop may create backlog; for time-critical logic, send only when values change.

Important: Both robots must be running projects that use message_link at the same time, or no messages will be sent/received.

Κατασκευαστές κλάσεων#

message_link( 
  int32_t     index, 
  const char  *name, 
  linkType    type, 
  bool        isWired = false );

Καταστροφέας κλάσης#

Destroys the message_link object and releases associated resources.

virtual ~message_link();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

index

int32_t

The Smart Port that the V5 Radio, or the Smart Cable, is connected to, written as PORTx, where x is the port number (for example, PORT1).

name

char

Το όνομα του συνδέσμου μηνύματος.

type

linkType

The type of link, either linkType::manager or linkType::worker. This information is used to correctly configure the radio and also determines available bandwidth for transmission and reception. A manager robot has double the available bandwidth (1040 bytes/second) to send information to the worker robot (520 bytes/second).

  • linkType::manager - The message_link object is a manager.
  • linkType::worker - The message_link object is a worker.

isWired

bool

Whether the message_link object is wired.

  • true - The message_link object is wired.
  • false - The message_link object is wireless.

Παράδειγμα#

Κωδικός για το Ρομπότ 1

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::manager, // type
  true); // isWired

Κωδικός για το Ρομπότ 2

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::worker, // type
  true); // isWired

Συναρτήσεις Μελών#

The message_link class includes the following member functions:

  • isLinked — Returns whether this Brain is actively connected to its paired Brain.

  • send — Sends a message to the paired Brain.

  • receive — Waits for and returns the next incoming message.

  • received — Registers a function to be called whenever a new message is received.

Before calling any message_link member functions, a message_link instance must be created, as shown below:

Κωδικός για το Ρομπότ 1

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::manager, // type
  true); // isWired

Κωδικός για το Ρομπότ 2

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::worker, // type
  true); // isWired

isLinked#

isLinked method returns whether the V5 Brains on a MessageLink are paired with one another.

Available Functions
bool isLinked();

Parameters

Αυτή η συνάρτηση δεν έχει παραμέτρους.

Return Values

Αυτή η συνάρτηση επιστρέφει μια λογική τιμή.

  • true – The two V5 Brains are paired and communicating on this link.

  • false – The two V5 Brains are not paired on this link.

Notes

Είναι καλή πρακτική να ελέγχετε πάντα για να βεβαιωθείτε ότι οι εγκέφαλοι V5 είναι συνδεδεμένοι στην αρχή ενός έργου πριν από την εκτέλεση οποιουδήποτε περαιτέρω κώδικα.

Examples

Κωδικός για το Ρομπότ 1

// Tell the other robot when the screen is being pressed
  // Create the link
  message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()){
    wait(0.1, seconds);
  }

  Brain.Screen.print("Robot 1 - Manager");

  // Continuously send if the screen is being pressed
  while (true){
    if (Brain.Screen.pressing()){
      link.send("pressed");
    } else {
      link.send("released");
    }
    wait(0.05, seconds);
  }

Κωδικός για το Ρομπότ 2

// Display if the other robot's screen is being pressed

  // Create the link
  message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);
  
  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()){
   wait(0.1, seconds);
  }

  // Continuously check if Robot 1 has sent "pressed"
  while (true){
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();
    char msg[32] = {0};                         // buffer for incoming message
    int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
    if (n > 0 && strcmp(msg, "pressed") == 0) {
      Brain.Screen.newLine();
      Brain.Screen.print("Manager is being pressed!");
    }
    wait(0.05, seconds);
  }

send#

Στέλνει ένα μήνυμα μέσω της σύνδεσης σύνδεσης.

Available Functions

1 — Στέλνει μια συμβολοσειρά μηνύματος.

int32_t send( 
  const char *message );

2 — Sends a message string with a double.

int32_t send( 
  const char *message, 
  double      value );

3 — Sends a message string with an int32_t and a double.

int32_t send(
  const char *message, 
  int32_t     index, 
  double      value );

Parameters

Παράμετρος

Τύπος

Περιγραφή

message

const char*

Το μήνυμα που θα σταλεί στον άλλο συνδεδεμένο εγκέφαλο V5.

index

int32_t

Ένας ακέραιος αριθμός για αποστολή στον άλλο συνδεδεμένο εγκέφαλο V5.

value

double

Ένα διπλό για αποστολή στον άλλο συνδεδεμένο εγκέφαλο V5. Τα διπλάσια μορφοποιούνται σε 4 δεκαδικά ψηφία. Εάν παρέχονται λιγότερα δεκαδικά ψηφία, προστίθενται μηδενικά στο τέλος μέχρι να εμφανιστούν 4.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει καμία τιμή.

Notes

If only message is sent, the other linked V5 Brain receives that exact message.

If value (and index if provided) are included, the receiving Brain gets a single encoded message that combines all fields in this order: .message_index_value

Examples

Using link.send(“string”, 1, 2.55) is received as .string_1_2.5500.

Κωδικός για το Ρομπότ 1

// Tell the other robot when the screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}

Brain.Screen.print("Robot 1 - Manager");

// Continuously send if the screen is being pressed
while (true){
  if (Brain.Screen.pressing()){
    link.send("pressed");
  } else {
    link.send("released");
  }
  wait(0.05, seconds);
}

Κωδικός για το Ρομπότ 2

// Display if the other robot's screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}
// Continuously check if Robot 1 has sent "pressed"
while (true){
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  char msg[32] = {0};  // buffer for incoming message
  int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
  if (n > 0 && strcmp(msg, "pressed") == 0) {
    Brain.Screen.newLine();
    Brain.Screen.print("Manager is being pressed!");
  }
  wait(0.05, seconds);
}

receive#

Λαμβάνει ένα μήνυμα από τη σύνδεση σύνδεσης.

Available Functions
int32_t receive(
  char     *buffer,
  int32_t   length, 
  int32_t   timeoutMs = 500 );

Parameters

Παράμετρος

Τύπος

Περιγραφή

buffer

char*

Η προσωρινή μνήμη για την αποθήκευση του ληφθέντος μηνύματος.

length

int32_t

Το μήκος του buffer.

timeoutMs

int32_t

How long in milliseconds receive will wait for a new message only if the queue is empty. Default is 300,000 (300 seconds).

Return Values

Αυτή η συνάρτηση επιστρέφει τον αριθμό των byte που λαμβάνονται.

Notes
  • receive returns the next queued message from the other linked V5 Brain. Messages are read in FIFO order (oldest unread first). If the queue is empty when receive is called, it waits up to the specified timeout for a new message. If no message arrives in that window, receive returns 0, and any message sent afterward remains in the queue to be read the next time receive is used.

  • If the other linked V5 Brain sent only a string, receive returns that exact string.

  • If the other linked V5 Brain sent an integer and/or float, receive returns a single encoded string that combines all fields in this order: .string_integer_float

    • For example, if the other linked V5 Brain uses link.send(“string”, 1, 2.55), then using link.receive() returns an encoded string such as .string_1_2.5500. You can split this encoded string (see the examples below) to extract the message name, integer, and float values.

    • If you’d rather avoid manual splitting/parsing, use received to register a handler for a specific message name; the handler receives the sent values as arguments.

Examples

Using link.send(“string”, 1, 2.55) is received as .string_1_2.5500.

Κωδικός για το Ρομπότ 1

// Tell the other robot when the screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}

Brain.Screen.print("Robot 1 - Manager");

// Continuously send if the screen is being pressed
while (true){
  if (Brain.Screen.pressing()){
    link.send("pressed");
  } else {
    link.send("released");
  }
  wait(0.05, seconds);
}

Κωδικός για το Ρομπότ 2

// Display if the other robot's screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}
// Continuously check if Robot 1 has sent "pressed"
while (true){
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  char msg[32] = {0};   // buffer for incoming message
  int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
  if (n > 0 && strcmp(msg, "pressed") == 0) {
    Brain.Screen.newLine();
    Brain.Screen.print("Manager is being pressed!");
  }
  wait(0.05, seconds);
}

received#

Καταγράφει μια συνάρτηση που θα καλείται κάθε φορά που ο εγκέφαλος V5 λαμβάνει ένα απεσταλμένο μήνυμα.

Available Functions

1 Καταγράφει μια επανάκληση για όλα τα ληφθέντα μηνύματα (μήνυμα + τιμή).

void received(
    void (* callback)(const char *, const char *, double)
);

2 Καταγράφει μια επανάκληση για όλα τα ληφθέντα μηνύματα (μήνυμα + δείκτης + τιμή).

void received(
    void (* callback)(const char *, const char *, int32_t, double)
);

3 Καταγράφει μια επανάκληση για ένα συγκεκριμένο μήνυμα (μήνυμα + τιμή).

void received(
    const char *message,
    void      (* callback)(const char *, const char *, double)
);

4 Καταγράφει μια επανάκληση για ένα συγκεκριμένο μήνυμα (μήνυμα + δείκτης + τιμή).

void received(
    const char *message,
    void      (* callback)(const char *, const char *, int32_t, double)
);

Parameters

Παράμετρος

Τύπος

Περιγραφή

message

const char *

Το όνομα του μηνύματος που θα ανακτηθεί. Εάν παραλειφθεί, η επανάκληση εκτελείται για όλα τα ληφθέντα μηνύματα.

callback

void (*)(const char *, const char , double) or void ()(const char *, const char *, int32_t, double)

Μια συνάρτηση που εκτελείται όταν λαμβάνεται ένα μήνυμα.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει καμία τιμή.

Callback Signature

1 Λαμβάνει το όνομα του αποστολέα, το όνομα του μηνύματος και την τιμή.

void callback(const char *, const char *, double)

2 Λαμβάνει το όνομα του αποστολέα, το όνομα του μηνύματος, τον δείκτη και την τιμή.

void callback(const char *, const char *, int32_t, double)

Τύπος

Περιγραφή

1st const char *

Το όνομα του συνδέσμου του αποστολέα.

2nd const char *

Το όνομα του μηνύματος που ελήφθη.

int32_t

Το ευρετήριο που σχετίζεται με το μήνυμα.

double

Η τιμή που σχετίζεται με το μήνυμα.

Examples

Κωδικός για το Ρομπότ 1

// Create the link.
message_link link(PORT1, "LeftRightLink", linkType::manager, true);

// Send whether screen is pressed on left or right.
void screen_pressed() {
  if (Brain.Screen.xPosition() < 240) {
    link.send("left");
  } else {
    link.send("right");
  }
}

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();
  
  // Do not run code UNTIL the Brains are linked.
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }

  Brain.Screen.print("Robot 1 - Manager");

  Brain.Screen.pressed(screen_pressed);

  while (true) {
    wait(10, msec);
  }
}

Κωδικός για το Ρομπότ 2

// Create variable to track where screen is pressed.
int lastPress = 0;

// Update the variable whenever a new message is received.
void message_received(const char* message, const char* linkname, double timestamp) {
  if (strcmp(message, "left") == 0)  lastPress = 1;
  if (strcmp(message, "right") == 0) lastPress = 2;
}

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Create the link.
  message_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

  // Do not run code UNTIL the Brains are linked.
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }

  link.received(message_received);

  // Display if Robot 1's screen was pressed on the left or right
  while (true) {
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();

    if (lastPress == 1) {
      Brain.Screen.print("Manager pressed LEFT");
    } else if (lastPress == 2) {
      Brain.Screen.print("Manager pressed RIGHT");
    } else {
      Brain.Screen.print("Waiting...");
    }

    wait(0.1, seconds);
  }
}

προηγούμενο

VEXlink

επόμενο

Σειριακός σύνδεσμος

On this page
  • Εισαγωγή
  • Κατασκευαστές κλάσεων
  • Καταστροφέας κλάσης
  • Παράμετροι
  • Παράδειγμα
  • Συναρτήσεις Μελών
    • isLinked
    • send
    • receive
    • received
Innovation First, International

Τα VEX και VEX Robotics είναι εμπορικά σήματα ή σήματα υπηρεσιών της Innovation First, Inc. Πνευματικά δικαιώματα ©2026. Με επιφύλαξη παντός δικαιώματος. Η VEX Robotics, Inc. είναι θυγατρική της Innovation First International, Inc. Όλα τα άλλα ονόματα προϊόντων/σήματα τρίτων αποτελούν ιδιοκτησία των αντίστοιχων κατόχων τους. Διπλώματα ευρεσιτεχνίας ή/και Διπλώματα ευρεσιτεχνίας σε εκκρεμότητα - innovationfirst.com/patents
Πολιτική απορρήτου ιστότοπου / Όροι χρήσης ιστότοπου / Πολιτική για τα cookie / Πολιτική απορρήτου λογισμικού

Επισκεφθείτε τη σελίδα VEX Robotics στο Facebook Επισκεφθείτε τη σελίδα VEX Robotics στο Twitter Επισκεφθείτε τη σελίδα VEX Robotics στο Instagram Επισκεφθείτε τη σελίδα VEX Robotics στο YouTube
Φόρμα σχολίων VEX API

Εκτιμούμε τα σχόλιά σας! Χρησιμοποιήστε αυτήν τη φόρμα για να μοιραστείτε προτάσεις, σχόλια ή να αναφέρετε σφάλματα με το VEX API. Η συμβολή σας μας βοηθά να βελτιώσουμε την τεκμηρίωση του VEX API.

Εάν αντιμετωπίζετε τεχνικά προβλήματα ή χρειάζεστε υποστήριξη πελατών, επισκεφθείτε τη διεύθυνση support.vex.com.

  • Send Happy Feedback
  • Send Sad Feedback

Σημείωση: η τρέχουσα διεύθυνση URL θα κοινοποιηθεί στο μήνυμά σας

Συμπεριλαμβάνοντας τη διεύθυνση ηλεκτρονικού ταχυδρομείου σας, συμφωνείτε ότι η VEX μπορεί να σας στέλνει ηλεκτρονικά μηνύματα εάν έχουμε ερωτήσεις σχετικά με τα σχόλιά σας.
Πολιτική Απορρήτου >
Παρακαλώ δώστε τα σχόλιά σας. Τα σχόλια υποβλήθηκαν με επιτυχία!
Choose Which VEX IQ Generation to View

VEX IQ (1st gen)

VEX IQ (2nd gen)