User Tools

Site Tools

Translations of this page:

Sidebar

MyCNC Shop

MyCNC website

myCNC Price List

plc:plc_modbus_api

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:
0x801=8,N,1
0x712=7,O,2
0x822=8,E,2
60019 Register Value. Writing to register will latch the value in shadow register. Value from shadow register will be used
60030 Write Register. Writing to register will send value from shadow register to Modbus devive to address given in written value on write operation
60020 Read Register Address. Writing to register will latch Address to read in shadow register
60031 Read. 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

PLC code example

main()
{
  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
 
  exit(99);
};

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.

Important!
If Modbus device controlled directly from PLC procedure, "RS485/Modbus communication" 
checkbox should be UNCHECKED in "Cfg->Technology->Spindle" configuration dialog 

plc/plc_modbus_api.txt · Last modified: 2017/11/05 17:28 by skirillov

Translations of this page: