• 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
  • Αναφορά API VEX EXP
  • VEXlink
  • Σειριακός σύνδεσμος
Ελληνικά
  • English
  • Español
  • 简体中文
  • VEXcode Robotics Logo

Πλοήγηση ενότητας

  • Μπλοκ
  • Πύθων
    • Σύστημα μετάδοσης κίνησης
    • Κίνηση
    • Ήχος
    • Οραμα
    • Οθόνη
    • Ελεγκτής
    • Εξεύρεση της φόρας
    • Αδρανειακό
    • Συσκευές 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 επιτρέπει σε δύο εγκεφάλους EXP να επικοινωνούν στέλνοντας και λαμβάνοντας ακατέργαστα σειριακά δεδομένα μέσω του VEX Link. Αντί για μηνύματα με ετικέτες, το SerialLink μεταδίδει ένα buffer (μια συμβολοσειρά ή ένα bytearray). Αυτό το καθιστά χρήσιμο για προηγμένη επικοινωνία μεταξύ ρομπότ, όπως ροή δεδομένων αισθητήρων, αποστολή προσαρμοσμένων μορφών πακέτων ή δημιουργία του δικού σας πρωτοκόλλου πάνω από bytes.

Every usage of send adds data to the linked EXP Brain’s receive buffer. Data is read in the order it arrives (first-in, first-out). If multiple buffers are sent before the other EXP Brain uses receive, they remain queued and are returned one at a time in the order they were sent. Because data can queue, repeatedly sending large buffers every loop may create backlog; for time-critical links, send only what you need.

Important: Both robots must be running projects that use SerialLink at the same time, or no data will be sent/received.

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

Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:

  • is_linked – Returns whether this Brain is actively connected to its paired Brain.

  • send – Sends a short message (with optional int/float data) to the paired Brain.

  • receive – Waits for and returns the next incoming message.

  • received – Registers a function to be called whenever a new message is received.

Δημιουργία συνδέσμου#

Δημιουργήστε μια Σειριακή Σύνδεση και στους δύο εγκεφάλους EXP για να δημιουργήσετε ένα κανάλι επικοινωνίας μεταξύ τους —είτε ασύρματα με τα V5 Robot Radios είτε μέσω ενός ενσύρματου Smart Cable— ώστε τα ρομπότ να μπορούν να στέλνουν ακατέργαστα σειριακά δεδομένα μεταξύ τους.

SerialLink(smartport, name, linktype, wired)

Παράμετρος

Περιγραφή

smartport

The Smart Port used for this link—the port the V5 Robot Radio is connected to (wireless) or the Smart Cable is plugged into (wired). Written as Ports.PORTx where x is the port number.

name

Το μοναδικό όνομα που θα δοθεί σε αυτόν τον σύνδεσμο ως συμβολοσειρά.
Σημείωση: Αυτό το όνομα πρέπει να είναι αρκετά μεγάλο για να δημιουργήσει ένα μοναδικό αναγνωριστικό, ώστε να μην ταιριάζει κατά λάθος με τον σύνδεσμο άλλης ομάδας.

linktype

The role this Brain will use for this link pair. Each pair must include one Manager and one Worker:

  • VexlinkType.MANAGER – Use for the robot that will send more or larger messages. Managers have higher outbound bandwidth (~1040 bytes/sec).
  • VexlinkType.WORKER – Use for the robot that will send fewer or smaller messages. Workers have lower outbound bandwidth (~520 bytes/sec).

wired

Optional. Whether this link is wired or wireless:

  • True – The EXP Brains are connected via a Smart Cable.
  • False (default) – The EXP Brains connect wirelessly using V5 Robot Radios.

Κωδικός για το Ρομπότ 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 και συνδεθούν οι Brains, μπορείτε να χρησιμοποιήσετε τις παρακάτω μεθόδους για να στέλνετε, να λαμβάνετε και να απαντάτε σε ακατέργαστα σειριακά δεδομένα.

is_linked#

is_linked method returns whether the EXP Brains on a SerialLink are paired with one another.

  • True – The two EXP Brains are paired and communicating on this link.

  • False – The two EXP Brains are not paired on this link.

Σημείωση: Είναι καλή πρακτική να ελέγχετε πάντα για να βεβαιωθείτε ότι οι εγκέφαλοι EXP είναι συνδεδεμένοι στην αρχή ενός έργου πριν από την εκτέλεση οποιουδήποτε περαιτέρω κώδικα.

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 transmits raw serial bytes to the other linked 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.

If you don’t want to depend on an exact byte count, use received instead; it lets you handle whatever bytes are available without requiring a specific length.

Usage:
send(buffer)

Παράμετροι

Περιγραφή

buffer

The data to send to the other linked EXP Brain. This can be a string or a 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 returns serial data from the other linked EXP Brain in FIFO order (oldest unread data first).

Because receive waits for an exact byte count, fixed-length messaging often requires padding when using send so each message reaches the expected size. If the sender transmits fewer than length bytes, receive will continue waiting for the remaining bytes and not return anything.

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

Optional. How long in milliseconds receive will wait for a new message only if the queue is empty. Default is 300000 (300 seconds).

Κωδικός για το Ρομπότ 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 registers a function to be called whenever the EXP Brain receives serial data.

Usage:
link.received(callback)

Παράμετροι

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο εγκέφαλος EXP λαμβάνει σειριακά δεδομένα.

received callbacks are called with two arguments:

Callback Signature:
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. Πνευματικά δικαιώματα ©2026. Με επιφύλαξη παντός δικαιώματος. Η VEX Robotics, Inc. είναι θυγατρική της Innovation First International, Inc. Όλα τα άλλα ονόματα προϊόντων/σήματα τρίτων αποτελούν ιδιοκτησία των αντίστοιχων κατόχων τους. Διπλώματα ευρεσιτεχνίας ή/και Διπλώματα ευρεσιτεχνίας σε εκκρεμότητα - innovationfirst.com/patents
Πολιτική απορρήτου ιστότοπου / Όροι χρήσης ιστότοπου / Πολιτική για τα cookie / Πολιτική απορρήτου λογισμικού

Επισκεφθείτε τη σελίδα 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)