Rpi Modbus TCP Slave Single Coil and Discrete Input read strange behaviour

ferrim
2020-11-02
2020-11-03
  • ferrim - 2020-11-02

    Hi all,
    as you can see in the image, I am using a Raspberry pi as a Modbus TCP Slave.
    I have a simple test application with 3 Coils (Start 1000), 3 Discrete Input (Start 2000), 3 Holding Registers (Start 3000) and 3 Input Registers (Start 4000).
    If I send a Read Coil (0x01) at address 1000 and read all the 3 coils together (QModMaster on the left) I get 3 zeros and this is ok.
    If I send a Read Coil at address 1000 and read only one coil, I get 0 and also this is ok.
    If I send a Read Coil at address 1001 and read only one coil, I get 1 and this is strange for me.
    If I send a Read Coil at address 1002 and read only one coil, I get 0 and this is ok.
    The same weird thing happens to me with Discrete Input.
    I try with a LOGO8 as Modbus TCP Slave and in this case I can read the single coil status correctly.
    I am using Codesys V3.5 SP16 Patch 2, IoDrvModbusTCPSlave V3.5.16.0, CODESYS Control for Raspberry Pi SL V3.5.16.20 with license.
    Please tell me what i'm doing wrong, thanks.

     
    πŸ‘
    1

    Last edit: ferrim 2020-11-02
    • Morberis

      Morberis - 2020-11-03

      Setup some more registers above and below the current registers. Maybe shifting everything up a few so that they still start at 1000, 2000, etc but you're only reading and writing 1003-1006 etc but you have on the slave registers 1000-1008 setup. Then try to write to all of them to make them 1. Check on the RPi which registers have been written to. My first guess is that something with offset registers despite being configured the same.

      I'm thinking that because when I look at modbus registers 1-9999 is for output coils and 10001-19999 is discrete inputs but I don't know how well 10000 would work.

      I know you did say 1,000 not 10,000 but 乁( ⁰͑ ΔΉΜ― ⁰͑ ) ㄏ

       

      Last edit: Morberis 2020-11-03
  • ferrim - 2020-11-03

    Thank you very much Morberis,
    tomorrow morning I will try to read and write other registers and I will try to understand if it's a shifting problem.
    Currently the registers are set as in the attached image but I noticed the same strange behavior also in the default setting.
    I hope the night brings advice...

     
    • Morberis

      Morberis - 2020-11-03

      I'm pretty sure it is an offset issue but hey maybe not. I am definately not an expert, I just read things and sometimes get to implement them. Below is a good qoute on why it might be like this. Basically Codesys is doing it in a way that is compliant with the protocol where some other systems might not. Also sometimes the info in a manual already includes an offset. So to test with new devices I always set up registers above and below what I think it should be.


      According to the MODBUS protocol, in response to a request for address 4xxxx, the master reads register xxxx-1 from the slave

       

      Last edit: Morberis 2020-11-03

Log in to post a comment.