First, we will introduce our hardware preparations.
1. A weighing instrument that supports the Modbus protocol
Weighing instrument that supports the Modbus protocol
2. Set the communication parameters of the instrument
You can adjust according to your requirements, as long as it matches the PLC side.
Baud rate: 9600
Data format: 8n1: 8 data bits / no parity bit
Communication method: Modbus protocol
Checksum: OFF
Instrument communication address: 1
3. Determine the variable address to be read
Here we only need to read the current real-time weight of the instrument.
The address for the real-time weight of the instrument is 0, corresponding to 40001 in Modbus communication.
4. One S7-200 SMART PLC
S7-200 SMART PLC
5. Connection ports
Connect the RS485 interface A and B of the instrument to the DB9 interface of the PLC (DB9 interface 3 is A, 8 is B).
I remember that 3 is A and 8 is B, not sure why this image shows otherwise, but it doesn’t matter; if different, just swap the two wires.
Preparation is complete, now we will start our PLC programming. Since the 200 SMART software already includes the Modbus protocol library, we do not need to add it separately. Below is an introduction to how to program.
6. Initialize the master station command
The value input for “Mode” is used to select the communication protocol. When the input value is 1, the CPU port is assigned to the Modbus protocol and the protocol is enabled.
The parameter “Parity” should be set to match the parity of the Modbus slave device. 0 (no parity).
The parameter “Port” sets the physical communication port (0 = integrated RS-485 in the CPU).
The parameter “Timeout” is set to the number of milliseconds to wait for the slave to respond. A typical value is 1000 ms (1 s).
When the MBUS_CTRL command is completed, it returns “TRUE” to the “Done” output.
The “Error” output contains the result of the command execution.
The above parameter settings correspond to those on the weighing instrument side.
7. Polling access for two instruments
The parameter “Slave” is the address of the Modbus slave device. The allowed range is 0 to 247. Address 0 is the broadcast address. Only use address 0 for write requests. The system will not respond to broadcast requests to address 0. Not all slave devices support the broadcast address. The S7-200 SMART Modbus slave library does not support the broadcast address.
Use the parameter RW to indicate whether to read or write the message. 0 (read).
The parameter address (Addr) is the starting Modbus address. The register address is 0, corresponding to address 40001 in Modbus communication.
The parameter “Count” is used to allocate the number of data elements to be read or written in that request. Read the number of holding registers in the instrument.
The parameter DataPtr is an indirect address pointer that points to the V memory in the CPU related to the read request. Set DataPtr to the first CPU storage unit for storing data read from the Modbus slave.
Data from instrument address 1 is stored in VW600, and data from address 2 is stored in VW610.
Programming is complete; now let’s look at the monitoring effect.
The master station initialization command runs normally, with no errors.
Data from address 1 is 131, and data from address 2 is 0.
This concludes our introduction to communication between the Siemens S7-200 SMART and weighing instruments via the MODBUS library.
Source: Internet, copyright belongs to the original author. If there is any infringement, please contact for deletion.
Check it out again. Everyone knows
Click“Read the original text“,to learn about electrical engineering, PLC, and other knowledge for free.