Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Error handling while reading Modbus TCP

meuzumcu
2017-06-09
2017-06-13
  • meuzumcu - 2017-06-09

    Hi..

    In my project I want to read registers from a modbus tcp slave device. In normal conditions everything is ok but I must handle an error bit while an reading or socket error at communication.
    For example when turn off the power of slave device, a communication error occurs. So how can understand the error of modbus tcp.

    Thanks already..

    IMG: Bild

     
  • teichhei - 2017-06-11

    If you have control over the slaves you could toggle a bit and increase a counter on the slave side and read that back, make sure it increases. But if there is a way to access the on board diagnostics from Codesys that would be nice.

    Sent from my SM-G935F using Tapatalk

     
  • TimvH

    TimvH - 2017-06-13

    Each modbus slave device has a property "byModbusError".
    In your case you can use e.g. the following code:

    Mb1State := Modbus_TCP_Slave.byModbusError;
    

    Mb1State is then of the following type:

    VAR
    Β  Β Mb1State: IoDrvModbusTCP.MB_ErrorCodes;
    END_VAR
    

    In the library "IoDrvModbusTCP" you can find this ENUM (in the Structs folder) to see the details.

     

Log in to post a comment.