Skip to content

Reading holding registers using SE RS485 with Modbus_RTU function blocks

Good afternoon

I am having issues getting my project set up to read holding registers on a modbus device connected directly to the SE RS485 module.

I connected the terminating resistors per the datasheet and connected 'A' to input 1 and 'B' to input 3.

The device acts as a slave.

I have used the ' MB_AXL_SE_RS485_Master_32' function block as well as the 'MB_RTU_FC3_71' function block (is this necessary to use both).

I am having trouble to connect the hardware to the function blocks and to actually read the registers. I have attached as many screenshots as possible.

Any help would be appreciated, I am lost at this point.

Thanks in advance

Dewan

Comments

  • Hi Dewan,

    Do you have a terminating resistor at both ends of the RS485 network? If the SE module is at one end of the network, there is information in the manual on how to set the terminating resistor on the SE module. You will also need a terminating resistor at the other end of the network.

    Are the comms settings (baud rate etc) the same on the SE module and on all the slaves in the network?

    Does each slave have a unique slave address?

    To answer your question - yes, you will need an instance of the Master FB, and also an FB instance for each Modbus function code (e.g. FC3) that you want to execute, so your screen shot looks OK.

    When you set xActivate on the Master FB, does xActive go TRUE? If not, xError will probably go TRUE, and there should be diagnostics information available in udtDiag.

    You will also need to set xActivate on the FC3 FB, otherwise xSendRequest will not work.

    When you set xSendRequest on FC3, you should get either xDone or xError in response. If xError, then there should be diagnostics information in the DiagCode variables. If xDone is set without xError, then the requested data should be in arrReadData.

    I hope this helps.

    ~ Martin.

  • Hi Martin

    Thank you for the quick response.

    To answer some of your questions:

    Do you have a terminating resistor at both ends of the RS485 network? If the SE module is at one end of the network, there is information in the manual on how to set the terminating resistor on the SE module. You will also need a terminating resistor at the other end of the network. - Yes, I have terminating resistors installed on both ends. At this point I only have the PLC and the single device that I am using for testing purposes.

    Are the comms settings (baud rate etc) the same on the SE module and on all the slaves in the network? - All the settings are checked and double checked. :-)

    Does each slave have a unique slave address? - Only the single device at this point with slave ID = 10. I am able to read the device using different software if the device is connected to my computer using a usb to rs485 converter.

     

    Thank you for the other advice you gave, I got it up and running.

     

    How do I access the diagnostics information that you mention? I have attached another screenshot of the working FB. In the screenshot you can see at the bottom that arrReadData remains at 16#0000 which I understand is just 0 in Hex, even while the polling takes place.

    The data coming out of the device should be in Hex format. How would I be able to view this raw data or even beter, convert it to decimal for each register that has been read.

     

    Thanks in advance Martin.

    Dewan

  • Hi Dewan,

    How do I access the diagnostics information that you mention?

    1. Attach a variable to all the FB outputs with "Diag" in the name.
    2. In Online mode, add all those varables to the Watch window.
    3. The documentation for the Modbus RTU FB library will help you to decode the values you see in those variables.

    In the screenshot you can see at the bottom that arrReadData remains at 16#0000 which I understand is just 0 in Hex, even while the polling takes place.

    The screen shot only shows elements 41 and 125 of that array in the Watch window ... and since iDataCount is only 13, I wouldn't expect to see any data in these array elements. What do you see in array elements 0, 1, 2, ... ?

    The screen shot also shows arrOutputData in the Watch window, but this will not give you any meaningful information in most cases (it contains low-level messages between the CPU and the SE module).

    The data coming out of the device should be in Hex format. How would I be able to view this raw data or even beter, convert it to decimal for each register that has been read.

    I'm not sure what you mean - the Watch window will always show the raw data in hex (this can't be changed) (this can be changed by right-clicking on the hex value in the Watch window, and selecting "Display"). In the code, you can use type conversion functions (e.g. TO_INT) to convert the WORD values in arrReadData to other data types (e.g. INT), if you want.

    Hope this helps.

    ~ Martin.

     

     

  • Hi Martin

    Thank you for the help. I managed to get it working. The only thing I was missing is that I didn't display the registers I needed in the WATCH window (like you said about 41 and 125). Those are empty registers.

    For anyone else finding this thread:

    iDataCount is the number of registers you want to read. I set mine to 13 since I wanted to read registers 126 to 139.

    Thank you for all the help Martin.

    Dewan

  • Hi,
    Good Morning,

    I have the some issue to read data from Modbus RTU Slave using AXL SE RS485.
    When I try to connect to the RS485 Slave, the MB_RTU_FC4_7 Function Block which is intended for read input registers
    is not active when I give TRUE signal to the xActivate (see picture below). I check all the parameters including the Baud rate, Slave ID, Parity, Data and stop bits match already.
    Do you have any experience on this topic?

  • Hi rizky,

    i think you used the wrong start address. Holding registeres beginn usually at 40000. You started at 1.

    Hope this will help you.
  • Hi Mehmet,

    Thanks for the reply.
    I tried also to change to start address but the problem is still the same.
Sign In or Register to comment.