• 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 API 참조
  • VEX링크
  • 메시지 링크
한국어
  • 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 카드
    • VEX링크
      • 메시지 링크
      • 시리얼링크
    • 콘솔
    • 논리
    • 6축 암
    • 자석
    • 경쟁
    • 마이크로파이썬 라이브러리
  • 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

메시지 링크#

  • 소개

  • 링크 생성

  • 사용 가능한 방법

    • is_linked

    • 보내다

    • 받다

    • 받았다

소개#

MessageLink는 두 대의 V5 Brain 로봇이 짧은 문자열 메시지와 선택적으로 소량의 데이터를 주고받으며 통신할 수 있도록 해줍니다. 이 기능은 로봇 간의 협업, 예를 들어 루틴 시작, 센서 결과 공유 또는 다른 로봇의 동작 실행 등을 위해 설계되었습니다.

send을 사용할 때마다 연결된 V5 Brain의 큐에 메시지가 추가되며, 큐는 선입선출(FIFO) 방식으로 읽힙니다. 다른 V5 Brain이 receive을 사용하기 전에 여러 메시지가 전송되면 해당 메시지는 전송된 순서대로 하나씩 저장되고 반환됩니다. 메시지는 큐에 저장될 수 있으므로 매 루프마다 동일한 상태를 반복적으로 전송하면 백로그가 발생할 수 있습니다. 시간 제약이 있는 로직의 경우 값이 변경될 때만 전송하십시오.

중요: 두 로봇 모두 동시에 MessageLink MessageLink 사용하는 프로젝트를 실행해야 합니다. 그렇지 않으면 메시지가 송수신되지 않습니다.

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

다음은 사용 가능한 방법 목록입니다.

  • is_linked – 이 Brain이 쌍을 이루는 Brain에 활발하게 연결되어 있는지 여부를 반환합니다.

  • send – 쌍을 이룬 Brain에 메시지를 보냅니다.

  • receive – 다음 수신 메시지를 기다리고 반환합니다.

  • received – 새 메시지가 수신될 때마다 호출될 함수를 등록합니다.

링크 생성#

두 대의 V5 브레인에 메시지링크를 생성하여 두 로봇 간의 통신 채널을 구축하십시오. 무선으로는 V5 로봇 라디오를 사용하거나 유선 스마트 케이블을 통해 연결할 수 있습니다. 이렇게 하면 로봇들이 서로 메시지를 주고받을 수 있습니다.

MessageLink(smartport, name, linktype, wired)

매개변수

설명

smartport

이 링크에 사용되는 스마트 포트는 V5 로봇 라디오가 연결된 포트(무선) 또는 스마트 케이블이 꽂힌 포트(유선)입니다. 형식은 Ports.PORTx 이며, 여기서 x는 포트 번호입니다.

name

이 링크에 부여할 고유한 문자열 이름입니다.
참고: 이 이름은 다른 팀의 링크와 실수로 겹치지 않도록 고유 ID를 생성할 수 있을 만큼 충분히 길어야 합니다.

linktype

이 브레인이 해당 링크 쌍에 사용할 역할입니다. 각 쌍에는 관리자 1명과 작업자 1명이 포함되어야 합니다.

  • 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 설정이 완료되고 Brains가 연결되면 아래 방법을 사용하여 메시지를 보내고 받고 답장할 수 있습니다.

is_linked#

is_linked 메서드는 MessageLink의 V5 Brain이 서로 쌍을 이루는지 여부를 반환합니다.

  • True – 두 개의 V5 브레인이 페어링되어 이 링크를 통해 통신하고 있습니다.

  • False – 이 링크에서는 두 개의 V5 브레인이 쌍을 이루지 않습니다.

참고: 프로젝트 시작 시 추가 코드를 실행하기 전에 V5 브레인이 제대로 연결되었는지 항상 확인하는 것이 좋습니다.

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 브레인으로 문자열 및/또는 정수 및/또는 부동 소수점을 전송합니다.

Usage:
send(string, integer, float)

매개변수

설명

string

연결된 다른 V5 브레인으로 보낼 문자열입니다.

integer

선택 사항입니다. 연결된 다른 V5 브레인으로 보낼 정수입니다.

float

선택 사항입니다. 연결된 다른 V5 브레인으로 보낼 부동 소수점 값입니다. 부동 소수점 값은 소수점 이하 4자리까지 형식이 지정됩니다. 4자리보다 적은 자릿수를 제공하면 4자리가 표시될 때까지 끝에 0이 추가됩니다.

If only string is sent, the other linked V5 Brain receives that exact string.

만약 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 브레인이 string만 보냈다면, receive 수신하고 정확히 그 문자열을 반환합니다.

다른 연결된 V5 브레인이 정수 및/또는 부동 소수점을 전송한 경우, receive 수신하고 모든 필드를 다음 순서로 결합한 단일 인코딩된 문자열을 반환합니다: .string_integer_float

예를 들어, 연결된 다른 V5 브레인이 link.send(“string”, 1, 2.55)사용하는 경우, <code>link.receive()</code> 를 사용하면<code>.string_1_2.5500</code> 같은 인코딩된 문자열이 반환됩니다. 이 인코딩된 문자열을 분할하여(아래 예 참조) 메시지 이름, 정수 및 부동 소수점 값을 추출할 수 있습니다.

수동 분할/구문 분석을 피하려면 received를 사용하여 특정 메시지 이름에 대한 핸들러를 등록하세요. 핸들러는 전송된 값을 인수로 받습니다.

Usage:
receive(timeout)

매개변수

설명

timeout

선택 사항입니다. receive 새 메시지를 수신하는 데 걸리는 시간(밀리초)입니다. 기본값은 300,000(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 등록합니다.

Usage:
link.received(message, arg)

매개변수

설명

message

일치시킬 메시지 이름(문자열). 수신된 메시지의 이름이 이 값과 일치하면 callback 호출됩니다.

callback

V5 브레인이 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)

이전

VEX링크

다음

시리얼링크

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
사이트 개인정보 보호정책 / 사이트 이용약관 / 쿠키 정책 / 소프트웨어 개인정보 보호정책

VEX Robotics 페이스북 페이지를 방문하세요 VEX Robotics 트위터 페이지를 방문하세요 VEX Robotics 인스타그램 페이지를 방문하세요 VEX Robotics 유튜브 페이지를 방문하세요
VEX API 피드백 양식

여러분의 소중한 의견을 기다립니다! 이 양식을 사용하여 VEX API에 대한 제안, 칭찬 또는 오류를 보고해 주세요. 여러분의 의견은 VEX API 문서 개선에 큰 도움이 됩니다.

If you are experiencing technical issues or require customer support, please visit 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)