ModMaster Manual - Commands

Commands

ModMaster provides several ways to send Modbus commands to a slave.

Some of these ways use the register definitions that you have added (see Registers) - these are referred to as "high level", and are described in the section High-level command sending.

Other ways of sending commands do not use the register definitions - these are referred to as "low level", and are described in the section Defining commands.

High-level command sending

"High-level" commands transfer values between the slave and the registers that you have defined.

Read & Write buttons

If you want to read from or write to a single defined register, you can select it in the main window by clicking on its address (see Register display) and then click the Read or Write button (or select the ActionRead or ActionWrite menu item).

Define Command panel

If you want to read from or write to a group of registers, you can use the ActionSend Command menu item. This will display the Define Command panel (Figure 12, “Define Command panel”).

Select High-level Read or High-level Write as the Command Type, select the address of the first register, enter the number of values you want to transfer in the Count field, and click the Send button.

See Defining commands for more information on using the Define Command panel.

Polling

If you want to read or write all the defined registers, you can use the Poll Once button (or the ActionPoll Once menu item). This causes ModMaster to make a pass through all the register definitions, writing to the slave those registers that have the write flag set, and reading the other registers. The pass is done in model address order (i.e. in the order that the registers are displayed in the register display area).

If you click the Poll button, or select the ActionPoll menu item, ModMaster will continually poll all registers when it is running. While ModMaster is continually polling, you may also request a poll manually (e.g you may have configured ModMaster to poll every 5 minutes, and you want to update the registers without waiting several minutes for the next automatic poll).

The Polling Settings control several aspects of how the polling is done.

Implementation

When using any of these high-level methods of sending Modbus commands, ModMaster will read values from the slave and display them in the register display area, or write the values displayed in the register display area to the slave.

ModMaster uses the address range of the register to choose which Modbus command to use, as shown in the following table:

Table 5. High-level command implementation
Address range Read command Write command
Holding register 3 Read Holding Registers 16 Write Multiple Registers
Input register 4 Read Input Registers -
Coil 1 Read Coils 15 Write Multiple Coils
Discrete input 2 Read Discrete Inputs -

If a register appears in more than one address range (i.e. is overlaid), then ModMaster will use the first (in the above table) address range that it appears in.

Defining commands

Introduction

You can use the Define Command panel (Figure 12, “Define Command panel”) to define and send Modbus commands.

Select the required type of command from the Command Type drop-down list, and enter/select values as necessary.

You can then click the Send button to send the command to the slave. The result of sending the command will be displayed in the panel.

If you want to save the command definition, enter a unique name for the command in the Name field and click the Add button. All saved command definitions are listed in the Commands panel.

The Reset button will restore the values to their last saved state.

There are four kinds of command types in the Command Type drop-down list:

  • Custom command. This option enables you to define and send non-standard Modbus commands, and is described in the Custom commands section below.

  • Send raw data. This option enables you to send arbitrary data to the slave, and is described in the Sending raw data section below.

  • High-level commands. These use the register definitions that you have added (see Registers), and are described in the section High-level command sending.

  • Low-level commands. These are standard Modbus commands that make no use of the registers you have defined. They are described in the Low-level commands section below.

Low-level commands

The Low-level commands in the Command Type drop-down list provide a low-level interface for sending Modbus commands to a slave. The panel shown in Figure 13, “Read Holding Registers panel” is typical.

These low-level command panels make no use of any register definitions you may have entered, nor do they use or affect the register display area. All transferred values are displayed in the panel itself.

The following fields are common to several of the panels:

  • Slave ID. You may enter a slave identifier that is different from the slave identifier configured in General settings. In particular, you may enter 0 for the slave identifier in order to send broadcast messages.

  • Address. Address of the first register to be transferred. You should enter message addresses into these panels - the Address mapping settings are not used.

  • Count. Enter the number of values to be transferred - for example, if you want to transfer five 32-bit floating-point values you should enter 5. Note that this count may be different from the number of registers and may also be different from the count that is actually sent in the Modbus message (the settings for 32/64-bit Value Settings are used to convert the count if necessary).

  • Type. The type (integer or floating-point) and size (1, 8, 16, 32 or 64 bit) of the value(s) to be transferred. You would normally use Integer 16-bit for holding registers and input registers, and Coil/Discrete-input (i.e. 1-bit integer) for coils and discrete inputs.

  • Radix. The radix to be used to display the value(s). The radix "10U" is used for unsigned decimal, and the radix "10" is used for signed decimal. The radix only affects the display of integer values; floating-point values are always displayed in signed decimal.

