pymodbus read meter registers












1















I'm new to modbus but I have a small project to work on. I need to read some values from an energy meter. I wrote this from some examples found in the internet:



import logging
from pymodbus.client.sync import ModbusTcpClient as ModbusClient

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusClient('192.168.80.210')
client.connect()
rr = client.read_holding_registers(40012, 1)
print rr

client.close()


It seems to be connecting to the meter 'cause this is my output:



DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x9c 0x4c 0x0 0x1
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received))
DEBUG:pymodbus.framer.socket_framer:Processing:
DEBUG:pymodbus.transaction:Getting transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received)


I want to read from register 40012 to 40014 and this is Modbusdbus map I have:
Modbus map



I appreciate your help. Regards,










share|improve this question





























    1















    I'm new to modbus but I have a small project to work on. I need to read some values from an energy meter. I wrote this from some examples found in the internet:



    import logging
    from pymodbus.client.sync import ModbusTcpClient as ModbusClient

    logging.basicConfig()
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)

    client = ModbusClient('192.168.80.210')
    client.connect()
    rr = client.read_holding_registers(40012, 1)
    print rr

    client.close()


    It seems to be connecting to the meter 'cause this is my output:



    DEBUG:pymodbus.transaction:Current transaction state - IDLE
    DEBUG:pymodbus.transaction:Running transaction 1
    DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x9c 0x4c 0x0 0x1
    DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
    DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
    DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received))
    DEBUG:pymodbus.framer.socket_framer:Processing:
    DEBUG:pymodbus.transaction:Getting transaction 1
    DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
    Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received)


    I want to read from register 40012 to 40014 and this is Modbusdbus map I have:
    Modbus map



    I appreciate your help. Regards,










    share|improve this question



























      1












      1








      1


      1






      I'm new to modbus but I have a small project to work on. I need to read some values from an energy meter. I wrote this from some examples found in the internet:



      import logging
      from pymodbus.client.sync import ModbusTcpClient as ModbusClient

      logging.basicConfig()
      log = logging.getLogger()
      log.setLevel(logging.DEBUG)

      client = ModbusClient('192.168.80.210')
      client.connect()
      rr = client.read_holding_registers(40012, 1)
      print rr

      client.close()


      It seems to be connecting to the meter 'cause this is my output:



      DEBUG:pymodbus.transaction:Current transaction state - IDLE
      DEBUG:pymodbus.transaction:Running transaction 1
      DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x9c 0x4c 0x0 0x1
      DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
      DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
      DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received))
      DEBUG:pymodbus.framer.socket_framer:Processing:
      DEBUG:pymodbus.transaction:Getting transaction 1
      DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
      Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received)


      I want to read from register 40012 to 40014 and this is Modbusdbus map I have:
      Modbus map



      I appreciate your help. Regards,










      share|improve this question
















      I'm new to modbus but I have a small project to work on. I need to read some values from an energy meter. I wrote this from some examples found in the internet:



      import logging
      from pymodbus.client.sync import ModbusTcpClient as ModbusClient

      logging.basicConfig()
      log = logging.getLogger()
      log.setLevel(logging.DEBUG)

      client = ModbusClient('192.168.80.210')
      client.connect()
      rr = client.read_holding_registers(40012, 1)
      print rr

      client.close()


      It seems to be connecting to the meter 'cause this is my output:



      DEBUG:pymodbus.transaction:Current transaction state - IDLE
      DEBUG:pymodbus.transaction:Running transaction 1
      DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x9c 0x4c 0x0 0x1
      DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
      DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
      DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received))
      DEBUG:pymodbus.framer.socket_framer:Processing:
      DEBUG:pymodbus.transaction:Getting transaction 1
      DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
      Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received)


      I want to read from register 40012 to 40014 and this is Modbusdbus map I have:
      Modbus map



      I appreciate your help. Regards,







      python modbus modbus-tcp pymodbus






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 21:59









      Benyamin Jafari

      3,19232243




      3,19232243










      asked Nov 21 '18 at 18:28









      Luis Javier Alvarez RodriguezLuis Javier Alvarez Rodriguez

      113




      113
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I think you should set the unit and port argument, and for getting the value use the rr.registers, so you need to know the unit_ID value, and the device port.



          In most cases, the unit is 1 and the port is 502 as the modbus default.



          If you want to read from address 40012 to 40014, you could read from 40012 as a bulky reading with count=3.





          I improved your code, try it:



          from pymodbus.client.sync import ModbusTcpClient

          client = ModbusTcpClient('192.168.80.210', port=502)

          if client.connect():
          res = client.read_holding_registers(40012, count=3, unit=1)

          if not res.isError():
          '''.isError() was implemented in pymodbus version 1.4.0 and above.'''
          print(res.registers)
          else:
          # handling error
          print(res)

          client.close()





          share|improve this answer
























          • Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

            – Luis Javier Alvarez Rodriguez
            Nov 21 '18 at 23:03











          • @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

            – Benyamin Jafari
            Nov 22 '18 at 13:29











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418415%2fpymodbus-read-meter-registers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I think you should set the unit and port argument, and for getting the value use the rr.registers, so you need to know the unit_ID value, and the device port.



          In most cases, the unit is 1 and the port is 502 as the modbus default.



          If you want to read from address 40012 to 40014, you could read from 40012 as a bulky reading with count=3.





          I improved your code, try it:



          from pymodbus.client.sync import ModbusTcpClient

          client = ModbusTcpClient('192.168.80.210', port=502)

          if client.connect():
          res = client.read_holding_registers(40012, count=3, unit=1)

          if not res.isError():
          '''.isError() was implemented in pymodbus version 1.4.0 and above.'''
          print(res.registers)
          else:
          # handling error
          print(res)

          client.close()





          share|improve this answer
























          • Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

            – Luis Javier Alvarez Rodriguez
            Nov 21 '18 at 23:03











          • @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

            – Benyamin Jafari
            Nov 22 '18 at 13:29
















          0














          I think you should set the unit and port argument, and for getting the value use the rr.registers, so you need to know the unit_ID value, and the device port.



          In most cases, the unit is 1 and the port is 502 as the modbus default.



          If you want to read from address 40012 to 40014, you could read from 40012 as a bulky reading with count=3.





          I improved your code, try it:



          from pymodbus.client.sync import ModbusTcpClient

          client = ModbusTcpClient('192.168.80.210', port=502)

          if client.connect():
          res = client.read_holding_registers(40012, count=3, unit=1)

          if not res.isError():
          '''.isError() was implemented in pymodbus version 1.4.0 and above.'''
          print(res.registers)
          else:
          # handling error
          print(res)

          client.close()





          share|improve this answer
























          • Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

            – Luis Javier Alvarez Rodriguez
            Nov 21 '18 at 23:03











          • @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

            – Benyamin Jafari
            Nov 22 '18 at 13:29














          0












          0








          0







          I think you should set the unit and port argument, and for getting the value use the rr.registers, so you need to know the unit_ID value, and the device port.



          In most cases, the unit is 1 and the port is 502 as the modbus default.



          If you want to read from address 40012 to 40014, you could read from 40012 as a bulky reading with count=3.





          I improved your code, try it:



          from pymodbus.client.sync import ModbusTcpClient

          client = ModbusTcpClient('192.168.80.210', port=502)

          if client.connect():
          res = client.read_holding_registers(40012, count=3, unit=1)

          if not res.isError():
          '''.isError() was implemented in pymodbus version 1.4.0 and above.'''
          print(res.registers)
          else:
          # handling error
          print(res)

          client.close()





          share|improve this answer













          I think you should set the unit and port argument, and for getting the value use the rr.registers, so you need to know the unit_ID value, and the device port.



          In most cases, the unit is 1 and the port is 502 as the modbus default.



          If you want to read from address 40012 to 40014, you could read from 40012 as a bulky reading with count=3.





          I improved your code, try it:



          from pymodbus.client.sync import ModbusTcpClient

          client = ModbusTcpClient('192.168.80.210', port=502)

          if client.connect():
          res = client.read_holding_registers(40012, count=3, unit=1)

          if not res.isError():
          '''.isError() was implemented in pymodbus version 1.4.0 and above.'''
          print(res.registers)
          else:
          # handling error
          print(res)

          client.close()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 21:55









          Benyamin JafariBenyamin Jafari

          3,19232243




          3,19232243













          • Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

            – Luis Javier Alvarez Rodriguez
            Nov 21 '18 at 23:03











          • @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

            – Benyamin Jafari
            Nov 22 '18 at 13:29



















          • Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

            – Luis Javier Alvarez Rodriguez
            Nov 21 '18 at 23:03











          • @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

            – Benyamin Jafari
            Nov 22 '18 at 13:29

















          Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

          – Luis Javier Alvarez Rodriguez
          Nov 21 '18 at 23:03





          Thank! you are right. I was missing unit, in this case the unit is 100, now I have registers returning from the device.

          – Luis Javier Alvarez Rodriguez
          Nov 21 '18 at 23:03













          @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

          – Benyamin Jafari
          Nov 22 '18 at 13:29





          @LuisJavierAlvarezRodriguez good luck, with upvote we could improve the Stack Overflow question/answer, and the minimum reputation for upvotes is 15.

          – Benyamin Jafari
          Nov 22 '18 at 13:29




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418415%2fpymodbus-read-meter-registers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$