• 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
  • C++
    • 구동계
    • 모터 및 모터 컨트롤러
    • 제어 장치
    • 뇌
    • 경쟁
    • 스마트 포트 장치
    • 3선 장치
    • 콘솔
    • 논리
    • VEX링크
      • 메시지 링크
      • 직렬 링크
    • CTE 워크셀
  • 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

메시지 링크#

  • 소개

  • 클래스 생성자

  • 클래스 소멸자

  • 매개변수

  • 예

  • 회원 기능

    • isLinked

    • 보내다

    • 받다

    • 받았다

소개#

message_link 클래스는 두 대의 V5 Brain 로봇이 짧은 문자열 메시지와 선택적으로 소량의 데이터를 주고받으며 통신할 수 있도록 합니다. 이 클래스는 로봇 간 조정, 예를 들어 루틴 시작, 센서 결과 공유 또는 다른 로봇의 동작 트리거 등에 사용하도록 설계되었습니다.

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

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

클래스 생성자#

message_link( 
  int32_t     index, 
  const char  *name, 
  linkType    type, 
  bool        isWired = false );

클래스 소멸자#

message_link 객체를 파괴하고 관련 리소스를 해제합니다.

virtual ~message_link();

매개변수#

매개변수

유형

설명

index

int32_t

V5 라디오 또는 스마트 케이블이 연결된 스마트 포트는 PORTx형식으로 표기되며, 여기서 x 포트 번호입니다(예: PORT1).

name

char

메시지 링크의 이름입니다.

type

linkType

링크 유형은 linkType::manager 또는 linkType::worker입니다. 이 정보는 무선 장치를 올바르게 구성하고 송수신에 사용 가능한 대역폭을 결정하는 데 사용됩니다. 관리자 로봇은 작업자 로봇(초당 520바이트)보다 두 배 많은 대역폭(초당 1040바이트)을 사용하여 정보를 전송할 수 있습니다.

  • linkType::manager - message_link 객체가 관리자입니다.
  • linkType::worker - message_link 객체가 작업자입니다.

isWired

bool

message_link 객체가 유선인지 여부.

  • true - message_link 객체가 유선입니다.
  • false - message_link 객체가 무선입니다.

예#

로봇 1용 코드

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::manager, // type
  true); // isWired

로봇 2용 코드

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::worker, // type
  true); // isWired

회원 기능#

message_link 클래스에는 다음과 같은 멤버 함수가 포함되어 있습니다.

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

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

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

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

message_link 멤버 함수를 호출하기 전에 아래와 같이 message_link 인스턴스를 생성해야 합니다.

로봇 1용 코드

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::manager, // type
  true); // isWired

로봇 2용 코드

// Create a wireless link in Port 1
message_link link = message_link(
  PORT1, // index
  "VEXRoboticsLink123456789", // name
  linkType::worker, // type
  true); // isWired

isLinked#

isLinked 메서드는 MessageLink의 V5 Brain이 서로 페어링되었는지 여부를 반환합니다.

Available Functions
bool isLinked();

Parameters

이 함수는 매개변수가 없습니다.

Return Values

이 함수는 부울 값을 반환합니다.

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

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

Notes

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

Examples

로봇 1용 코드

// Tell the other robot when the screen is being pressed
  // Create the link
  message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()){
    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(0.05, seconds);
  }

로봇 2용 코드

// Display if the other robot's screen is being pressed

  // Create the link
  message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);
  
  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()){
   wait(0.1, seconds);
  }

  // Continuously check if Robot 1 has sent "pressed"
  while (true){
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();
    char msg[32] = {0};                         // buffer for incoming message
    int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
    if (n > 0 && strcmp(msg, "pressed") == 0) {
      Brain.Screen.newLine();
      Brain.Screen.print("Manager is being pressed!");
    }
    wait(0.05, seconds);
  }

send#

링크 연결을 통해 메시지를 전송합니다.

Available Functions

1 — 메시지 문자열을 보냅니다.

int32_t send( 
  const char *message );

2 — double 이 두 개 있는 메시지 문자열을 보냅니다.

int32_t send( 
  const char *message, 
  double      value );

3 — int32_t 과 double 을 포함하는 메시지 문자열을 보냅니다.

int32_t send(
  const char *message, 
  int32_t     index, 
  double      value );

Parameters

매개변수

유형

설명

message

const char*

연결된 다른 V5 브레인에게 보낼 메시지입니다.

index

int32_t

연결된 다른 V5 브레인으로 보낼 정수 값입니다.

value

double

연결된 다른 V5 브레인으로 전송할 double형 데이터입니다. double형 데이터는 소수점 4자리까지 표시되어야 하며, 4자리보다 적은 자릿수가 제공될 경우 4자리가 표시될 때까지 끝에 0이 추가됩니다.

Return Values

이 함수는 값을 반환하지 않습니다.

Notes

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

value (및 제공된 경우 index )이 포함되면 수신 브레인은 모든 필드를 다음 순서로 결합한 단일 인코딩 메시지를 받습니다: .message_index_value

Examples

link.send(“string”, 1, 2.55) .string_1_2.5500 으로 수신됩니다.

로봇 1용 코드

// Tell the other robot when the screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  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(0.05, seconds);
}

로봇 2용 코드

// Display if the other robot's screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}
// Continuously check if Robot 1 has sent "pressed"
while (true){
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  char msg[32] = {0};  // buffer for incoming message
  int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
  if (n > 0 && strcmp(msg, "pressed") == 0) {
    Brain.Screen.newLine();
    Brain.Screen.print("Manager is being pressed!");
  }
  wait(0.05, seconds);
}

