Author Topic: Using PLC as MODBUS or RTU master.  (Read 48487 times)

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Using PLC as MODBUS or RTU master.
« on: July 14, 2003, 08:47:26 AM »
The M-series PLCs have built-in READMODBUS, WRITEMODBUS, READMB2, WRITEMB2 ?commands which allow the PLC to act as a MODBUS master and interface to third party MODBUS or RTU slaves. These commands use the MODBUS function 03 for reading and funciton 16 for writing to the slaves. Function 03 and 16 are considered MODBUS level 1 functions and are the most fundamental MODBUS functions that all MODBUS slave devices must implement.

However, if your device requires other function (such as 04 to read Modicon input register 3xxxxx, etc), then you will not be able to use the abovementioned built-in commands.

Fortunately, the amazing flexibility of the M-series programming language allows you to implement your own Modbus RTU master by using INCOMM, OUTCOMM and CRC16 commands (for PLC with firmware revision r44 and above only). ?You can also implement your own MODBUS ASCII master by using the PRINT n and INPUT$(n) commands.

We have posted a sample program that you can download from the following link:
 
http://www.tri-plc.com/trilogi/modbusFunction04.zip
 
This sample implements the RTU function 04 and is tested to work with a slave T100MD888+.
« Last Edit: December 06, 2004, 09:03:27 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
MODBUS Function 04
« Reply #1 on: September 04, 2005, 12:08:28 PM »
The default MODBUS read is always to use MODBUS function 03 to maintain a LEVEL1 MODBUS compatibility mode according MODBUS.ORG. In the previous post we mentioned how to use TBASIC to create your own MODBUS command using function 04.

However, M-series PLC with firmware version r49 is now able to use MODBUS function 04 instead of 03 when running the READMODBUS or READMB2 function:

1) SETSYSTEM 6,4 will force the READMODBUS and READMB2
   to use function 04 instead of default 03.

2) SETSYSTEM 6,3 will force the READMODBUS and READMB2
   to use function 03.

Note: The command was previously posted wrongly as SETSYSTEM 5, x which is wrong and won't work.  We apologize for any inconvenience caused.


« Last Edit: May 04, 2006, 06:01:16 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Using PLC as MODBUS or RTU master.
« Reply #2 on: July 17, 2009, 02:15:21 PM »
As mentioned in the previous posts, the built-in READMODBUS, WRITEMODBUS, READMB2, WRITEMB2 commands use Modbus Function 03 and 16 only (04 can be used in place of 03 with a SETSYSEM command). Function 03 and 16 are Level 1 functions and all Modbus compliant devices are supposed to support them.

However, we are aware that there are some Modbus slave devices that do not support these two level 1 functions, but instead support other Modbus functions such as 01, 02, 05 and 06.

Although TBASIC does not have built-in commands to directly handle these other Modbus protocol, it is possible to use TBASIC language to construct the binary data that comform to Modbus RTU protocol and send them out to the slave, and receive response data from the Modbus slave and interpret them. These require some sophistication in programming skill but is readily achievable. We are providing examples of  Modbus function 01,02,04,05 and 06 handlers which can be downloaded from the following link:

http://www.tri-plc.com/trilogi/TBASICModbus.zip
« Last Edit: July 17, 2009, 02:19:07 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Using PLC as MODBUS or RTU master.
« Reply #3 on: October 23, 2012, 12:03:40 PM »
For Nano-10, FMD or F-series with firmware >= r74, the WRITEMODBUS command can be configured to use Modbus function 06 for writing instead of the default function 16. This is achieved by running the following command:

   SETSYSTEM 6,6    ' after this statement WRITEMODBUS uses function 06.
     
Note:

1)   SETSYSTEM 6,4   ' after this statement READMODBUS and READMB2 uses function 04
                                 'as explained in previous post.

2) SETSYTEM 6,n where n <>4 && n <> 6 ==> default in action (function 03 for read  and function 16 for write).
« Last Edit: October 23, 2012, 12:04:25 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Using PLC as MODBUS or RTU master.
« Reply #4 on: April 16, 2015, 10:20:44 AM »
To recap, the current generation of Nano-10, FMD88-10 and FMD1616-10 can send only the following Modbus functions via the READMODBUS and WRITEMODBUS commands:  03, 04, 06, 16.  To use the other functions please use the TBASIC emulated method mentioned in the previous post.

However, the new generation of SmartTILE-Fx based PLCs:  Fx1616-BA, Fx2424, EZWire1616 now do support all the following  Modbus function as a Modbus RTU or Modbus TCP master:  Modbus 01,02, 03, 04, 05, 06, 16. In order to switch function type please run  the command "SETSYSTEM 6, n  ' where n is the function number"  before running the READMODBUS, READMB2, WRITEMODBUS or WRITEMB2 commands.

The following table summarizes the additional features on the Fx and note that Modbus support section. This table is obtained from Chapter 1.1 of the Fx PLC User's Manual.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS