• 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

シリアルリンク#

  • 導入

  • クラスコンストラクタ

  • クラスデストラクタ

  • パラメータ

  • 注記

  • 例

  • メンバーの機能

    • 関連付けられています

    • 送信

    • 受け取る

    • 受け取った

導入#

serial_link クラスを使用すると、ロボット間で生のバイト列を送信できます。これは、送信側と受信側の両方のロボットがデータストリームの内容を理解する、ロボット間通信向けに設計されています。

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

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

クラスコンストラクタ#

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

クラスデストラクタ#

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

~serial_link();

パラメータ#

パラメータ

タイプ

説明

index

int32_t

メッセージリンクが接続されているスマートポートは、 PORTxと表記され、 x はポート番号です (例: PORT1)。

name

const char*

このリンクの名前。この固有の文字列は、Vexosによってハッシュ化された際に一意のIDが生成されるよう、十分な長さにすることをお勧めします。「vexlink」のような一般的な名前は、他のチームによって使用される可能性があるため、好ましくありません。

type

linkType

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

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

isWired

bool

serial_link オブジェクトが有線かどうか (デフォルトは false):

  • true — serial_link オブジェクトは有線です
  • false — serial_link オブジェクトは無線です

注記#

  • VEXlinkは無線および有線通信の両方をサポートしており、有線接続の場合は電力経路の問題を回避するために改良されたスマートケーブルの使用を推奨します。

  • 無線通信を行うには、各ロボットにスマートポートに接続されたV5ロボット無線機が必要です。

  • VEXlink無線機は、EXPコントローラーのVEXnet無線機と併用できます。競合を避けるため、VEXnet無線機は番号が最も大きいスマートポートに接続する必要があります。

  • VEXlinkを作成するには、両方のEXP BrainをV5ロボット無線機に接続する必要があります。

例#

ロボット1のコード

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

ロボット2のコード

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

メンバーの機能#

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

  • isLinked — EXP Brain がペアになってこのリンクで通信しているかどうかを確認します。

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

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

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

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

ロボット1のコード

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

ロボット2のコード

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

isLinked#

シリアルリンク上のEXP Brainが互いにペアになっているかどうかを返します。

Available Functions
bool isLinked();

Parameters

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

Return Values

EXP Brainsがリンクされているかどうかを示すブール値を返します。

  • true — The two EXP Brains are paired and communicating on this link.
  • false — The two EXP Brains are not paired on this link.
Notes
  • プロジェクトを開始する前に、EXP Brainが正しくリンクされていることを必ず確認してから、さらにコードを実行することをお勧めします。

Examples

ロボット1のコード

// Create the link
  serial_link 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");
  Brain.Screen.newLine();
  Brain.Screen.print("Sending message...");

  // Message to send
  const char* message = "Hello Robot 2";

  // Send the message
  link.send((uint8_t*)message, strlen(message));

ロボット2のコード

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

  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }
  
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Buffer to store incoming bytes
  uint8_t buffer[32] = {0};

  int32_t n = link.receive(buffer, sizeof(buffer) - 1);

  // Null-terminate
  if (n > 0) {
    buffer[n] = 0;

    // Display the message that was sent
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();
    Brain.Screen.print((char*)buffer);
  }
  else {
    Brain.Screen.newLine();
    Brain.Screen.print("No message received");
  }

send#

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

Available Functions

1 — バイトバッファを使用してメッセージを送信します。

int32_t send( 
  uint8_t *buffer, 
  int32_t  length );

2 — 文字バッファを使用してメッセージを送信します。

int32_t send( 
  const char *buffer, 
  int32_t     length );

Parameters

パラメータ

タイプ

説明

buffer

uint8_t* or const char*

他のリンクされたEXP Brainに送信するバッファ。

length

int32_t

送信するバッファの長さ。

Return Values

送信されたバイト数を表す int32_t を返します。

Examples

ロボット1のコード

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

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

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

  // Track last sent state
  uint8_t lastState = 255;  // impossible initial value

 // Tell Robot 2 when the screen is being pressed
  while (true) {
    uint8_t state = Brain.Screen.pressing() ? 1 : 0;

    // Only send if state changed
    if (state != lastState) {
      link.send(&state, 1);
      lastState = state;
    }

    wait(0.02, seconds);
  }

ロボット2のコード

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

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

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Track the last state
  uint8_t lastShown = 255;

  while (true) {
    // Variable stores 1 - pressed, 0 - not pressed 
    uint8_t state = 0;
    int32_t n = link.receive(&state, 1, 200);

    // Only update screen if state changes
    if (n == 1 && state != lastShown) {
      Brain.Screen.clearScreen();
      Brain.Screen.setCursor(1, 1);
      Brain.Screen.print("Robot 2 - Worker");
      Brain.Screen.newLine();

      // Display text if Robot 1's screen is being pressed
      if (state == 1) {
        Brain.Screen.print("Manager IS being pressed!");
      } else {
        Brain.Screen.print("Manager is NOT being pressed");
      }

      lastShown = state;
    }
    wait(0.02, seconds);
  }

receive#

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

Available Functions

1 — オプションのタイムアウト付きでメッセージを文字バッファに受信します。

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

Parameters

パラメータ

タイプ

説明

buffer

char*

受信したメッセージを格納するためのバッファ。

length

int32_t

バッファの長さ。

timeoutMs

int32_t

receive キューが空の場合にのみ新しいメッセージを待機します (デフォルトは 500 ms)。

Return Values

受信したバイト数を表す int32_t を返します。

Notes
  • receive は、リンクされた別の EXP Brain から次のキューイングされたメッセージを返します。

  • メッセージはFIFO順(最も古い未読メッセージから順に)で読み込まれます。

  • receive が呼び出されたときにキューが空の場合、指定された timeoutMs まで新しいメッセージを待ちます。

  • そのウィンドウ内にメッセージが到着しない場合、 receive は 0を返し、その後送信されたメッセージはキューに残り、 receive が次に使用されるときに読み取られます。

Examples

ロボット1のコード

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

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

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

  // Track last sent state
  uint8_t lastState = 255;  // impossible initial value

 // Tell Robot 2 when the screen is being pressed
  while (true) {
    uint8_t state = Brain.Screen.pressing() ? 1 : 0;

    // Only send if state changed
    if (state != lastState) {
      link.send(&state, 1);
      lastState = state;
    }

    wait(0.02, seconds);
  }

ロボット2のコード

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

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

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Track the last state
  uint8_t lastShown = 255;

  while (true) {
    // Variable stores 1 - pressed, 0 - not pressed 
    uint8_t state = 0;
    int32_t n = link.receive(&state, 1, 200);

    // Only update screen if state changes
    if (n == 1 && state != lastShown) {
      Brain.Screen.clearScreen();
      Brain.Screen.setCursor(1, 1);
      Brain.Screen.print("Robot 2 - Worker");
      Brain.Screen.newLine();

      // Display text if Robot 1's screen is being pressed
      if (state == 1) {
        Brain.Screen.print("Manager IS being pressed!");
      } else {
        Brain.Screen.print("Manager is NOT being pressed");
      }

      lastShown = state;
    }
    wait(0.02, seconds);
  }

received#

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

Available Functions

1 — 受信したメッセージごとにコールバック関数を登録します。

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

2 — 追加の int32_t フィールドを含む受信メッセージごとに呼び出されるコールバックを登録します。

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 — メッセージペイロードに追加の int32_t フィールドが含まれる、名前が message と一致する受信メッセージに対してのみ呼び出されるコールバックを登録します。

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

Parameters

パラメータ

タイプ

説明

message

const char*

照合するメッセージ名(文字列)。受信したメッセージ名がこの値と一致すると、コールバック関数 callback が呼び出されます。

callback

function

EXP Brain がメッセージ messageに一致するメッセージを受信したときに実行される、事前に定義された関数。

Return Values

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

Notes
  • received のコールバックが4つの引数で呼び出されました。

Callback Signature

callback(message, linkname, index, value)

口論

説明

message

受信したメッセージ名(例: “add”)。

linkname

メッセージを受信したリンク名。

index

メッセージとともに送信される整数値(指定されている場合)。

value

メッセージとともに送信される浮動小数点値(指定されている場合)。

Examples

ロボット1のコード

// Send left or right when pressed
void screen_pressed() {
  if (Brain.Screen.xPosition() < 240) {
    link.send((uint8_t*)"left", 4);
  } else {
    link.send((uint8_t*)"right", 5);
  }
}

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

// Create the link
serial_link 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");


  Brain.Screen.pressed(screen_pressed);
}

ロボット2のコード

// Called when message received
void received_callback(uint8_t *buffer, int32_t length) {
  char msg[32];

  // Copy safely and null terminate
  int n = (length < 31) ? length : 31;
  memcpy(msg, buffer, n);
  msg[n] = '\0';

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();

  // Display if Robot 1's screen is pressed on left or right
  if (strcmp(msg, "left") == 0) {
    Brain.Screen.print("Manager pressed LEFT");
  }
  else if (strcmp(msg, "right") == 0) {
    Brain.Screen.print("Manager pressed RIGHT");
  }
}

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

// Create the link
serial_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(received_callback);

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");
}

前へ

メッセージリンク

次へ

CTEワークセル

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)