receive#

링크 연결로부터 메시지를 수신합니다.

Available Functions
int32_t receive(
  char     *buffer,
  int32_t   length, 
  int32_t   timeoutMs = 500 );

Parameters

매개변수

유형

설명

buffer

char*

수신된 메시지를 저장하는 버퍼.

length

int32_t

버퍼의 길이.

timeoutMs

int32_t

receive 새 메시지를 수신하는 데 걸리는 시간을 밀리초 단위로 지정합니다. 기본값은 300,000(300초)입니다.

Return Values

이 함수는 수신된 바이트 수를 반환합니다.

Notes
  • receive 연결된 다른 V5 브레인에서 대기 중인 다음 메시지를 반환합니다. 메시지는 FIFO 순서(가장 오래된 미읽은 메시지부터)로 읽습니다. receive 호출될 때 큐가 비어 있으면 지정된 timeout 까지 새 메시지를 기다립니다. 해당 시간 내에 메시지가 도착하지 않으면 receive 은 0을 반환하고, 이후에 전송된 메시지는 다음에 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를 사용하여 특정 메시지 이름에 대한 핸들러를 등록하세요. 핸들러는 전송된 값을 인수로 받습니다.

Examples

link.send(“string”, 1, 2.55) .string_1_2.5500 으로 수신됩니다.

로봇 1용 코드

// Tell the other robot when the screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  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(0.05, seconds);
}

로봇 2용 코드

// Display if the other robot's screen is being pressed

// Create the link
message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

// Do not run code UNTIL the Brains are linked
while (!link.isLinked()){
  wait(0.1, seconds);
}
// Continuously check if Robot 1 has sent "pressed"
while (true){
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  char msg[32] = {0};   // buffer for incoming message
  int32_t n = link.receive(msg, sizeof(msg), 100);  // wait up to 100ms
  if (n > 0 && strcmp(msg, "pressed") == 0) {
    Brain.Screen.newLine();
    Brain.Screen.print("Manager is being pressed!");
  }
  wait(0.05, seconds);
}

received#

V5 브레인이 전송된 메시지를 수신할 때마다 호출될 함수를 등록합니다.

Available Functions

1 수신된 모든 메시지(메시지 + 값)에 대한 콜백을 등록합니다.

void received(
    void (* callback)(const char *, const char *, double)
);

2 수신된 모든 메시지(메시지 + 인덱스 + 값)에 대한 콜백을 등록합니다.

void received(
    void (* callback)(const char *, const char *, int32_t, double)
);

3 특정 메시지(메시지 + 값)에 대한 콜백을 등록합니다.

void received(
    const char *message,
    void      (* callback)(const char *, const char *, double)
);

4 특정 메시지(메시지 + 인덱스 + 값)에 대한 콜백을 등록합니다.

void received(
    const char *message,
    void      (* callback)(const char *, const char *, int32_t, double)
);

Parameters

매개변수

유형

설명

message

const char *

수신 대기할 메시지 이름입니다. 생략하면 수신된 모든 메시지에 대해 콜백 함수가 실행됩니다.

callback

void (*)(const char *, const char , double) or void ()(const char *, const char *, int32_t, double)

메시지가 수신될 때 실행되는 함수입니다.

Return Values

이 함수는 값을 반환하지 않습니다.

Callback Signature

1 발신자 이름, 메시지 이름 및 값을 수신합니다.

void callback(const char *, const char *, double)

2 발신자 이름, 메시지 이름, 인덱스 및 값을 수신합니다.

void callback(const char *, const char *, int32_t, double)

유형

설명

1st const char *

발신자 링크 이름입니다.

2nd const char *

수신된 메시지 이름입니다.

int32_t

메시지와 연결된 인덱스입니다.

double

메시지와 관련된 값입니다.

Examples

로봇 1용 코드

// Create the link.
message_link link(PORT1, "LeftRightLink", linkType::manager, true);

// Send whether screen is pressed on left or right.
void screen_pressed() {
  if (Brain.Screen.xPosition() < 240) {
    link.send("left");
  } else {
    link.send("right");
  }
}

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();
  
  // Do not run code UNTIL the Brains are linked.
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }

  Brain.Screen.print("Robot 1 - Manager");

  Brain.Screen.pressed(screen_pressed);

  while (true) {
    wait(10, msec);
  }
}

로봇 2용 코드

// Create variable to track where screen is pressed.
int lastPress = 0;

// Update the variable whenever a new message is received.
void message_received(const char* message, const char* linkname, double timestamp) {
  if (strcmp(message, "left") == 0)  lastPress = 1;
  if (strcmp(message, "right") == 0) lastPress = 2;
}

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Create the link.
  message_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true);

  // Do not run code UNTIL the Brains are linked.
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }

  link.received(message_received);

  // Display if Robot 1's screen was pressed on the left or right
  while (true) {
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();

    if (lastPress == 1) {
      Brain.Screen.print("Manager pressed LEFT");
    } else if (lastPress == 2) {
      Brain.Screen.print("Manager pressed RIGHT");
    } else {
      Brain.Screen.print("Waiting...");
    }

    wait(0.1, seconds);
  }
}

이전

VEX링크

다음

직렬 링크

On this page
  • 소개
  • 클래스 생성자
  • 클래스 소멸자
  • 매개변수
  • 예
  • 회원 기능
    • isLinked
    • 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)