• 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
Langsung ke konten utama
Ctrl+K

< Back to Platform Select

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

Navigasi Bagian

  • Blok
  • Python
    • Sistem penggerak
    • Gerakan
    • Penglihatan
    • Layar
    • Pengontrol
    • Penginderaan
    • Inersia
    • Perangkat 3-Kabel
    • Pneumatik
    • Otak
    • Suara
    • Kartu SD
    • VEXlink
      • Tautan Pesan
      • Tautan Serial
    • Menghibur
    • Logika
    • Lengan 6-Sumbu
    • Magnet
    • Kompetisi
    • Pustaka MicroPython
  • C++
  • Tutorial VEXcode

Navigasi Platform

  • 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

Tautan Pesan#

  • Perkenalan

  • Buat Tautan

  • Metode yang Tersedia

    • terhubung

    • mengirim

    • menerima

    • diterima

Perkenalan#

MessageLink memungkinkan dua V5 Brain berkomunikasi dengan mengirimkan pesan string pendek dengan data kecil opsional. Fitur ini dirancang untuk koordinasi antar robot — seperti memulai rutinitas, berbagi hasil sensor, atau memicu perilaku pada robot lain.

Setiap penggunaan send menambahkan pesan ke antrian V5 Brain yang terhubung, dan antrian dibaca masuk pertama keluar pertama (FIFO). Jika beberapa pesan dikirim sebelum V5 Brain lainnya menggunakan receive, pesan-pesan tersebut akan disimpan dan dikembalikan satu per satu sesuai urutan pengirimannya. Karena pesan dapat mengantri, mengirim status yang sama berulang kali setiap putaran dapat menyebabkan penumpukan; untuk logika yang sensitif terhadap waktu, kirim hanya ketika nilai berubah.

Penting: Kedua robot harus menjalankan proyek yang menggunakan MessageLink secara bersamaan, jika tidak, tidak ada pesan yang akan dikirim/diterima.

Halaman ini menggunakan link sebagai contoh MessageLink name. Ganti dengan nama yang Anda konfigurasi sendiri sesuai kebutuhan.

Berikut adalah daftar metode yang tersedia:

  • is_linked – Mengembalikan apakah Otak ini terhubung secara aktif ke Otak pasangannya.

  • send – Mengirim pesan ke Otak yang berpasangan.

  • receive – Menunggu dan mengembalikan pesan masuk berikutnya.

  • received – Mendaftarkan fungsi yang akan dipanggil setiap kali pesan baru diterima.

Buat Tautan#

Buat MessageLink pada kedua V5 Brain untuk membangun saluran komunikasi di antara keduanya—baik secara nirkabel dengan V5 Robot Radio atau melalui Smart Cable berkabel—sehingga robot dapat saling mengirim pesan.

MessageLink(smartport, name, linktype, wired)

Parameter

Keterangan

smartport

Port Pintar yang digunakan untuk tautan ini—port tempat Radio Robot V5 terhubung (nirkabel) atau tempat Kabel Pintar dicolokkan (berkabel). Ditulis sebagai Ports.PORTx di mana x adalah nomor port.

name

Nama unik yang akan diberikan pada tautan ini sebagai string.
Catatan: Nama ini harus cukup panjang untuk membuat ID unik sehingga tidak secara tidak sengaja cocok dengan tautan tim lain.

linktype

Peran yang akan digunakan Otak ini untuk pasangan tautan ini. Setiap pasangan harus mencakup satu Manajer dan satu Pekerja:

  • VexlinkType.MANAGER – Gunakan untuk robot yang akan mengirim lebih banyak atau pesan yang lebih besar. Manajer memiliki bandwidth keluar yang lebih tinggi (~1040 byte/detik).
  • VexlinkType.WORKER – Gunakan untuk robot yang akan mengirim lebih sedikit atau pesan yang lebih kecil. Pekerja memiliki bandwidth keluar yang lebih rendah (~520 byte/detik).

wired

Opsional. Apakah tautan ini menggunakan kabel atau nirkabel:

  • True – V5 Brains terhubung melalui Smart Cable.
  • False (default) – V5 Brains terhubung secara nirkabel menggunakan V5 Robot Radios.

Kode untuk Robot 1

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

Kode untuk Robot 2

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

Metode yang Tersedia#

Setelah MessageLink Anda diatur dan Brain terhubung, Anda dapat menggunakan metode di bawah ini untuk mengirim, menerima, dan membalas pesan.

is_linked#

Metode is_linked mengembalikan nilai boolean yang menunjukkan apakah V5 Brains pada MessageLink sudah berpasangan satu sama lain.

  • True – Kedua Otak V5 berpasangan dan berkomunikasi melalui tautan ini.

  • False – Kedua V5 Brain tidak dipasangkan pada tautan ini.

Catatan: Sebaiknya selalu periksa untuk memastikan V5 Brains sudah terhubung di awal proyek sebelum menjalankan kode lebih lanjut.

Usage:
link.is_linked()

Parameter

Keterangan

Metode ini tidak memiliki parameter.

Kode untuk Robot 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)

Kode untuk Robot 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 mengirimkan string dan/atau bilangan bulat dan/atau bilangan pecahan ke V5 Brain lain yang terhubung.

Usage:
send(string, integer, float)

Parameter

Keterangan

string

String yang akan dikirim ke V5 Brain lain yang terhubung.

integer

