python-3.xserial-portmodbusminimalmodbus

How can i achieve slave in python using minimalmodbus?


I am using python minimamlmodbus library using this library i want to achieve slave and master communication in which i am going to be slave and the instrument will be master

I have successfully achieve master and slave communication using minimalmodbus in which,master was me and slave was the instrument.

i have used the following code to achieve master and slave communication

            ser=minimalmodbus.Instrument(port_to_connect,1,'ascii')
            ser.serial.baudrate=baudrate
            ser.serial.bytesize=8
            ser.serial.parity=serial.PARITY_NONE
            ser.serial.stopbits=1
            ser.debug=False
            ser.serial.timeout=3
            #gui()
            while self._stopped:
                time.sleep(1)
                data=ser.read_string(4096,33,3)
                print(str(data))

            self.finished.emit()
            self._stopped=True 

I want the instrument to be master and the python interface be slave is it possible.


Solution

  • Minimalmodbus can only be used as a Modbus master, unfortunately. I think that Pymodbus is useful for implementing a Modbus slave. See https://pymodbus.readthedocs.io

    Disclaimer: I am the maintainer of Minimalmodbus