• 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 EXP
  • VEX EXP APIリファレンス
  • VEXlink
  • メッセージリンク
日本語
  • English
  • العربية
  • বাংলা
  • Česky
  • Deutsch
  • Ελληνικά
  • Español
  • Español Latinoamericano
  • Suomi
  • Français
  • Gaeilge
  • हिंदी
  • Magyar
  • Bahasa Indonesia
  • 한국어
  • Lietuvių
  • Latviešu
  • മലയാളം
  • Nederlands
  • Polski
  • Português
  • Русский
  • Svenska
  • ไทย
  • Türkçe
  • Українська
  • Tiếng Việt
  • 简体中文
  • 繁體中文
  • VEXcode Robotics Logo

セクションナビゲーション

  • ブロック
  • Python
  • C++
    • パワートレイン
    • モーターとモーターコントローラー
    • 3線式デバイス
    • 脳
    • コンソール
    • コントローラ
    • 論理
    • スマートポートデバイス
    • VEXlink
      • メッセージリンク
      • シリアルリンク
    • CTEワークセル
  • 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

メッセージリンク#

  • 導入

  • クラスコンストラクタ

  • クラスデストラクタ

  • パラメータ

  • 例

  • メンバーの機能

    • 関連付けられています

    • 送信

    • 受け取る

    • 受け取った

導入#

message_link クラスを使用すると、2 つの EXP Brain が短い文字列メッセージとオプションの小さなデータを送受信することで通信できます。これは、ルーチンの開始、センサー結果の共有、別のロボットの動作のトリガーなど、ロボット間の連携を目的として設計されています。

send を使用するたびに、リンクされた EXP Brain のキューにメッセージが追加され、キューは先入れ先出し (FIFO) で読み取られます。他の EXP Brain が receive を使用する前に複数のメッセージが送信された場合、それらは保存され、送信された順序で 1 つずつ返されます。メッセージはキューに格納できるため、ループごとに同じステータスを繰り返し送信するとバックログが発生する可能性があります。時間制約のあるロジックの場合は、値が変更されたときのみ送信してください。

重要: 両方のロボットは、同時に message_link を使用するプロジェクトを実行している必要があります。そうでない場合、メッセージの送受信は行われません。

クラスコンストラクタ#

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

クラスデストラクタ#

message_link オブジェクトを破棄し、関連するリソースを解放します。

virtual ~message_link();

パラメータ#

パラメータ

タイプ

説明

index

int32_t

V5無線機またはスマートケーブルが接続されているスマートポートは、 PORTxと表記され、 x はポート番号です (例: PORT1)。

name

char

メッセージリンクの名前。

type

linkType

リンクの種類は、 linkType::manager または linkType::workerのいずれかです。この情報は、無線を正しく構成するために使用され、送受信に利用可能な帯域幅も決定します。マネージャーロボットは、ワーカーロボット (520 バイト/秒) に情報を送信するために、2 倍の帯域幅 (1040 バイト/秒) を持っています。

  • linkType::manager - message_link オブジェクトはマネージャーです。
  • linkType::worker - message_link オブジェクトはワーカーです。

isWired

bool

message_link オブジェクトが有線接続かどうか。

  • true - message_link オブジェクトは有線接続です。
  • false - message_link オブジェクトは無線接続です。

例#

ロボット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

メンバーの機能#

message_link クラスには、以下のメンバ関数が含まれています。

  • isLinked — この Brain がペアになっている Brain にアクティブに接続されているかどうかを返します。

  • send — ペアになっているブレインにメッセージを送信します。

  • receive — 次の受信メッセージを待機し、返します。

  • received — 新しいメッセージが受信されるたびに呼び出される関数を登録します。

message_link メンバー関数を呼び出す前に、以下に示すように、 message_link インスタンスを作成する必要があります。

ロボット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 メソッドは、MessageLink 上の EXP Brain が互いにペアになっているかどうかを返します。

Available Functions
bool isLinked();

Parameters

この関数には引数がありません。

Return Values

この関数はブール値を返します。

  • true – 2 つの EXP Brain はペアになっており、このリンクで通信しています。

  • false – このリンクでは、2 つの EXP Brain はペアになっていません。

Notes

プロジェクトを開始する前に、EXP Brainが正しくリンクされていることを必ず確認してから、さらにコードを実行することをお勧めします。

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 — doubleを重複させたメッセージ文字列を送信します。

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

3 — int32_t と doubleを含むメッセージ文字列を送信します。

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

Parameters

パラメータ

タイプ

説明

message

const char*

他のリンクされたEXP Brainに送信するメッセージ。

index

int32_t

他のリンクされたEXP Brainに送信する整数値。

value

double

他のリンクされたEXP Brainに送信するdouble型の値。double型は小数点以下4桁まで表示されます。小数点以下の桁数が少ない場合は、4桁になるまで末尾にゼロが追加されます。

Return Values

この関数は値を返しません。

Notes

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

value (および指定されている場合は index ) が含まれる場合、受信側の Brain は、すべてのフィールドを次の順序で組み合わせた単一のエンコードされたメッセージを受け取ります: .message_index_value

Examples

link.send(“string”, 1, 2.55) は .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

バッファの長さ。

timeoutMs

int32_t

キューが空の場合にのみ新しいメッセージを待機する時間(ミリ秒 receive デフォルトは 300,000 (300 秒) です。

Return Values

この関数は受信したバイト数を返します。

Notes
  • receive returns the next queued message from the other linked EXP 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.

  • もしリンクされた別のEXP Brainが文字列 string receive はその文字列を正確に返します。

  • 他のリンクされた EXP Brain が整数および/または浮動小数点数を送信した場合、 receive を受信し、すべてのフィールドを次の順序で組み合わせた単一のエンコードされた文字列を返します: .string_integer_float

    • 例えば、リンクされた別の EXP Brain が link.send(“string”, 1, 2.55)を使用している場合、 link.receive() を使用すると、 .string_1_2.5500のようなエンコードされた文字列が返されます。このエンコードされた文字列を分割して (以下の例を参照)、メッセージ名、整数値、および浮動小数点値を抽出できます。

    • 手動での分割/解析を避けたい場合は、received を使用して特定のメッセージ名のハンドラを登録します。ハンドラは送信された値を引数として受け取ります。

Examples

link.send(“string”, 1, 2.55) は .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#

EXP Brainが送信メッセージを受信するたびに呼び出される関数を登録します。

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

関数ポインタ

メッセージを受信した際に実行される関数。

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のコード

// 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();
  
// Create the link
  message_link link(PORT1, "LeftRightLink", 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");

  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.の商標またはサービスマークです Copyright ©2026。無断複写・転載を禁じます。VEX Robotics, Inc.は、Innovation First International, Inc.の子会社です。その他の製品名/マークは、それぞれの所有者の財産です。特許および/または特許出願中 - innovationfirst.com/patents
サイトプライバシーポリシー / サイト利用規約 / クッキーポリシー / ソフトウェアプライバシーポリシー

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)