• 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 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 카드
    • 6축 암
    • 신호탑
    • VEX링크
      • 메시지 링크
      • 시리얼링크
    • 콘솔
    • 논리
    • 마이크로파이썬 라이브러리
  • 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

    • 보내다

    • 받다

    • 받았다

소개#

SerialLink는 두 EXP Brain이 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 – 이 Brain이 쌍을 이루는 Brain에 활발하게 연결되어 있는지 여부를 반환합니다.

  • send – 쌍을 이룬 Brain에 짧은 메시지(선택적으로 int/float 데이터 포함)를 보냅니다.

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

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

링크 생성#

EXP Brain 두 대 모두에 SerialLink를 생성하여 V5 로봇 라디오를 사용한 무선 통신 또는 스마트 케이블을 사용한 유선 통신을 통해 로봇 간 통신 채널을 구축하십시오. 이렇게 하면 로봇들이 서로에게 원시 직렬 데이터를 전송할 수 있습니다.

SerialLink(smartport, name, linktype, wired)

매개변수

설명

smartport

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

name

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

linktype

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

  • VexlinkType.MANAGER – 더 많거나 더 큰 메시지를 보내는 로봇에 사용합니다. 관리자는 더 높은 송신 대역폭(~1040바이트/초)을 가집니다.
  • VexlinkType.WORKER – 더 적거나 더 작은 메시지를 보내는 로봇에 사용합니다. 작업자는 더 낮은 송신 대역폭(~520바이트/초)을 가집니다.

wired

선택 사항입니다. 이 연결이 유선인지 무선인지 여부를 지정합니다.

  • True – EXP 브레인은 스마트 케이블을 통해 연결됩니다.
  • False (기본값) – EXP 브레인은 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 설정이 완료되고 Brains가 연결되면 아래 방법을 사용하여 원시 직렬 데이터를 송수신하고 응답할 수 있습니다.

is_linked#

is_linked 메서드는 SerialLink의 EXP Brain이 서로 쌍을 이루고 있는지 여부를 반환합니다.

  • 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 브레인으로 원시 직렬 바이트를 전송합니다.

receive로 해당 데이터를 읽을 때 receive length 매개변수로 지정된 바이트 수를 수집한 후에만 반환됩니다. 따라서 코드가 항상 고정된 length로 receive 호출하는 경우 send 로 전송되는 각 메시지가 정확히 그 바이트 수(종종 패딩을 통해)인지 확인하여 수신자가 추가 바이트를 기다리며 차단되지 않도록 해야 합니다.

정확한 바이트 수에 의존하고 싶지 않다면 대신 received를 사용하세요. 이렇게 하면 특정 길이를 요구하지 않고 사용 가능한 바이트를 처리할 수 있습니다.

Usage:
send(buffer)

매개변수

설명

buffer

연결된 다른 EXP Brain으로 보낼 데이터입니다. 이는 string 또는 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 순서(가장 오래된 읽지 않은 데이터부터)로 반환합니다.

receive 정확한 바이트 수를 기다리기 때문에, 고정 길이 메시징에서는 send 사용할 때 각 메시지가 예상 크기에 도달하도록 패딩이 필요한 경우가 많습니다. 송신자가 length 바이트보다 적은 바이트를 전송하면 receive 나머지 바이트를 계속 기다리고 아무것도 반환하지 않습니다.

큐가 비어 있고 타임아웃 값을 timeout, receive 초 동안 새 데이터가 도착할 때까지 기다립니다. 해당 시간 내에 데이터가 도착하지 않으면 None반환합니다. 이후에 전송되는 모든 데이터는 나중에 읽을 수 있도록 큐에 남아 있습니다.

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

선택 사항입니다. 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

EXP Brain이 직렬 데이터를 수신할 때 실행되는 이전에 정의된 함수.

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.의 상표 또는 서비스 마크입니다. 저작권 ©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)