• 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
  • 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

    • 보내다

    • 받다

    • 받았다

소개#

serial_link 클래스는 로봇 간에 원시 바이트 스트림을 전송할 수 있도록 합니다. 이 클래스는 송신 로봇과 수신 로봇 모두 데이터 스트림의 내용을 이해하는 로봇 간 통신을 위해 설계되었습니다.

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

중요: 두 로봇 모두 동시에 serial_link 하는 프로젝트를 실행해야 합니다. 그렇지 않으면 데이터 송수신이 이루어지지 않습니다.

클래스 생성자#

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

클래스 소멸자#

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

~serial_link();

매개변수#

매개변수

유형

설명

index

int32_t

메시지 링크가 연결된 스마트 포트는 PORTx형식으로 표기되며, 여기서 x 포트 번호입니다(예: PORT1).

name

const char*

이 링크의 이름입니다. 이 고유한 문자열은 Vexos에서 해시될 때 고유 ID가 생성될 수 있도록 충분히 길어야 합니다. “vexlink”와 같이 일반적인 이름은 다른 팀에서 이미 사용하고 있을 수 있으므로 좋지 않습니다.

type

linkType

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

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

isWired

bool

serial_link 객체가 유선인지 여부(기본값: false:

  • true — serial_link 객체가 유선입니다
  • false — serial_link 객체가 무선입니다

메모#

  • VEXlink는 무선 및 유선 통신을 모두 지원하며, 유선 연결 시에는 전원 배선 문제를 방지하기 위해 특수 개조된 스마트 케이블을 사용하는 것이 좋습니다.

  • 무선 통신을 위해서는 각 로봇에 스마트 포트에 연결된 V5 로봇 라디오가 필요합니다.

  • VEXlink 라디오는 EXP 컨트롤러의 VEXnet 라디오와 함께 사용할 수 있으며, 충돌을 방지하기 위해 가장 높은 번호의 스마트 포트에 연결해야 합니다.

  • VEXlink를 생성하려면 두 개의 EXP 브레인을 V5 로봇 라디오에 연결해야 합니다.

예#

로봇 1용 코드

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

로봇 2용 코드

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

회원 기능#

serial_link 클래스에는 다음과 같은 멤버 함수가 포함됩니다.

  • isLinked — EXP Brain이 이 링크에서 페어링되고 통신하는지 확인합니다.

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

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

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

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

로봇 1용 코드

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

로봇 2용 코드

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

isLinked#

직렬 링크에 있는 EXP Brain이 서로 페어링되었는지 여부를 반환합니다.

Available Functions
bool isLinked();

Parameters

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

Return Values

EXP 브레인이 연결되어 있는지 여부를 나타내는 부울 값을 반환합니다.

  • true — The two EXP Brains are paired and communicating on this link.
  • false — The two EXP Brains are not paired on this link.
Notes
  • 프로젝트를 시작할 때 추가 코드를 실행하기 전에 EXP Brains가 제대로 연결되었는지 항상 확인하는 것이 좋습니다.

Examples

로봇 1용 코드

// Create the link
  serial_link 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");
  Brain.Screen.newLine();
  Brain.Screen.print("Sending message...");

  // Message to send
  const char* message = "Hello Robot 2";

  // Send the message
  link.send((uint8_t*)message, strlen(message));

로봇 2용 코드

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

  // Do not run code UNTIL the Brains are linked
  while (!link.isLinked()) {
    wait(0.1, seconds);
  }
  
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Buffer to store incoming bytes
  uint8_t buffer[32] = {0};

  int32_t n = link.receive(buffer, sizeof(buffer) - 1);

  // Null-terminate
  if (n > 0) {
    buffer[n] = 0;

    // Display the message that was sent
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Robot 2 - Worker");
    Brain.Screen.newLine();
    Brain.Screen.print((char*)buffer);
  }
  else {
    Brain.Screen.newLine();
    Brain.Screen.print("No message received");
  }

send#

짝을 이룬 브레인에게 메시지를 보냅니다.

Available Functions

1 — 바이트 버퍼를 사용하여 메시지를 보냅니다.

int32_t send( 
  uint8_t *buffer, 
  int32_t  length );

2 — 문자 버퍼를 사용하여 메시지를 보냅니다.

int32_t send( 
  const char *buffer, 
  int32_t     length );

Parameters

매개변수

유형

설명

buffer

uint8_t* or const char*

연결된 다른 EXP 브레인으로 보낼 버퍼입니다.

length

int32_t

전송할 버퍼의 길이입니다.

Return Values

전송된 바이트 수를 나타내는 int32_t 을 반환합니다.

Examples

로봇 1용 코드

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

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

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

  // Track last sent state
  uint8_t lastState = 255;  // impossible initial value

 // Tell Robot 2 when the screen is being pressed
  while (true) {
    uint8_t state = Brain.Screen.pressing() ? 1 : 0;

    // Only send if state changed
    if (state != lastState) {
      link.send(&state, 1);
      lastState = state;
    }

    wait(0.02, seconds);
  }

로봇 2용 코드

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

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

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Track the last state
  uint8_t lastShown = 255;

  while (true) {
    // Variable stores 1 - pressed, 0 - not pressed 
    uint8_t state = 0;
    int32_t n = link.receive(&state, 1, 200);

    // Only update screen if state changes
    if (n == 1 && state != lastShown) {
      Brain.Screen.clearScreen();
      Brain.Screen.setCursor(1, 1);
      Brain.Screen.print("Robot 2 - Worker");
      Brain.Screen.newLine();

      // Display text if Robot 1's screen is being pressed
      if (state == 1) {
        Brain.Screen.print("Manager IS being pressed!");
      } else {
        Brain.Screen.print("Manager is NOT being pressed");
      }

      lastShown = state;
    }
    wait(0.02, seconds);
  }

receive#

다음 수신 메시지를 기다렸다가 반환합니다.

Available Functions

1 — 선택적으로 타임아웃을 설정하여 문자 버퍼에 메시지를 수신합니다.

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

Parameters

매개변수

유형

설명

buffer

char*

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

length

int32_t

버퍼의 길이.

timeoutMs

int32_t

receive 수신하면 큐가 비어 있는 경우에만 새 메시지를 기다리는 시간(밀리초)입니다(기본값은 500ms).

Return Values

수신된 바이트 수를 나타내는 int32_t 을 반환합니다.

Notes
  • receive 수신하고, 다른 연결된 EXP 브레인에서 대기 중인 다음 메시지를 반환합니다.

  • 메시지는 FIFO 순서(가장 오래된 미읽음 메시지부터)로 읽힙니다.

  • receive 호출될 때 큐가 비어 있으면 지정된 timeoutMs 까지 새 메시지를 기다립니다.

  • 해당 시간 내에 메시지가 도착하지 않으면 receive 수신하고 0을 반환하며, 이후에 전송된 메시지는 receive 다음에 사용될 때 읽히도록 큐에 남아 있습니다.

Examples

로봇 1용 코드

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

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

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

  // Track last sent state
  uint8_t lastState = 255;  // impossible initial value

 // Tell Robot 2 when the screen is being pressed
  while (true) {
    uint8_t state = Brain.Screen.pressing() ? 1 : 0;

    // Only send if state changed
    if (state != lastState) {
      link.send(&state, 1);
      lastState = state;
    }

    wait(0.02, seconds);
  }

로봇 2용 코드

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

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

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");

  // Track the last state
  uint8_t lastShown = 255;

  while (true) {
    // Variable stores 1 - pressed, 0 - not pressed 
    uint8_t state = 0;
    int32_t n = link.receive(&state, 1, 200);

    // Only update screen if state changes
    if (n == 1 && state != lastShown) {
      Brain.Screen.clearScreen();
      Brain.Screen.setCursor(1, 1);
      Brain.Screen.print("Robot 2 - Worker");
      Brain.Screen.newLine();

      // Display text if Robot 1's screen is being pressed
      if (state == 1) {
        Brain.Screen.print("Manager IS being pressed!");
      } else {
        Brain.Screen.print("Manager is NOT being pressed");
      }

      lastShown = state;
    }
    wait(0.02, seconds);
  }

received#

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

Available Functions

1 — 수신된 모든 메시지에 대한 콜백 함수를 등록합니다.

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

2 — 추가적인 int32_t 필드를 포함하는 수신된 모든 메시지에 대해 호출되는 콜백을 등록합니다.

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 — 메시지 페이로드에 추가적인 int32_t 필드가 포함된, 이름이 message와 일치하는 수신 메시지에 대해서만 호출되는 콜백을 등록합니다.

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

Parameters

매개변수

유형

설명

message

const char*

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

callback

function

EXP 브레인이 message 과 일치하는 메시지를 수신할 때 실행되는 이전에 정의된 함수입니다.

Return Values

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

Notes
  • received 인수를 받아 호출되었습니다.

Callback Signature

callback(message, linkname, index, value)

논쟁

설명

message

수신된 메시지 이름(예: “add”).

linkname

메시지를 수신한 링크의 이름입니다.

index

메시지와 함께 전송된 정수 값(제공된 경우).

value

메시지와 함께 전송되는 부동 소수점 값(제공된 경우).

Examples

로봇 1용 코드

// Send left or right when pressed
void screen_pressed() {
  if (Brain.Screen.xPosition() < 240) {
    link.send((uint8_t*)"left", 4);
  } else {
    link.send((uint8_t*)"right", 5);
  }
}

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

// Create the link
serial_link 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");


  Brain.Screen.pressed(screen_pressed);
}

로봇 2용 코드

// Called when message received
void received_callback(uint8_t *buffer, int32_t length) {
  char msg[32];

  // Copy safely and null terminate
  int n = (length < 31) ? length : 31;
  memcpy(msg, buffer, n);
  msg[n] = '\0';

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();

  // Display if Robot 1's screen is pressed on left or right
  if (strcmp(msg, "left") == 0) {
    Brain.Screen.print("Manager pressed LEFT");
  }
  else if (strcmp(msg, "right") == 0) {
    Brain.Screen.print("Manager pressed RIGHT");
  }
}

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

// Create the link
serial_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(received_callback);

  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  Brain.Screen.print("Robot 2 - Worker");
  Brain.Screen.newLine();
  Brain.Screen.print("Waiting...");
}

이전

메시지 링크

다음

CTE 워크셀

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)