Custom commands

The Custom Command panel (Figure 14, “Custom Command panel”) enables you to define and send non-standard Modbus commands.

The following values must be entered:

  • Slave ID. You may enter a slave identifier that is different from the slave identifier configured in General settings. In particular, you may enter 0 for the slave identifier in order to send broadcast messages.

  • Function. Enter the Modbus function code for the command, in decimal.

  • Count. Enter the number of bytes of data that you want to send.

  • Send data. Enter the data bytes that you want to send, in hex.

If you want to enter all the data bytes as a group using copy-paste or drag-and-drop (e.g. from the trace window), you should paste/drop on to a grey cell in the table. The Count value will be set automatically if you enter the data this way.

The header/CRC/LRC will be added to the command as appropriate to the packet type (TCP/RTU/ASCII) that you have configured.

When you send the data to the slave, any data received in response from the slave will be displayed in the Received Data table. This data does not include the slave ID, function code and header/CRC/LRC bytes.

Sending raw data

The Send Raw Data panel (Figure 15, “Send Raw Data panel”) enables you to send arbitrary data to the slave. This is particularly useful for testing the error-handling capabilities of the slave.

The following values must be entered:

  • Count. Enter the number of bytes of data that you want to send.

  • Send data. Enter the data bytes that you want to send, in hex.

If you want to enter all the data bytes as a group using copy-paste or drag-and-drop (e.g. from the trace window), you should paste/drop on to a grey cell in the table. The Count value will be set automatically if you enter the data this way.

The data that you enter will be sent to the slave without adding any slave ID, function code or header/CRC/LRC bytes. If you want to send slave/function/header/CRC/LRC bytes, you will have to include these in the data that you enter.

When you send the data to the slave, any data received in response from the slave will be displayed in the Received Data table. This is also raw data, and will include any slave ID, function code or header/CRC/LRC bytes.

Command table

All the commands you have defined are listed in the EditCommands table (Figure 16, “Commands panel”).

The Name and Command Type columns show the name you gave the command and the command type. To see further details of a command, select the command and then select the Edit Command panel.

Sending commands

You can send a command to the slave by selecting it and then clicking the Send button. To view the results (if any) of the command, select the Edit Command panel.

You can send all the defined commands by clicking the Send All button (click the Send All button again if you want to stop the sending). The commands will be sent in the order that they are listed in the table - you can change the order if required. You can also insert a delay after sending each command, if you need to reduce the load on the slave.

To view the results (if any) of a command, select the command in the table and then select the Edit Command panel.

Deleting commands

To delete a command, select it and the click the Delete button.

To delete several commands, select them by clicking on them while holding down the control key, and then click the Delete button.

To delete all commands, click the Delete All button.

Re-ordering commands

To move a command in the table, select it and click the Move button. Then select the destination table row, and click the Move After button (to move the command to after the destination row) or the Move Before button (to move the command to before the destination row).

You can also move a contiguous block of commands by selecting them (hold down the control key while clicking on them), and then clicking the Move button.

While you are selecting the destination row (i.e. after you have clicked the Move button), the commands to be moved are highlighted in grey, and the destination row is highligted in blue.

Editing command definitions

You can edit a defined command using the Edit Command panel (Figure 17, “Edit Command panel”).

Use the Command drop-down list to select the command to be edited, change the values as required, and click Apply to save the changes.

To restore the values to their last saved state, click the Reset button.

You can make a copy of the command by clicking the Copy button. The copy of the command will be displayed in the Define Command panel, where you can modify it (if required), name it, and save it.

You can send the command to the slave (before or after saving it) by clicking the Send button.