User Tools

Site Tools

Translations of this page:


MyCNC Shop

MyCNC website

myCNC Price List


PLC/Modbus API

A number of Variables from Global Variable Array are mapped to Modbus interface. It's possible to setup Modbus device ID, communication parameters and speed, and access to device Modbus Registers by writing to this variables.

Mapped variables to access Modbus devices are listed below

Variable Address Description
60010 Device ID. Change Device ID
60011 ASCII/RTU Switch. Change Modbus mode.
"0" - Modbus/RTU
"1" - Modbus/ASCII
60012 Modbus bitrate. Writing to this register will change RS485/Modbus speed. Available speeds are
1200, 2400, 4800, 
9600, 19200, 38400, 
57600, 115200
60013 Communication parameters. Change UART connection parameters: number of bits (8 or 7), parity (none, odd, even), number of stop bits (1, 2). Data comes in 3 low nibbles. The lowest is stop bits, then parity, then number of bits. Example:
60019 Register Value. Writing to register will latch the value in shadow register. Value from shadow register will be used
60020 Read Register Address. Writing to register will latch Address to read in shadow register
60030 Write Register. Writing to register will send value from shadow register to Modbus devive to address given in written value on write operation
60031 Read Register. Read from this register will send read inquiry to Modbus device (PLC controller will be in Sleep till Register value received from Modbus device). Writing to this register will send ready inquiry to Modbus device. The value written is used as Register address to read
60035 Write multiple coils. Write multiple coils command indicates the 16-bit address of first coil to write, the number of coils to write, number of bytes of coil values to follow, and the coil values.
60037 Write single register. Write single register indicates address of the holding register and the new value of the register

PLC code example

  gvarset (60010,40);    //Set Device ID (40)
  gvarset (60011,1);     //Set Modbus ASCII
  gvarset (60012,9600);  //Set bitrate 9600bps
  gvarset (60013,0x801); //Set communication parameters 8,N,1
  gvarset (60019,12345); //Set Value to write (12345)
  gvarset (60030,0x1001);//Write the Value (12345) to Register #0x1001
  gvarset (60035, 0x081001);//Write the value (12345) to register #0x1001
  gvarset (60037,0x64);  //Send value to address 

Modbus Scheduler in myCNC has 4 messages queue. Up to 4 registers can be written immediately from PLC procedure. Modbus manager will send it one-by-one and will be waiting a reply from Modbus device after each message.

Modbus manager will repeat the message to device up to 4 times in case no reply in 250ms.

If Modbus device is controlled directly from the PLC procedure, "RS485/Modbus communication" 
checkbox should be UNCHECKED in Settings > Config > Technology > Mill/Lathe > Spindle configuration dialog 

plc/plc_modbus_api.txt · Last modified: 2019/07/18 15:28 by ivan

Translations of this page: