ModTest Manual - Commands

Commands

ModTest enables you to define a Modbus command, send the command to the Modbus slave, and then save the command together with the result. The saved result may be a normal response, an error response, or a failure of the slave to respond.

Later, you can send the command again (possibly to a different slave), and ModTest will automatically compare the result with the previous result. If the results are different, ModTest will report the difference as a test failure.

You can save a sequence of commands and results as a "test suite", and execute the whole sequence automatically. Any failures (i.e. differences between expected and actual results) will be reported.

The commands that you define may be standard Modbus commands, custom commands, or arbitrary data. This makes it easy to test the error handling of the Modbus slave.

Defining commands

Introduction

You can use the Define Command panel (Figure 5, “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. If you have sent the command to the slave, the result will be saved with the command. All saved command definitions are listed in the Commands panel.

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

There are three 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.

  • Standard commands. These are standard Modbus commands, which are described in the Standard commands section below.

Standard commands

The panel shown in Figure 5, “Define Command panel” is typical of the panels for defining standard commands.

The following fields are common to several of the panels:

  • Slave ID. You may enter a slave identifier that is different from the default 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.

  • 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.

  • Received Data: Check. Select Check if you want ModTest to compare the actual data received in the response from the slave with the expected data, and report an error if they are different. De-select Check if you want ModTest to ignore differences between the actual and received data, and only report an error if the outcomes are different.

Custom commands

The Custom Command panel (Figure 6, “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 default 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 7, “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 Commands table (Figure 8, “Commands panel”).

The Name and Command Type columns show the name you gave the command and the command type. The Result column shows whether the command test succeeded. Test failures are highlighted in red. To see further details of a command, select the command and then select the Edit Command panel.

Sending commands

You can send the defined commands by clicking the Test button (click the Test 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.

The Result column will be updated as each command is sent to indicate whether the command test succeeded.

To view the detailed result of a command, select the command in the table and then select the Test Command panel. You can also use the Test Command panel to send individual commands.

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 9, “Edit Command panel”).

Use the Command drop-down list to select the command to be edited and change the values as required. Click the Send button to update the result of the command (if required). Then 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.

Testing commands

The Test Command panel (Figure 10, “Test Command panel”) enables you to send individual defined commands to the slave and check its response. You can also use this panel to view the results of commands that were sent using the Commands panel.

Use the Command drop-down list to select the command that you want to send or view, and click the Send button if want to send the command.

The expected and actual result of the command will be displayed in the panel. The "expected" results and outcome are those that were saved when you defined (or last edited) the command. The "actual" results and outcome are from the last time that you sent the command to the slave. Any differences between the expected and actual results/outcome are highlighted in red.

If you decide that the actual results are correct and the expected results are wrong, you can save the actual results by selecting the Edit Command panel and clicking the Apply button.