• 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
    • パワートレイン
    • モーション
    • 音
    • ビジョン
    • 画面
    • コントローラ
    • センシング
    • 慣性
    • 3線式デバイス
    • 空気圧
    • 脳
    • SDカード
    • 6軸アーム
    • 信号塔
    • VEXlink
      • メッセージリンク
      • シリアルリンク
    • コンソール
    • 論理
    • MicroPythonライブラリ
  • C++
  • 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

メッセージリンク#

  • 導入

  • リンクを作成する

  • 利用可能な方法

    • 関連付けられている

    • 送信

    • 受け取る

    • 受け取った

導入#

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

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

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

This page uses link as the example MessageLink name. Replace it with your own configured name as needed.

利用可能なメソッドの一覧は以下のとおりです。

  • is_linked – この脳がペアの脳にアクティブに接続されているかどうかを返します。

  • send – ペアになったブレインにメッセージを送信します。

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

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

リンクを作成する#

両方のEXP BrainにMessageLinkを作成して、V5 Robot Radioを使用した無線接続、またはスマートケーブルを使用した有線接続のいずれかで、両者間の通信チャネルを確立し、ロボット同士がメッセージを送受信できるようにします。

MessageLink(smartport, name, linktype, wired)

パラメータ

説明

smartport

このリンクに使用されるスマートポートとは、V5 Robot Radioが接続されているポート(無線)またはスマートケーブルが差し込まれているポート(有線)のことです。0 Ports.PORTx ように表記され、xはポート番号です。

name

このリンク
付ける一意の名前を文字列として指定します。0 注: この名前は、他のチームのリンクと誤って一致しないように、一意のIDを作成するのに十分な長さにする必要があります。

linktype

このリンクペアで使用するブレインの役割。各ペアには、1 つのマネージャーと1 つのワーカーが含まれている必要があります。

  • VexlinkType.MANAGER – より多くのメッセージまたはより大きなメッセージを送信するロボットに使用します。マネージャーは送信帯域幅が広くなっています (~1040 バイト/秒)。
  • VexlinkType.WORKER – より少ないメッセージまたはより小さなメッセージを送信するロボットに使用します。ワーカーは送信帯域幅が狭くなっています (~520 バイト/秒)。

wired

オプション。このリンクが有線か無線か:

  • True – EXP Brainsはスマートケーブルで接続されています。
  • False (デフォルト) – EXP BrainsはV5ロボット無線を使用して無線で接続されます。

ロボット1のコード

"""
Create a wireless link in Port 1
name: VEXRoboticsLink123456789
linktype: Manager
"""
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

ロボット2のコード

"""
Create a wireless link in Port 1
name: VEXRoboticsLink123456789
linktype: Worker
"""
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

利用可能な方法#

MessageLinkの設定が完了し、Brainがリンクされると、以下の方法を使用してメッセージの送受信や返信を行うことができます。

is_linked#

is_linked メソッドは、MessageLink 上の EXP Brain が互いにペアになっているかどうかを返します。

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

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

注: プロジェクトの開始時にEXP Brainがリンクされていることを常に確認してから、さらにコードを実行することをお勧めします。

Usage:
link.is_linked()

パラメータ

説明

このメソッドにはパラメータがありません。

ロボット1のコード

# Tell the other robot when the screen is being pressed

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    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(50, MSEC)

ロボット2のコード

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

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

# Continuously check if Robot 1 has sent "pressed"
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Robot 2 - Worker")
    brain.screen.next_row()

    if link.receive() == "pressed":
        brain.screen.new_line()
        brain.screen.print("Manager is being pressed!")

    wait(50, MSEC)

send#

send 文字列、整数、浮動小数点数をもう一方の EXP Brain に送信します。

Usage:
send(string, integer, float)

パラメータ

説明

string

他のリンクされたEXP Brainに送信する文字列。

integer

オプション。リンク先のEXP Brainに送信する整数値。

float

オプション。リンク先のEXP Brainに送信する浮動小数点数。浮動小数点数は小数点以下4桁まででフォーマットされます。小数点以下の桁数が少ない場合は、4桁になるまで末尾にゼロが追加されます。

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

integer および/または float が含まれる場合、受信側の Brain は、すべてのフィールドを次の順序で組み合わせた単一のエンコードされた文字列を受け取ります: .string_integer_float

