minimalmodbus | use Modbus RTU and Modbus ASCII implementation | TCP library

 by   pyhys Python Version: 2.1.1 License: Apache-2.0

kandi X-RAY | minimalmodbus Summary

kandi X-RAY | minimalmodbus Summary

minimalmodbus is a Python library typically used in Networking, TCP applications. minimalmodbus has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install minimalmodbus' or download it from GitHub, PyPI.

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              minimalmodbus has a highly active ecosystem.
              It has 236 star(s) with 133 fork(s). There are 20 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 11 open issues and 73 have been closed. On average issues are closed in 199 days. There are 3 open pull requests and 0 closed requests.
              OutlinedDot
              It has a negative sentiment in the developer community.
              The latest version of minimalmodbus is 2.1.1

            kandi-Quality Quality

              minimalmodbus has 0 bugs and 0 code smells.

            kandi-Security Security

              minimalmodbus has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              minimalmodbus code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              minimalmodbus is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              minimalmodbus releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              minimalmodbus saves you 2191 person hours of effort in developing the same functionality from scratch.
              It has 7219 lines of code, 394 functions and 6 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed minimalmodbus and discovered the below as its top functions. This is intended to give you an instant insight into minimalmodbus implemented functionality, and help decide if they suit your requirements.
            • Generic generic command .
            • Extract the message payload .
            • Check that the inputstring is valid .
            • Create the payload .
            • Predict response size .
            • Convert a number to a two - byte string .
            • Check that the numerical value is valid .
            • Convert a float value to a string .
            • Parse a response payload .
            • Convert a string to a float .
            Get all kandi verified functions for this library.

            minimalmodbus Key Features

            No Key Features are available at this moment for minimalmodbus.

            minimalmodbus Examples and Code Snippets

            Noob trying to get values from his EnergyMeter via Modbus RTU RS485 in python
            Pythondot img1Lines of Code : 3dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            HV_A_Phase_Spannung = Hausverbrauch.read_float(0, functioncode=4, number_of_registers=2)
            print(str(f'{HV_A_Phase_Spannung :.2f}')+"V -Phase A") 
            
            Python Minimal Modbus CRC byte order
            Pythondot img2Lines of Code : 28dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            return _num_to_twobyte_string(register, lsb_first=True)
            
            return _num_to_twobyte_string(register, lsb_first=False)
            
            import minimalmodbus
            
            def _calculate_crc_string(inputstring):
                """Calcula
            Can't connect to EPsolar Tracer 3210an charge controller from Windows 10 via Serial / Modbus
            Pythondot img3Lines of Code : 11dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Pin  | Define 
            -----|-------------------------------------
            1    | Power supply output +5V or +7.5V 
            2    | Power supply output +5V or +7.5V 
            3    | RS-485-B 
            4    | RS-485-B 
            5    | RS-485-A 
            6    | RS-485-A 
            7    | Ground 
            8    | Ground
            <
            Read and write to Modbus RTU
            Pythondot img4Lines of Code : 6dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            instrument = minimalmodbus.Instrument('COM4', 2)
            
            instrument.write_register(0, 0xff00)
            
            instrument.write_bit(0, 1)
            
            Raspberry Pi RS485/Uart Modbus
            Pythondot img5Lines of Code : 2dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            print RecievedData.encode('hex')
            
            Handling unusual response from slave register - Extra 'FF' added by manufacturer
            Pythondot img6Lines of Code : 2dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                    answer = self.serial.read(number_of_bytes_to_read)[3:]
            
            Minimalmodbus function code 0x46 and sub function 06
            Pythondot img7Lines of Code : 8dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            _performCommand(0x46, '0x05,0x04,0x02')
            
            0x46 - function code
            
            0x05 - sub function code
            0x04 - baud rate 38400
            0x02 - parity/stop bits 8E1
            
            Python script for RTU Modbus Slave
            Pythondot img8Lines of Code : 27dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from pymodbus.client.sync import ModbusSerialClient
            
            client = ModbusSerialClient(
                method='rtu',
                port='/dev/ttyUSB0',
                baudrate=115200,
                timeout=3,
                parity='N',
                stopbits=1,
                bytesize=8
            )
            
            if client.connect():  # Tryi
            Error in writing to multiple slaves in minimalmodbus
            Pythondot img9Lines of Code : 4dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Left.write_register(4097, Ltemp)
            Middle.write_register(4097, Mtemp)
            Right.write_register(4097, Rtemp)
            
            snmpd pass to run python
            Pythondot img10Lines of Code : 5dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pi@rraspberrypi:~$ groups Debian-snmp
            Debian-snmp : Debian-snmp
            
            pi@raspberrypi:~ $ sudo usermod -a  -G dialout Debian-snmp
            

            Community Discussions

            QUESTION

            python minimalmodbus protocol implementation for SMC LEC 6: write to multiple coils
            Asked 2021-Jun-22 at 12:59

            minimalmodbus does not provide a way to set multiple coils at once. I cannot find a workaround.

            objective:

            The modbus protocol description in the datasheet of the SMC LEC 6 controller, see link. I try to follow the directions from the example starting at page 7 by sending the listed modbus commands using the pyton library minimalmodbus.

            I want to send the command 01 0F 00 10 00 08 01 02 BE 97 but do not find a way to do this with minimalmodbus. There is not implementation of function code 15 (OF).

            What I tried to do:

            I reasoned as follows:

            • I want to set multiple coils: 0F
            • Starting from position: 00 10
            • I want to set 8 coils: 00 08, or one byte 01
            • What I want to do is set this byte to value 2 (02), or in binary 00000010

            I thought this could work by setting these positions all separately:

            ...

            ANSWER

            Answered 2021-Jun-22 at 12:59

            I was able to send the command in question by going a bit deeper in the minimal modbus class and sending the raw payload to the device:

            00 10 00 08 01 02

            Source https://stackoverflow.com/questions/68072096

            QUESTION

            How to read register of digital counter with minimalmodbus
            Asked 2021-Jun-10 at 05:34

            I'm trying to read the values of an industry digital counter with Modbus RTU RS-485. Using USB-RS-485 conversion, and here is the master send code is taken from the following datasheet,

            Datasheet Link

            I am expecting that the read input register is what I'm expecting, and the API of the minimalmodbus expects to specify register number, a number of decimals, and function code.

            • Does the library auto-assign the slave number, or we have to define it?
            • From the datasheet, is it the register number is the address?
            • And how many decimals do I expect if there's two data sequence as a response?
            • Is the CRC16 check already included within the library as i shouldn't code it?

            Here's my code by far, modifying examples.

            ...

            ANSWER

            Answered 2021-Jun-10 at 05:34

            Does the library auto-assign the slave number, or we have to define it?

            With MinimalModbus you pass the slave ID through in the minimalmodbus.Instrument('/dev/ttyUSB0', 1) call (the 1 is the Slave ID). How you set the slave ID on the device itself varies (this is not covered by the Modbus over serial line spec; could be a configuration program, DIP switches, based on the serial number etc. Other libraries may take different approaches (for example defaulting to Slave ID 1).

            From the datasheet, is it the register number is the address?

            The header in the spec tables says "No(Address)" so "10001(0000)" means register 1, address 0 (these refer to the same thing; I recommend reading the "Modbus: When 40001 Really Means 1, or 0 Really Means 1" section in this article which explains some of the issues around addressing).

            And how many decimals do I expect if there's two data sequence as a response?

            Not quite sure what you mean by "two data sequence". The Modbus spec only details the sending of bits (coils) and 16 bit values (input/holding registers). From a quick look at your spec it looks like this device just uses a single registers; for instance "OUT1 Output time" has "unit: ×10㎳" so take whatever is in the register and divide by 10 to get ms.

            Is the CRC16 check already included within the library as i shouldn't code it?

            Any decent Modbus library will look after the protocol details (such as CRC) for you (so no you don't need to code this; MinimalModbus will calculate it for you)

            Source https://stackoverflow.com/questions/67913346

            QUESTION

            Trouble reading MODBUS register using Python
            Asked 2021-Jun-07 at 03:36

            I am trying to use Python (PyCharm) to read a register on a modbus device. I have confirmed the COM port, Baud rate and other communication settings and I can use the devices application to read the value (it is a water level logger). I am getting no response from the instrument.

            Register is readable in mbpoll using -

            ...

            ANSWER

            Answered 2021-Jun-03 at 05:31

            The device manual isn't clear about the register start address, but the first register it mentions has the address of 1.

            Similarly, the mbpoll command-line utility (not the one with GUI) isn't very clear about the start address. But its documentation mentions that the default value for -r parameter is 1.

            I think it's safe to assume that both use the same addressing which starts from 1, as the command-line tool has no problems accessing the value.

            But MinimalModbus API clearly mentions that its register start address is 0. So when using this library, you need to use registeraddress = 45 for accessing the temperature, not 46 or 40046.

            But why won't 46 work? Normally, one would expect it to grab data starting from the next register and print some garbage, but not timeout. But we can't know how the device works internally. Maybe a request to access the temperature register actually triggers some measurement function and then returns a value. A request to access an unaligned data (with a wrong register value) can be simply rejected by the firmware.

            If you still get timeouts with registeraddress = 45, your Python runtime may have some problems accessing the serial port. As I stated in my comment, I recommend using a logic analyzer to see what's going on on the wire. Without such a tool, you're doing blind-debugging.

            Source https://stackoverflow.com/questions/67669720

            QUESTION

            Noob trying to get values from his EnergyMeter via Modbus RTU RS485 in python
            Asked 2021-May-14 at 13:08

            fist Post as i normaly find the answers if i search long enough. But today is the day... I bought a EnergyMeter from Aliexpress with MODBUS RTU connection and im trying to read it out. I already tried a lot of stuff from all over the Internet.

            This is the Datasheet of the EnergyMeter1

            I tried pyModbus and minimalmodbus.

            My both Scripts:

            ...

            ANSWER

            Answered 2021-May-14 at 13:08

            Thanks to @Brits i got it running. I had to use read_float(0, functioncode=4, number_of_registers=2) where 0 is decimal. If i want to read 001A i had to convert from hex to dec = 26. Works very good

            Source https://stackoverflow.com/questions/67528300

            QUESTION

            Modbus registers can be only read and cannot be written
            Asked 2021-May-12 at 07:50

            I am trying communicate via Modbus protocol to a uC2 SE controller for a air-water chiller. A serial RS485 to USB port COM is connected with the controller and I was able to read registers, but it is not possible to change their values by using write_register function. I have also tried with tester. exe and Modscan64 softwares and the result was the same, they only can read but not write. I have introduced here the piece of code is being run and debug responses can be checked. Thank you for your help in advance!

            Change temperature setpoint

            COOLING_SETPOINT_REG = 41

            try: print(instrument.read_register(COOLING_SETPOINT_REG,1)) except IOError: print('Failed to read from instrument')

            NEW_TEMPERATURE = 20.1

            return_flag = instrument.write_register(COOLING_SETPOINT_REG, NEW_TEMPERATURE,1,functioncode = 6, signed = True) # Registernumber, value, number of decimals for storage output_flag = 'SUCCESS' if return_flag else 'FAILURE' print('writing single register status ' + output_flag + '\n' )

            try: print(instrument.read_register(COOLING_SETPOINT_REG,1)) except IOError: print('Failed to read from instrument')

            Respuesta debug:

            MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): '\x01\x03\x00)\x00\x01UÂ' (01 03 00 29 00 01 55 C2) MinimalModbus debug mode. Opening port COM8 MinimalModbus debug mode. Clearing serial buffers for port COM8 MinimalModbus debug mode. No sleep required before write. Time since previous read: 334030.00 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Closing port COM8 MinimalModbus debug mode. Response from instrument: '\x01\x03\x02\x00ȹÒ' (01 03 02 00 C8 B9 D2) (7 bytes), roundtrip time: 62.0 ms. Timeout for reading: 1000.0 ms.

            20.0 MinimalModbus debug mode. Will write to instrument (expecting 8 bytes back): '\x01\x06\x00)\x00É\x98T' (01 06 00 29 00 C9 98 54) MinimalModbus debug mode. Opening port COM8 MinimalModbus debug mode. Clearing serial buffers for port COM8 MinimalModbus debug mode. No sleep required before write. Time since previous read: 47.00 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Closing port COM8 MinimalModbus debug mode. Response from instrument: '\x01\x06\x00)\x00É\x98T' (01 06 00 29 00 C9 98 54) (8 bytes), roundtrip time: 47.0 ms. Timeout for reading: 1000.0 ms.

            writing single register status FAILURE

            MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): '\x01\x03\x00)\x00\x01UÂ' (01 03 00 29 00 01 55 C2) MinimalModbus debug mode. Opening port COM8 MinimalModbus debug mode. Clearing serial buffers for port COM8 MinimalModbus debug mode. No sleep required before write. Time since previous read: 46.00 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Closing port COM8 MinimalModbus debug mode. Response from instrument: '\x01\x03\x02\x00ȹÒ' (01 03 02 00 C8 B9 D2) (7 bytes), roundtrip time: 47.0 ms. Timeout for reading: 1000.0 ms.

            ...

            ANSWER

            Answered 2021-Mar-22 at 15:06

            Writing is successful.

            write_register from minimalmodbus has "None" return value.

            So checking the return_flag results in failure.

            Source https://stackoverflow.com/questions/66742777

            QUESTION

            Store modbus messages using minimalModbus
            Asked 2021-May-05 at 19:56

            I need to write and read registers from a serial device. Everything works fine, but I need to store the messages in a variable. For example:

            ...

            ANSWER

            Answered 2021-May-05 at 19:56

            Option 1) Modify the library to return the "answer" variable from private function _communicate to your program.

            Option 2) Save the debug log output to a variable and filter this variable for the string.

            Source https://stackoverflow.com/questions/67366544

            QUESTION

            Minimalmodbus, randomly generates wrong crc
            Asked 2021-Apr-05 at 08:07

            I am currently working on a project of data acquisition with a RaspberryPi. When i launch my request script, sometimes (rare but too often) my slave (computer) detects a CRC error or invalid length. I'm guessing the error could come from the fact that, as my script is fast and asks for hundreds of register in a few seconds, sometimes the message is incomplete and my slaves detects it as a wrong message. I wanted to know if it was possible that minimalmodbus isn't timed right and sometimes will send a wrong or part of a request (incomplete).

            Error returned on the slave:

            ...

            ANSWER

            Answered 2021-Apr-04 at 10:04

            Sounds like your problem could be the byte order used by the emulated slave.

            Source https://stackoverflow.com/questions/66905927

            QUESTION

            Can't connect to EPsolar Tracer 3210an charge controller from Windows 10 via Serial / Modbus
            Asked 2020-Oct-08 at 19:16
            Summary

            I'm using this USB-to-RJ45 cable to connect my Windows 10 developer workstation to the EPEver Tracer 3210an solar charge controller.

            I'm using Python 3.8.6 with the minimalmodbus module to attempt to connect to the device, retrieve data, and control the device parameters.

            Expected Result

            The charge controller returns the input voltage of the photovoltaic (PV) panels.

            Actual Result ...

            ANSWER

            Answered 2020-Oct-08 at 19:16

            Communication with these controllers (manual) is via RS485 (delivered through an RJ45 connector). This is only mentioned briefly in the manual ("RS485 interface" in the technical specifications section).

            The cable you are using appears to be a router console cable which, I believe, uses the RS232 protocol (see document from Cisco as an example). RS232 and RS485 are different, and incompatible, so this cable will not work.

            The manual for this controller does not go into much detail and I could not see a modbus manual on the EPEVER website. I use Tracer-BN series units and epever support emailed me a manual detailing the modbus setup; as your unit also supports the MT50 remote meter I'm assuming its registers are the same. You can probably find the manual by searching for "common software or MT50 LCD unit" (with the quotes) - I believe version 2.5 is the latest (note: I'm not posting the link because it does not seem to be available on the official website so click at your own risk!)

            The RJ45 wiring (from the above manual) is:

            Source https://stackoverflow.com/questions/64251163

            QUESTION

            Read a binary file and send over Modbus RTU using Python 3 (how to convert 'str' to an 'int')
            Asked 2020-Jun-08 at 20:08

            I have made a PCB circuit that has a microcontroller (Microchip PIC18F47K40) that can program a parallel flash memory (Microchip SST39SF040).

            The microcontroller communicates to my PC (Windows 10) via Modbus RTU over a USB to UART adaptor.

            I use five Modbus registers...

            Control, Address0, Address1, Address2, Data

            Control = read, write, erase

            Address0,1,2 = Address bus

            Data = Data bus

            Using Baseblock program I have verified the microcontroller is working fine, and in Python I can send individual commands ok.

            My goal is to be able to read in a binary file and send to the microcontroller to program the flash memory chip.

            This is the code I have so far: -

            ...

            ANSWER

            Answered 2020-Jun-08 at 18:23

            You can use int(dataByte.hex())

            Source https://stackoverflow.com/questions/62268300

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install minimalmodbus

            You can install using 'pip install minimalmodbus' or download it from GitHub, PyPI.
            You can use minimalmodbus like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install minimalmodbus

          • CLONE
          • HTTPS

            https://github.com/pyhys/minimalmodbus.git

          • CLI

            gh repo clone pyhys/minimalmodbus

          • sshUrl

            git@github.com:pyhys/minimalmodbus.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link