Difference between revisions of "RS485 Modbus Relay"

From Diustou Wiki
Line 82: Line 82:
 
=== Introduction to Modbus RTU Commands ===
 
=== Introduction to Modbus RTU Commands ===
 
*Modbus devices execute relevant operations by receiving Modbus RTU commands from external control terminals (such as host computers/MCUs). A frame of commands generally consists of the device address, function code, register address, register data, and checksum. The frame length is related to the function code. Typically, the first byte of each frame of data is the device address, with a settable range of 1-255 and a default of 255 (i.e., 0xFF). The last two bytes are the CRC checksum.
 
*Modbus devices execute relevant operations by receiving Modbus RTU commands from external control terminals (such as host computers/MCUs). A frame of commands generally consists of the device address, function code, register address, register data, and checksum. The frame length is related to the function code. Typically, the first byte of each frame of data is the device address, with a settable range of 1-255 and a default of 255 (i.e., 0xFF). The last two bytes are the CRC checksum.
*Assuming the device address is 255, the commonly used Modbus RTU commands are as follows. For details, please refer to [[:File:RS485 Modbus Relay_模块说明.zip|Module User Manual]].
+
*Assuming the device address is 255, the commonly used Modbus RTU commands are as follows. For details, please refer to [https://wiki.diustou.com/cn/%E6%96%87%E4%BB%B6:RS485_Modbus_Relay_%E6%A8%A1%E5%9D%97%E8%AF%B4%E6%98%8E.zip Module User Manual].
  
 
*'''Turn On Relay 1'''
 
*'''Turn On Relay 1'''

Revision as of 12:04, 10 January 2025

RS485 Modbus Relay
RS485 Modbus Relay 示意图.png

RS485 Modbus Relay (1, Opto)


RS485 Modbus Relay 示意图1.png RS485 Modbus Relay (2, Opto)


RS485 Modbus Relay 示意图2.png RS485 Modbus Relay (3, Opto)


RS485 Modbus Relay 示意图3.png RS485 Modbus Relay (4, Opto)

Information

Categories: Relay

Brand: Diustou

Description
Features
  • RS485 Modbus Relay

Interfaces

RS485

Related products

Product Overview

  • A relay is an electrical control device that causes a controlled quantity within an electrical output circuit to undergo a predetermined step change when the variation of the input quantity (excitation quantity) meets specified requirements. It establishes an interactive relationship between the control system (also known as the input circuit) and the controlled system (also known as the output circuit). Typically used in automated control circuits, it essentially functions as an "automatic switch" where a small current controls the operation of a larger current. Therefore, in circuits, it plays roles such as automatic regulation, safety protection, and circuit conversion.
  • The RS485 Modbus Relay Module is equipped with a mature and stable 8-bit MCU and RS485 level communication chip. It adopts the standard MODBUS RTU format RS485 communication protocol, capable of achieving 2/3/4-channel input signal detection and 2/3/4-channel relay output. This makes it suitable for applications requiring digital signal detection or power control.

Product Features

  • Equipped with a mature and stable 8-bit MCU and SP3485 level conversion chip.
  • Power Supply Voltage: 5V - 32V.
  • Communication Protocol: Supports the standard Modbus RTU protocol.
  • Communication Interface: Supports the RS485 interface.
  • Communication Baud Rate: 4800/9600/19200 bps, default 9600 bps, supports power-loss retention.
  • Output Signal: Relay switch signal.
  • Device Address: Range from 1 to 255, default 255, supports power-loss retention.
  • Baud rate, input signals, relay status, and device address can be read using software/instructions.
  • Equipped with 2/3/4 channels of 5V, 10A/250VAC, 10A/30VDC relays, capable of continuous operation up to 100,000 cycles, featuring diode flyback protection, optocoupler protection circuitry, and fast response time.
  • Equipped with relay switch indicator lights and power indicator lights.

Product Description

  • RS485 Modbus Relay 产品说明.png
  • 1. VCC, GND: DC5-32V 5.08mm power input terminal
  • 2. A+, B-, GND: RS485 communication interface, A+ and B- are connected to the A+ and B- of the external control terminal respectively, GND can be left unconnected
  • 3. Relay 2 switch signal output:
    • NC2: Normally closed terminal, short-circuited to COM before the relay is energized, and open after the relay is energized;
    • COM2: Common terminal;
    • NO2: Normally open terminal, open before the relay is energized, and short-circuited to COM after the relay is energized.
  • 4. Relay 1 switch signal output:
    • NC1: Normally closed terminal, short-circuited to COM before the relay is energized, and open after the relay is energized;
    • COM1: Common terminal;
    • NO1: Normally open terminal, open before the relay is energized, and short-circuited to COM after the relay is energized.
  • 5. Relay indicator light: Lights up when the relay is energized
  • 6. Optocoupler protection circuit

User Instructions

Host Computer Testing

  • Connecting the Serial Port
    • Connect the relay module to the USB-to-485 module with the connection: A - A, B - B. GND can be left unconnected.
    • Open the host computer software.
      • RS485 Modbus Relay 上位机测试1.png
      • Refresh the serial port.
      • Select the corresponding serial port.
      • Select baud rate 9600.
      • Open the serial port.
  • Setting the Communication ID
    • If there is only one module on the 485 bus, you can click the "Read ID" button to automatically read the module's ID and display it in the ID text box (in hexadecimal format). You can also set the module's ID to the value in the ID text box (in hexadecimal format) by clicking the "Set ID" button. The set module ID will be saved in the module and retained even after power-off.
      • RS485 Modbus Relay 上位机测试2.png
    • If there is more than one module on the 485 bus, you cannot use the above method to read or set the ID. You must manually enter the ID of the module you wish to communicate with into the ID text box (in hexadecimal format) to operate the corresponding module. If the ID is set to 0, it is in broadcast mode, and all modules on the bus will receive the same command and perform the same action, but there may be conflicts in the response commands, leading to unexpected results.
      • RS485 Modbus Relay 上位机测试3.png
  • Operating the Relay
    • You can operate the relay on the corresponding channel or turn all relays on/off simultaneously using the relay control buttons. The output status indicator for the corresponding channel will update accordingly upon receiving a response from the module.
      • RS485 Modbus Relay 上位机测试4.png
  • Debugging Function
    • The debugging area displays the command data (in hexadecimal format) currently being sent and received by the serial port. Click the "Send Directly" button to send the data in the "Send Data" text box via the serial port. Click the "Calculate CRC" button to automatically calculate the CRC for all data in the "Send Data" text box and append the result to the end, facilitating Modbus command debugging. Note: Since the sent command already includes the CRC, if you manually modify the command to be sent, you need to delete the last two bytes before clicking the "Calculate CRC" button.
      • RS485 Modbus Relay 上位机测试5.png

Introduction to Modbus RTU Commands

  • Modbus devices execute relevant operations by receiving Modbus RTU commands from external control terminals (such as host computers/MCUs). A frame of commands generally consists of the device address, function code, register address, register data, and checksum. The frame length is related to the function code. Typically, the first byte of each frame of data is the device address, with a settable range of 1-255 and a default of 255 (i.e., 0xFF). The last two bytes are the CRC checksum.
  • Assuming the device address is 255, the commonly used Modbus RTU commands are as follows. For details, please refer to Module User Manual.
  • Turn On Relay 1
Send: 	FF 05 00 00 FF 00 99 E4 
Return: FF 05 00 00 FF 00 99 E4 

Note 1: The 3rd and 4th bytes of the sent frame represent the relay address. The addresses for relays 1 to 8 are 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, and 0x0007, respectively.

Note 2: The 5th and 6th bytes of the sent frame represent the data. 0xFF00 represents turning on the relay, and 0x0000 represents turning off the relay.

  • Turn Off Relay 1
 
Send: 	FF 05 00 00 00 00 D8 14
Return: FF 05 00 00 00 00 D8 14 
  • Turn On All Relays
 
Send: 	FF 0F 00 00 00 08 01 FF 30 1D 
Return: FF 0F 00 00 00 08 41 D3 
  • Turn Off All Relays
Send:	 FF 0F 00 00 00 08 01 00 70 5D 
Return:	 FF 0F 00 00 00 08 41 D3 
  • Set Device Address to 255
Send: 	00 10 00 00 00 01 02 00 FF EB 80 
Return:	00 10 00 00 00 01 02 00 FF EB 80 

Note: The 8th and 9th bytes of the sent frame, 0x00FF, represent the device address to be written.

  • Read Device Address 255
 
Send: 	00 03 00 00 00 01 85 DB 
Return: 00 03 02 00 FF C5 C4
 

Note: The 4th and 5th bytes of the response frame, 0x00FF, represent the read device address.

  • Set Baud Rate to 9600
 
Send:	FF 10 03 E9 00 01 02 00 03 8B CC 
Return: FF 10 03 E9 00 01 C5 A7
 
  • Read Relay Status
 
Send: 	FF 01 00 00 00 08 28 12
Return: FF 01 01 01 A1 A0 

Generating Checksum

When sending module commands through ready-made host software, the CRC checksum is automatically generated. If you want to test the Modbus relay module using a serial port debugging software (such as SSCOM), you need to manually generate the CRC checksum and append it to the end of the transmission frame. For example, to open the first relay (manual mode):

  • The transmission frame for opening/closing the relay (manual mode) consists of: Device address (1Byte) + Function code (1Byte) + Register address (2Byte) + Register data (2Byte) + CRC checksum (2Byte)
  • Assuming the device address is 0xFF, the first 6 bytes of the transmission frame would be: FF 05 00 00 FF 00
  • Use a CRC checksum tool to calculate the checksum for these 6 bytes: http://www.ip33.com/crc.html

Modbus RTU Relay 校验码.png

  • Swap the high and low bytes of the calculated checksum result E499 to obtain the CRC checksum 99E4, and the complete transmission frame: FF 05 00 00 FF 00 99 E4
  • Send this transmission frame to the Modbus relay module through the serial port debugging software SSCOM V5.13.1 to open the first relay (manual mode), as shown below:

Modbus RTU Relay 校验码1.png

References

Precautions

  • Please use the power supply and load within the specified parameters and avoid exceeding them.
  • The rated load and lifespan are reference values and may vary significantly depending on different environmental factors, load properties, and types. Therefore, it is best to confirm them in actual or simulated actual use.
  • The module's load capacity is significantly affected by ambient temperature and its own temperature rise. It needs to be installed in an environment with good air convection for heat dissipation.
  • Electrical endurance at high temperatures: When the module is used at high temperatures, its electrical endurance will be lower than at normal temperatures. Therefore, please confirm this in actual use.