User Tools

Site Tools


en-us_commands:reference:imcinit

This is an old revision of the document!


IMcInit()

IMcInit() sets the communication port, station number and baud rate.

IMcInit command operation flow

void IMcInit(HardwareSerial& serialPort, uint8_t stationNo, long baudrate)

Commands

Command Arguments Return Value Operation
IMcInit(serialPort, stationNo, baudrate) HardwareSerial& serialPort — Communication Serial port
uint8_t stationNo — Station number
long baudrate — Baud rate
void Sets the communication port, station number and baud rate.

Example

void setup() {
  IMcMem(32, 32, 64, 64);  // Set the X·Y·M·D memory sizes used by MC Protocol.
  IMcAdr(0, 0, 0, 0);  // Set the start addresses of X·Y·M·D memory.
  IMcInit(Serial2, 1, 9600);  // Set the communication port, station number and baud rate.
}
 
void loop() {
  IMcProtocol();  // Check incoming requests and process MC Protocol responses.
  if (X != nullptr) X[0] = IdigitalRead(0, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state.
  if (Y != nullptr) digitalWrite(32, Y[0] ? HIGH : LOW);
}

Precautions

  • Keep calling IMcProtocol() in loop().
  • Do not confuse hexadecimal addressing for X/Y with decimal addressing for M/D.
  • Do not use X/Y/M/D before allocating the pointers.
  • If Cnet or Modbus reallocates shared M/D memory at runtime, the addresses used by MC Protocol change. Complete all memory size settings in setup() and do not call them again at runtime.
  • Allocation functions do not return success status. For nonzero sizes, verify the corresponding global pointer is not nullptr before accessing it.

Built-in Commands in the Same Category

en-us_commands/reference/imcinit.1788796399.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki