목차

ImodbusRTUmaster()

ImodbusRTUmaster()는 하나의 Master 요청을 즉시 실행합니다.

ImodbusRTUmaster 명령어 동작 흐름

uint8_t ImodbusRTUmaster(HardwareSerial& serialPort, uint8_t slaveId, uint8_t functionCode, uint16_t address, uint16_t quantity, uint16_t* data, uint16_t timeoutMs = 100)

명령어

명령어 인수 반환값 동작
ImodbusRTUmaster(serialPort, slaveId, functionCode, address, quantity, data, timeoutMs) HardwareSerial& serialPort — RS-485에 연결된 Serial
uint8_t slaveId — Slave 주소
uint8_t functionCode
uint16_t address
uint16_t quantity
uint16_t* data
uint16_t timeoutMs = 100
uint8_t 하나의 Master 요청을 즉시 실행합니다.

예제

uint16_t data[10];
uint16_t readValue0;
uint16_t readValue1;
 
void setup() {
  ImodbusRTUmasterInit(Serial2, 9600);  // Master 통신 포트와 보레이트를 설정합니다.
}
 
void loop() {
  uint8_t result;
 
  result = ImodbusRTUmaster(Serial2, 1, 0x03, 0, 2, data);  // 하나의 Master 요청을 즉시 실행합니다.
  if (result == IMODBUS_RTU_SUCCESS) {
    readValue0 = data[0];
    readValue1 = data[1];
  }
 
  data[0] = 1234;
  ImodbusRTUmaster(Serial2, 1, 0x06, 10, 1, data);  // 하나의 Master 요청을 즉시 실행합니다.
}

주의사항

같은 카테고리의 내장 명령어

← 내장 명령어 리스트