Opsional. Bilangan bulat untuk dikirim ke V5 Brain lain yang terhubung.

float

Opsional. Bilangan floating point untuk dikirim ke V5 Brain lain yang terhubung. Bilangan floating point diformat hingga 4 angka desimal; jika angka desimal yang diberikan kurang dari itu, angka nol di belakang koma akan ditambahkan hingga 4 angka desimal ditampilkan.

Jika hanya string string yang dikirim, V5 Brain lain yang terhubung akan menerima string yang persis sama.

Jika integer dan/atau float disertakan, Otak penerima akan mendapatkan satu string terenkripsi yang menggabungkan semua bidang dalam urutan ini: .string_integer_float

Contoh: Menggunakan link.send(“string”, 1, 2.55) diterima sebagai .string_1_2.5500.

Kode untuk Robot 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)

Kode untuk Robot 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)

Kode untuk Robot 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)

Kode untuk Robot 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 mengembalikan pesan antrean berikutnya dari V5 Brain lain yang terhubung. Pesan dibaca dalam urutan FIFO (pesan terlama yang belum dibaca terlebih dahulu). Jika antrean kosong saat receive dipanggil, ia menunggu hingga batas waktu yang ditentukan timeout untuk pesan baru. Jika tidak ada pesan yang tiba dalam jangka waktu tersebut, receive mengembalikan None, dan pesan apa pun yang dikirim setelahnya tetap berada dalam antrean untuk dibaca saat receive digunakan berikutnya.

Jika V5 Brain yang terhubung lainnya hanya mengirimkan string string, receive dan mengembalikan string yang persis sama.

Jika V5 Brain lain yang terhubung mengirimkan bilangan bulat dan/atau bilangan pecahan, receive mengembalikan satu string terenkripsi yang menggabungkan semua bidang dalam urutan ini: .string_integer_float

Misalnya, jika V5 Brain yang terhubung lainnya menggunakan link.send(“string”, 1, 2.55), maka menggunakan link.receive() akan mengembalikan string yang dikodekan seperti .string_1_2.5500. Anda dapat memisahkan string yang dikodekan ini (lihat contoh di bawah) untuk mengekstrak nama pesan, nilai integer, dan float.

Jika Anda lebih suka menghindari pemisahan/penguraian manual, gunakan received untuk mendaftarkan handler untuk nama pesan tertentu; handler menerima nilai yang dikirim sebagai argumen.

Usage:
receive(timeout)

Parameter

Keterangan

timeout

Opsional. Berapa lama dalam milidetik receive akan menunggu pesan baru hanya jika antrean kosong. Nilai default adalah 300.000 (300 detik).

Kode untuk Robot 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)

Kode untuk Robot 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)

Kode untuk Robot 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)

Kode untuk Robot 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 mendaftarkan sebuah fungsi yang akan dipanggil setiap kali V5 Brain menerima pesan yang dikirim.

Usage:
link.received(message, arg)

Parameter

Keterangan

message

The message name (string) to match. When a received message’s name matches this value, the callback function is called.

callback

Sebuah fungsi yang telah didefinisikan sebelumnya yang dijalankan ketika V5 Brain menerima pesan yang cocok dengan pesan message.

received panggilan balik yang dipanggil dengan empat argumen:

Tanda Tangan Panggilan Balik:
callback(message, linkname, index, value)

Argumen

Keterangan

message

Nama pesan yang diterima (misalnya, “add”).

linkname

Nama tautan tempat pesan diterima.

index

Nilai bilangan bulat yang dikirim bersama pesan (jika disediakan).

value

Nilai float yang dikirim bersama pesan (jika disediakan).

Kode untuk Robot 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)

Kode untuk Robot 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)

sebelum

VEXlink

berikut

Tautan Serial

On this page
  • Perkenalan
  • Buat Tautan
  • Metode yang Tersedia
    • is_linked
    • send
    • receive
    • received
Innovation First, International

VEX and VEX Robotics are trademarks or service marks of Innovation First, Inc. Copyright ©2026. All Rights Reserved. VEX Robotics, Inc. is a subsidiary of Innovation First International, Inc. All other product names / marks of others are the property of their respective owners. Patents and / or Patents Pending - innovationfirst.com/patents
Site Privacy Policy / Site Terms of Use / Cookie Policy / Software Privacy Policy

Kunjungi Halaman Facebook VEX Robotics Kunjungi Halaman Twitter VEX Robotics Kunjungi Halaman Instagram VEX Robotics Kunjungi Halaman YouTube VEX Robotics
Formulir Umpan Balik API VEX

Kami menghargai masukan Anda! Gunakan formulir ini untuk berbagi saran, pujian, atau melaporkan kesalahan pada API VEX. Masukan Anda membantu kami meningkatkan dokumentasi API VEX.

​

Jika Anda mengalami masalah teknis atau memerlukan dukungan pelanggan, silakan kunjungi support.vex.com.

  • Send Happy Feedback
  • Send Sad Feedback

Catatan: URL saat ini akan dibagikan bersama pesan Anda.

Dengan mencantumkan alamat email Anda, Anda setuju bahwa VEX dapat mengirimkan email kepada Anda jika kami memiliki pertanyaan tentang masukan Anda.
Kebijakan Privasi >
Mohon berikan masukan Anda. Masukan berhasil dikirim!
Choose Which VEX IQ Generation to View

VEX IQ (1st gen)

VEX IQ (2nd gen)