Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    modbus library not working on 1.19 and up firmware

    Scheduled Pinned Locked Moved WiPy 2&3
    2 Posts 2 Posters 144 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      gt1
      last edited by

      Hi All,

      I have a program works great reading a modbus sensors i had this working on firmware version 1.18.
      so i just got in new wipy3s and updated them to the newest firmware ( 1.20 RC13 ) put my sensor on my board and it did not read. First i thought it was my board so i tired another board same result. so then i went and loaded Firmware 1.18 on the same wipy and plugged it in and it started working.

      Then i went to the github page to pull the last modbus library and that also doenst solve any problems on the newer firmwares. does anyone know why the modbus library doesnt work on the newer firmwares over 1.18?

      FYI i went to 1.19b4 and that also did not work.

      1 Reply Last reply Reply Quote 0
      • L Offline
        luixal
        last edited by

        I made it work in version 1.20.2.rc7 (dated 2020-05-04) by going into serial.py file and replacing readall function call by read.

        Anyhow, isn't a better library? A port of minimalmodbus will be great as I hard to hardcode some things to be able to read inverse float values.

        I've filled this issue at github's repo, but last commit is 12 months ago...

        Issue content:
        Hi,

        I'm reading values from a sensor that uses RS485 and sends inverse float values with function code 4 (addresses 0, 2 and 4) and it was imposible for me to read those values using the read_input_registers function (which uses function code 4).

        I had to add another function for converting values to float instead of short (quite hardcoded for my case, not so much into modbus):

        def _to_float(self, byte_array, signed=True):
                # response_quantity = int(len(byte_array) / 2)
                # this always returned 2
                # fmt = '>' + ('f' * response_quantity)
                # so fmt ended up like '>ff' and caused a buffer issue, so I hardcoded it to ' >f'
                # also, no idea about signed floats, just left the signed var to be consistent
                return struct.unpack('>f', byte_array)
        

        and a new function copy&pasted from read_input_registers, but using the _to_float` function defined above:

        def read_float_registers(self, slave_addr, starting_address, register_quantity, signed=True):
                modbus_pdu = functions.read_input_registers(starting_address, register_quantity)
        
                resp_data = self._send_receive(modbus_pdu, slave_addr, True)
                register_value = self._to_float(resp_data, signed)
        
                return register_value
        

        Any cleaner/correct/good way to implement this?

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom