• 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
  • VEXlink
  • SerialLink
العربية
  • 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
    • نظام نقل الحركة
    • حركة
    • صوت
    • رؤية
    • شاشة
    • وحدة التحكم
    • الاستشعار
    • القصور الذاتي
    • الأجهزة ثلاثية الأسلاك
    • هوائي
    • مخ
    • بطاقة SD
    • ذراع سداسي المحاور
    • برج الإشارة
    • VEXlink
      • رابط الرسائل
      • SerialLink
    • وحدة التحكم
    • منطق
    • مكتبات مايكرو بايثون
  • 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#

  • مقدمة

  • إنشاء رابط

  • الطرق المتاحة

    • مرتبط

    • يرسل

    • يستلم

    • تلقى

مقدمة#

تتيح تقنية SerialLink لوحدتي تحكم EXP Brains التواصل عبر إرسال واستقبال بيانات تسلسلية خام باستخدام VEX Link. وبدلاً من الرسائل المُصنّفة، تنقل SerialLink مخزنًا مؤقتًا (سلسلة نصية أو مصفوفة بايتات). وهذا يجعلها مفيدةً للتواصل المتقدم بين الروبوتات، مثل بث بيانات المستشعرات، وإرسال تنسيقات حزم مخصصة، أو بناء بروتوكول خاص بك باستخدام البايتات.

كل استخدام للأمر send يُضيف بيانات إلى مخزن الاستقبال الخاص بـ EXP Brain المرتبط. تُقرأ البيانات حسب ترتيب وصولها (الأولوية للأقدم). إذا تم إرسال عدة مخازن بيانات قبل أن يستخدم EXP Brain الآخر الأمر receive، فإنها تبقى في قائمة الانتظار وتُعاد واحدة تلو الأخرى بالترتيب الذي أُرسلت به. نظرًا لإمكانية تراكم البيانات في قائمة الانتظار، فإن إرسال مخازن بيانات كبيرة بشكل متكرر في كل دورة قد يُؤدي إلى تراكم البيانات؛ لذا، بالنسبة للروابط الحساسة للوقت، أرسل فقط ما تحتاجه.

هام: يجب أن يقوم كلا الروبوتين بتشغيل مشاريع تستخدم SerialLink في نفس الوقت، وإلا فلن يتم إرسال/استقبال أي بيانات.

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

فيما يلي قائمة بالطرق المتاحة:

  • is_linked – تُرجع ما إذا كان هذا الدماغ متصلاً بشكل فعال بالدماغ المقترن به.

  • send – يرسل رسالة قصيرة (مع بيانات اختيارية من نوع int/float) إلى الدماغ المقترن.

  • receive – ينتظر ويعيد الرسالة الواردة التالية.

  • received – يسجل دالة ليتم استدعاؤها كلما تم استلام رسالة جديدة.

إنشاء رابط#

قم بإنشاء رابط تسلسلي على كل من دماغي EXP لإنشاء قناة اتصال بينهما - إما لاسلكيًا باستخدام أجهزة راديو الروبوت V5 أو من خلال كابل ذكي سلكي - حتى تتمكن الروبوتات من إرسال بيانات تسلسلية خام إلى بعضها البعض.

SerialLink(smartport, name, linktype, wired)

المعلمة

وصف

smartport

المنفذ الذكي المستخدم لهذا الاتصال هو المنفذ الذي يتصل به جهاز راديو الروبوت V5 (لاسلكيًا) أو المنفذ الذي يتم توصيل الكابل الذكي به (سلكيًا). يُكتب على النحو التالي: Ports.PORTx حيث x هو رقم المنفذ.

name

الاسم الفريد الذي يُطلق على هذا الرابط كسلسلة نصية.
ملاحظة: يجب أن يكون هذا الاسم طويلاً بما يكفي لإنشاء مُعرّف فريد حتى لا يتطابق عن طريق الخطأ مع رابط فريق آخر.

linktype

الدور الذي سيستخدمه هذا الدماغ لهذا الزوج من الروابط. يجب أن يتضمن كل زوج مديرًا واحدًا وعاملًا واحدًا:

  • 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 الخاص بك وربط وحدات المعالجة، يمكنك استخدام الطرق أدناه لإرسال واستقبال والرد على البيانات التسلسلية الخام.

is_linked#

is_linked تُرجع هذه الطريقة ما إذا كانت وحدات EXP Brains الموجودة على SerialLink مقترنة ببعضها البعض.

  • True - يتم إقران دماغي EXP ويتواصلان عبر هذا الرابط.

  • False - لم يتم إقران دماغي EXP على هذا الرابط.

ملاحظة: من الممارسات الجيدة دائمًا التحقق من ربط EXP Brains في بداية المشروع قبل تشغيل أي كود إضافي.

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

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 يعيد البيانات التسلسلية من وحدة EXP Brain الأخرى المرتبطة بترتيب FIFO (أقدم البيانات غير المقروءة أولاً).

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

عدد البايتات المطلوب استقبالها. receive ينتظر حتى وصول هذا العدد من البايتات، ثم يُعيدها كمصفوفة بايتات receiveإذا كان الطول receive هو 0، bytearray يُعيد length فورًا. إذا طلبت بايتات أكثر مما يُرسله المُرسِل، length سيستمر في الانتظار. إذا أرسل المُرسِل أكثر من ذلك، فإن المخزن المؤقت المُعاد يقتصر على الطول None بايت.

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 يسجل وظيفة يتم استدعاؤها كلما استقبلت وحدة المعالجة المركزية بيانات تسلسلية.

Usage:
link.received(callback)

حدود

وصف

callback

A previously defined function that executes when the EXP Brain receives serial data.

تم استلام received دالة رد نداء مع وسيطين:

توقيع الاستدعاء:
callback(buffer, length)

دعوى

وصف

buffer

مصفوفة بايتات bytearray تكون مصفوفة البايتات أكبر من الرسالة المستلمة.

length

عدد البايتات الصالحة المستلمة في المخزن المؤقت buffer لهذه الدالة. استخدم المخزن المؤقت buffer[:length] للوصول إلى البيانات المستلمة.

كود للروبوت 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. حقوق الطبع والنشر © ٢٠٢٦جميع الحقوق محفوظة. VEX Robotics, Inc. هي شركة تابعة لشركة Innovation First International, Inc. جميع أسماء المنتجات/العلامات التجارية الأخرى هي ملك لأصحابها المعنيين. براءات الاختراع و/أو براءات الاختراع قيد الانتظار - innovationfirst.com/patents
سياسة خصوصية الموقع / شروط استخدام الموقع / سياسة ملفات تعريف الارتباط / سياسة خصوصية البرامج

تفضل بزيارة صفحة VEX Robotics على فيسبوك تفضل بزيارة صفحة VEX Robotics على تويتر تفضل بزيارة صفحة VEX Robotics على إنستغرام تفضل بزيارة صفحة VEX Robotics على يوتيوب
نموذج ملاحظات حول واجهة برمجة تطبيقات VEX

نُقدّر ملاحظاتكم! استخدموا هذا النموذج لمشاركة اقتراحاتكم، أو إشاداتكم، أو الإبلاغ عن أخطاء في واجهة برمجة تطبيقات VEX. تساعدنا ملاحظاتكم على تحسين وثائق واجهة برمجة تطبيقات VEX.

​

إذا كنت تواجه مشكلات فنية أو تحتاج إلى دعم العملاء، فيُرجى زيارة 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)