• 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

シリアルリンク#

  • 導入

  • リンクを作成する

  • 利用可能な方法

    • 関連付けられている

    • 送信

    • 受け取る

    • 受け取った

導入#

SerialLinkを使用すると、2つのEXP BrainがVEX Linkを介して生のシリアルデータを送受信することで通信できます。SerialLinkはラベル付きメッセージではなく、バッファ(文字列またはバイト配列)を送信します。そのため、センサーデータのストリーミング、カスタムパケットフォーマットの送信、バイトベースの独自のプロトコルの構築など、高度なロボット間通信に役立ちます。

send を使用するたびに、リンクされた EXP Brain の受信バッファにデータが追加されます。データは到着した順序 (先入れ先出し) で読み取られます。他の EXP Brain が receive を使用する前に複数のバッファが送信された場合、それらはキューに保持され、送信された順序で 1 つずつ返されます。データはキューに格納される可能性があるため、ループごとに大きなバッファを繰り返し送信するとバックログが発生する可能性があります。時間制約のあるリンクでは、必要なデータのみを送信してください。

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

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

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

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

  • send – ペアになった Brain に短いメッセージ (オプションで int/float データを含む) を送信します。

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

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

リンクを作成する#

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

SerialLink(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 = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)

ロボット2のコード

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

利用可能な方法#

SerialLinkの設定が完了し、Brainがリンクされたら、以下の方法を使用して生のシリアルデータを送受信し、応答することができます。

is_linked#

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

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

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

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

Usage:
link.is_linked()

パラメータ

説明

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

ロボット1のコード

# Send a message to the other robot

# Create the link
link = SerialLink(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")

link.send("HELLO")

ロボット2のコード

# Display the message that Robot 1 sends

# Create the link
link = SerialLink(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()

def received_message(bytearray, length):
    # Slice the bytearray to the valid data
    data = bytearray[:length]  
    # Decode and strip the message before displaying it
    text = data.decode().strip()
    brain.screen.print("Got: ", text)

# Call received_message whenever a message is received
link.received(received_message)

send#

send 生のシリアルバイトをリンクされたもう一方の EXP Brain に送信します。

When reading that data with receive, receive will only return once it has collected the number of bytes specified by its length parameter. Because of that, if your code always calls receive with a fixed length, you should ensure each message sent with send is exactly that many bytes (often by padding) so the receiver doesn’t block waiting for additional bytes.

正確なバイト数に依存したくない場合は、received を使用してください。これにより、特定の長さを必要とせずに、利用可能なバイトを処理できます。

Usage:
send(buffer)

パラメータ

説明

buffer

他のリンクされたEXP Brainに送信するデータ。これは、 string または bytearrayいずれかです。

ロボット1のコード

# Send a message to the other robot

# Create the link
link = SerialLink(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")

link.send("HELLO")

ロボット2のコード

# Display the message that Robot 1 sends

# Create the link
link = SerialLink(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()

def received_message(bytearray, length):
    # Slice the bytearray to the valid data
    data = bytearray[:length]  
    # Decode and strip the message before displaying it
    text = data.decode().strip()
    brain.screen.print("Got: ", text)

# Call received_message whenever a message is received
link.received(received_message)

receive#

receive リンクされたもう一方の EXP Brain からシリアルデータを FIFO 順 (最も古い未読データが最初に) で返します。

receive は正確なバイト数を待つため、固定長メッセージングでは、各メッセージが期待されるサイズに達するように、 receive を使用する際にパディングが必要になることがよくあります。送信者が send バイト未満しか送信しない場合、 length は残りのバイトを待ち続け、何も返しません。

If the queue is empty and you provide a timeout, receive waits up to that many milliseconds for new data. If nothing arrives in that window, it returns None. Any data sent afterward remains queued to be read later.

Usage:
receive(length, timeout)

パラメータ

説明

length

The number of bytes to receive. receive waits until this many bytes have arrived, then returns them as a bytearray. If length is 0, receive returns None immediately. If you request more bytes than the sender transmits, receive will keep waiting. If the sender transmits more than this, the returned buffer is limited to length bytes.

timeout

オプション。待機時間(ミリ秒 receive キューが空の場合にのみ新しいメッセージを待機します。デフォルト値は300000(300秒)です。

ロボット1のコード

# Send a math problem for the other Brain to solve

# Create the link
link = SerialLink(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.
"""
packet = "add,7,2.5"

# Pad with spaces until it's exactly 16 bytes
while len(packet) < 16:
    packet = packet + " "

link.send(packet)

ロボット2のコード

# Solve the math problem that the other Brain sends

# Create the link
link = SerialLink(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()

# Receive exactly 16 bytes
buffer = link.receive(16)

# Remove the added " " padding
text = buffer.decode().strip()

# Separate the operator and numbers
parts = text.split(",")

operator = parts[0]
a = float(parts[1])
b = float(parts[2])

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

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

received#

received EXP Brain がシリアルデータを受信するたびに呼び出される関数を登録します。

Usage:
link.received(callback)

パラメータ

説明

callback

EXP Brainがシリアルデータを受信したときに実行される、事前に定義された関数。

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

コールバックシグネチャ:
callback(buffer, length)

口論

説明

buffer

A bytearray containing the received serial data. The bytearray may be larger than the received message.

length

The number of valid bytes received in buffer for this callback. Use buffer[:length] to access the received data.

ロボット1のコード

# Send a message to the other robot

# Create the link
link = SerialLink(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")

link.send("HELLO")

ロボット2のコード

# Display the message that Robot 1 sends

# Create the link
link = SerialLink(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()

def received_message(bytearray, length):
    # Slice the bytearray to the valid data
    data = bytearray[:length]  
    # Decode and strip the message before displaying it
    text = data.decode().strip()
    brain.screen.print("Got: ", text)

# Call received_message whenever a message is received
link.received(received_message)

前へ

メッセージリンク

次へ

コンソール

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)