例: link.send(“string”, 1, 2.55) .string_1_2.5500として受信されます。

ロボット1のコード

# Tell the other robot when the screen is being pressed

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    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(50, MSEC)

ロボット2のコード

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

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

# Continuously check if Robot 1 has sent "pressed"
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Robot 2 - Worker")
    brain.screen.next_row()

    if link.receive() == "pressed":
        brain.screen.new_line()
        brain.screen.print("Manager is being pressed!")

    wait(50, MSEC)

ロボット1のコード

# Tell the other robot where the screen was pressed

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 1 - Manager")
brain.screen.next_row()
brain.screen.print("Tap to send circles")

# Send the coordinates whenever the screen is pressed
while True:
    if brain.screen.pressing():
        x = brain.screen.x_position()
        y = brain.screen.y_position()

        link.send("touch", x, y)

    wait(10, MSEC)

ロボット2のコード

# Draw a circle where Robot 1's screen was pressed

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 2 - Worker")

while True:
    # Get the full encoded string
    circle_coordinates = link.receive(200)

    if circle_coordinates:

        # Split the encoded string by _
        parts = circle_coordinates.split("_")

        if len(parts) == 3:
            # Convert the coordinates back into numbers
            x = float(parts[1])
            y = float(parts[2])

            brain.screen.set_fill_color(Color.WHITE)
            brain.screen.draw_circle(x, y, 20)

    wait(10, MSEC)

receive#

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 None, 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 を使用して特定のメッセージ名のハンドラを登録します。ハンドラは送信された値を引数として受け取ります。

Usage:
receive(timeout)

パラメータ

説明

timeout

オプション。キューが空の場合にのみ新しいメッセージを待機する時間(ミリ秒 receive 待機時間は300,000(300秒)です。

ロボット1のコード

# Tell the other robot when the screen is being pressed

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    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(50, MSEC)

ロボット2のコード

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

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

# Continuously check if Robot 1 has sent "pressed"
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Robot 2 - Worker")
    brain.screen.next_row()

    if link.receive() == "pressed":
        brain.screen.new_line()
        brain.screen.print("Manager is being pressed!")

    wait(50, MSEC)

ロボット1のコード

# Send a math problem for the other Brain to solve

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 1 - Manager")

"""
Change whether to "add" or "subtract",
then what numbers to use in the operation.
"""
link.send("add", 7, 2.5)

ロボット2のコード

# Solve the math problem that the other Brain sends

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 2 - Worker")
brain.screen.next_row()

math_problem = link.receive()

if math_problem:

    # Split the encoded string by _
    parts = math_problem.split("_")

    if len(parts) == 3:
        # Remove the . from the beginning of the string
        operator = "".join([c for c in parts[0] if c.isalpha()])

        # Separate out the numbers for the operation
        a = int(parts[1])
        b = float(parts[2])

        # Use what operator was sent
        if operator == "add":
            result = a + b
        elif operator == "subtract":
            result = a - b
        # If neither add or subtract is sent, do nothing
        else:
            pass

brain.screen.print("Result = ", result)

received#

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

Usage:
link.received(message, arg)

パラメータ

説明

message

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

callback

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

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

コールバック署名:
callback(message, linkname, index, value)

口論

説明

message

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

linkname

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

index

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

value

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

ロボット1のコード

# Send a math problem for the other Brain to solve

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

# Do not run code UNTIL the Brains are linked
while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 1 - Manager")

"""
Change whether to "add" or "subtract",
then what numbers to use in the operation.
"""
link.send("add", 7, 2.5)

ロボット2のコード

# Solve the math problem that the other Brain sends

# Create the link
link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)

while not link.is_linked():
    wait(0.1, SECONDS)

brain.screen.print("Robot 2 - Worker")
brain.screen.next_row()

# add if "add" is received
def add_cmd(message, linkname, a, b):
    result = a + b
    brain.screen.print("Result = ", result)

# subtract if ""subtract" is received
def subtract_cmd(message, linkname, a, b):
    result = a - b
    brain.screen.print("Result = ", result)

# Create event handlers for "add" and "subtract"
link.received("add", add_cmd)
link.received("subtract", subtract_cmd)

前へ

VEXlink

次へ

シリアルリンク

On this page
  • 導入
  • リンクを作成する
  • 利用可能な方法
    • is_linked
    • 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)