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

رابط الرسائل#

  • مقدمة

  • إنشاء رابط

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

    • مرتبط

    • يرسل

    • يستلم

    • تلقى

مقدمة#

تتيح تقنية MessageLink لروبوتين من طراز V5 Brains التواصل عبر إرسال رسائل نصية قصيرة مع بيانات صغيرة اختيارية. وهي مصممة لتنسيق العمليات بين الروبوتات، مثل بدء الإجراءات الروتينية، ومشاركة نتائج المستشعرات، أو تحفيز سلوكيات معينة على روبوت آخر.

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

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

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

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

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

  • send – يرسل رسالة إلى الدماغ المقترن.

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

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

إنشاء رابط#

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

MessageLink(smartport, name, linktype, wired)

المعلمة

وصف

smartport

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

name

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

linktype

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

  • VexlinkType.MANAGER - يُستخدم للروبوت الذي سيرسل عددًا أكبر من الرسائل أو رسائل أكبر حجمًا. يتمتع المديرون بنطاق ترددي صادر أعلى (~1040 بايت/ثانية).
  • VexlinkType.WORKER - يُستخدم للروبوت الذي سيرسل عددًا أقل من الرسائل أو رسائل أصغر حجمًا. يتمتع العمال بنطاق ترددي صادر أقل (~520 بايت/ثانية).

wired

اختياري. ما إذا كان هذا الاتصال سلكيًا أم لاسلكيًا:

  • True - يتم توصيل وحدات التحكم V5 عبر كابل ذكي.
  • False (افتراضي) - تتصل وحدات التحكم V5 لاسلكيًا باستخدام أجهزة راديو 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 الخاص بك وربط العقول، يمكنك استخدام الطرق التالية لإرسال الرسائل واستقبالها والرد عليها.

is_linked#

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

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

  • False - لم يتم إقران جهازي V5 Brains على هذا الرابط.

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

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 V5 Brain الأخرى المرتبطة.

Usage:
send(string, integer, float)

حدود

وصف

string

السلسلة المراد إرسالها إلى وحدة التحكم V5 الأخرى المرتبطة.

integer

اختياري. عدد صحيح لإرساله إلى وحدة V5 Brain الأخرى المرتبطة.

float

اختياري. قيمة عشرية لإرسالها إلى وحدة المعالجة المركزية V5 الأخرى المرتبطة. يتم تنسيق القيم العشرية إلى 4 منازل عشرية؛ إذا تم توفير عدد أقل من المنازل العشرية، تتم إضافة أصفار لاحقة حتى يتم عرض 4 منازل عشرية.

إذا تم إرسال السلسلة string فإن وحدة V5 Brain الأخرى المرتبطة بها تتلقى تلك السلسلة بالضبط.

إذا تم تضمين integer و/أو float ، فإن الدماغ المستقبل يحصل على سلسلة مشفرة واحدة تجمع جميع الحقول بهذا الترتيب: .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 الرسالة التالية المُدرجة في قائمة الانتظار من وحدة المعالجة V5 الأخرى المرتبطة. تُقرأ الرسائل بترتيب FIFO (الأقدم غير المقروءة أولاً). إذا كانت قائمة الانتظار فارغة عند استدعاء receive ، فإنه ينتظر حتى انتهاء timeout لرسالة جديدة. إذا لم تصل أي رسالة خلال هذه المهلة، يُعيد receive القيمة None، وتبقى أي رسالة مُرسلة بعد ذلك في قائمة الانتظار ليتم قراءتها في المرة التالية التي يُستخدم فيها الأمر receive.

إذا أرسل جهاز V5 Brain المرتبط الآخر سلسلة stringو receive ويعيدان تلك السلسلة بالضبط.

إذا أرسل معالج V5 Brain الآخر المرتبط عددًا صحيحًا و/أو عددًا عشريًا، فإن receive ، ويعيد سلسلة مشفرة واحدة تجمع جميع الحقول بهذا الترتيب: .string_integer_float

على سبيل المثال، إذا استخدم معالج V5 المرتبط الآخر الدالة link.send(“string”, 1, 2.55)، فإن استخدام الدالة link.receive() يُعيد سلسلة مُشفّرة مثل .string_1_2.5500. يمكنك تقسيم هذه السلسلة المُشفّرة (انظر الأمثلة أدناه) لاستخراج اسم الرسالة، والقيم الصحيحة، والقيم العشرية.

إذا كنت تفضل تجنب التقسيم/التحليل اليدوي، فاستخدم received لتسجيل معالج لاسم رسالة معين؛ يتلقى المعالج القيم المرسلة كوسائط.

Usage:
receive(timeout)

حدود

وصف

timeout

اختياري. مدة الانتظار بالمللي ثانية receive تعني انتظار رسالة جديدة فقط إذا كانت قائمة الانتظار فارغة. القيمة الافتراضية هي 300000 (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 يسجل وظيفة ليتم استدعاؤها كلما استقبلت وحدة V5 Brain رسالة مرسلة.

Usage:
link.received(message, arg)

حدود

وصف

message

اسم الرسالة (نص) المراد مطابقته. عند مطابقة اسم الرسالة المستلمة مع هذه القيمة، يتم استدعاء دالة رد الاتصال callback.

callback

A previously defined function that runs when the V5 Brain receives a message matching message.

تم استلام received دالة رد نداء بأربعة وسائط:

توقيع الاستدعاء:
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

التالي

SerialLink

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)