Modpoll is a command line-based Modbus master simulator and test utility utilizing the FieldTalk™ Modbus driver.
To check Modbus connection using modpoll:
cd modpoll
cd x86_64-linux-gnu/
./modpoll -t 1 -a 50 -c 2 -r 4 -m tcp 192.168.110.128
Parameter explanations:
· -t 1: Discrete input data type
· -a #: Slave address (1-255 for serial, 0-255 for TCP, default is 1)
· -c #: Number of values to read (1-125, default is 1), optional for write
· -r #: Start reference (1-65536, default is 1)
· -m tcp: MODBUS/TCP protocol (default otherwise)
For more information: Modpoll
If you are using Moxa, the configuration page includes:
· Default username: admin
·
Password: moxa
.
Modbus
Communication Guidelines and Example Using Modpoll
1. Overview:
In Modbus communication using Modpoll, the following details are crucial for users to understand and configure their systems.
2. Essential Information:
Host Information:
· The device's host information is required for Modbus communication, utilizing the default port 502.
· Ensure you have the device's IP address for communication.
Security Credentials:
· If applicable, gather the username and password for authentication.
Slave ID:
· Identify the slave ID of the target device.
Timeout Considerations:
· Set the timeout duration based on the device's response speed.
First Register Index:
· Determine whether the device's register addresses start from 0 or 1.
· If the first register is 0, set the index as 0; if it is 1, set the index as 1.
Health Check Register Index:
· Choose a meaningful register address to serve as a health check for connection status.
3. Modbus Function Codes:
Function 03 (03hex) Read Holding Registers:
Request: Specify the starting register and quantity of registers to read.
Example Request (Slave 1, Registers 40001 to 40002):
Header :(Colon)
Slave Addr :01
Function :03
Start
Addr :0000
Quantity :0002
Checksum :C40B
Trailer :CRLF
Example Response
Header :(Colon)
Slave Addr :01
Function :03
Byte Count :04
Data Hi :0006
Data Lo :0005
Checksum :DA31
Function 04 (04hex) Read Input Registers:
Request: Specify the starting register and quantity of registers to read.
Example Request (Slave 1, Registers 30001 to 30002):
Header :(Colon)
Slave Addr :01
Function :04
Start
Addr :0000
Quantity :0002
Checksum :71CB
Trailer :CRLF
Example Response:
Header :(Colon)
Slave Addr :01
Function :04
Byte Count :04
Data
Hi :0006
Data
Lo :0005
Checksum :DB86
Trailer :CRLF
Function 01 (01hex) Read Coils:
Request: Specify the starting coil and quantity of coils to read.
Example Request (Slave 4, Coils 11 to 23):
Header :(Colon)
Slave Addr :04
Function :01
Start
Addr :000A
Quantity :000D
Checksum :DD98
Trailer :CRLF
Example Response:
Header :(Colon)
Slave Addr :04
Function :01
Byte Count :02
Data(Coils18...11):0A
Data(Coils23...19):11
Checksum :B350
Trailer :CRLF
Function 02 (02hex) Read Discrete Inputs:
Request: Specify the starting input and quantity of inputs to read.
Example Request (Slave 4, Inputs 10011 to 10023):
Header :(Colon)
Slave Addr :04
Function :02
Start
Addr :000A
Quantity :000D
Checksum :9998
Trailer :CRLF
Example Response:
Header :(Colon)
Slave Addr :04
Function :02
Byte Count :02
Data(Inputs18...11):0A
Data(Inputs23...19):11
Checksum :B314
Trailer :CRLF
4. Additional Notes:
Modbus Exception Codes
In Modbus communication, exception codes are used to indicate errors or exceptional conditions that may occur during data exchange between the master and slave devices. Below are common Modbus exception codes, along with their meanings:
Exception Code 01 (01 hex): Illegal Function
Meaning: The function code received in the query is not allowable for the slave. It could be due to incompatibility with the device or the slave being in the wrong state to process the request.
Exception Code 02 (02 hex): Illegal Data Address
Meaning: The data address received in the query is not a valid address for the slave. This may result from an invalid combination of reference number and transfer length.
Exception Code 03 (03 hex): Illegal Data Value
Meaning: A value in the query data field is not acceptable for the slave. This indicates a fault in the structure of a complex request, such as an incorrect implied length.
Exception Code 04 (04 hex): Slave Device Failure
Meaning: An unrecoverable error occurred while the slave was attempting to perform the requested action.
Exception Code 05 (05 hex): Acknowledge
Meaning: The slave has accepted the request and is processing it, but a long duration is required. This is to prevent a timeout error in the master, and the master can issue a Poll Program Complete message to check if processing is completed.
Exception Code 06 (06 hex): Slave Device Busy
Meaning: The slave is engaged in processing a long-duration program command. The master should retransmit the message later when the slave is free.
Exception Code 07 (07 hex): Negative Acknowledge
Meaning: The slave cannot perform the program function received in the query. It is returned for an unsuccessful programming request using function code 13 or 14. The master should request diagnostic or error information from the slave.
Exception Code 08 (08 hex): Memory Parity Error
Meaning: Used in conjunction with function codes 20 and 21, and reference type 6. Indicates that the extended file area failed to pass a consistency check. The master can retry the request, but service may be required on the slave device.
Exception Code 10 (0A hex): Gateway Path Unavailable
Meaning: Used in conjunction with gateways, indicates that the gateway was unable to allocate an internal communication path for processing the request. Typically, this implies misconfiguration or overload.
Exception Code 11 (0B hex): Gateway Target Device Failed to Respond
Meaning: Used in conjunction with gateways, indicates that no response was obtained from the target device. Usually means that the device is not present on the network.
These exception codes help in understanding and diagnosing errors that may occur during Modbus communication.