How to use the minimalmodbus.Instrument function in minimalmodbus

To help you get started, we’ve selected a few minimalmodbus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyhys / minimalmodbus / tests / test_deltaDTB4824.py View on Github external
def verify_two_instrument_instances(instr, portname, mode, baudrate):
    ADDRESS_SETPOINT = 0x1001

    _print_out("Verify using two instrument instances")
    instr2 = minimalmodbus.Instrument(portname, SLAVE_ADDRESS, mode=mode)
    instr2.serial.timeout = TIMEOUT

    instr.read_register(ADDRESS_SETPOINT)
    instr2.read_register(ADDRESS_SETPOINT)

    _print_out("... and verify port closure")
    instr.clear_buffers_before_each_transaction = False
    instr2.close_port_after_each_call = True
    instr.read_register(ADDRESS_SETPOINT)
    instr2.read_register(ADDRESS_SETPOINT)
    instr.read_register(ADDRESS_SETPOINT)
    instr2.read_register(ADDRESS_SETPOINT)
    _print_out("Passing test for using two instrument instances")
github CINF / PyExpLabSys / machines / rasppi103 / data_logger.py View on Github external
def __init__(self, port):
        self.comm = minimalmodbus.Instrument(port, 1)
        self.comm.serial.baudrate = 9600
        self.comm.serial.parity = serial.PARITY_EVEN
        self.comm.serial.timeout = 0.5
        error = 0
        while error < 10:
            try:
                self.temperature = self.comm.read_register(4096, 1)
                break
            except OSError:
                error = error + 1
        if error > 9:
            exit('Error in communication with TC reader')
        threading.Thread.__init__(self)
        self.quit = False
github lambcutlet / DPS5005_pyGUI / source_files / dps_modbus.py View on Github external
def __init__(self, port1, addr, baud_rate, byte_size ):
		self.instrument = minimalmodbus.Instrument(port1, addr) # port name, slave address (in decimal)
		#self.instrument.serial.port          # this is the serial port name
		self.instrument.serial.baudrate = baud_rate   # Baud rate 9600 as listed in doc
		self.instrument.serial.bytesize = byte_size
		self.instrument.serial.timeout = 0.5     # This had to be increased from the default setting else it did not work !
		self.instrument.mode = minimalmodbus.MODE_RTU  #RTU mode
github MFxMF / SDM630-Modbus / plugin.py View on Github external
def onStart(self):
        self.rs485 = minimalmodbus.Instrument(Parameters["SerialPort"], int(Parameters["Mode2"]))
        self.rs485.serial.baudrate = Parameters["Mode1"]
        self.rs485.serial.bytesize = 8
        self.rs485.serial.parity = minimalmodbus.serial.PARITY_NONE
        self.rs485.serial.stopbits = 1
        self.rs485.serial.timeout = 1
        self.rs485.debug = False
                          

        self.rs485.mode = minimalmodbus.MODE_RTU
        devicecreated = []
        Domoticz.Log("Eastron SDM630 Modbus plugin start")
        self.runInterval = int(Parameters["Mode3"]) * 1 
        if 1 not in Devices:
            Domoticz.Device(Name="Voltage L1", Unit=1,TypeName="Voltage",Used=0).Create()
        if 2 not in Devices:
            Domoticz.Device(Name="Voltage L2", Unit=2,TypeName="Voltage",Used=0).Create()
github CINF / PyExpLabSys / PyExpLabSys / drivers / omega_D6400.py View on Github external
def __init__(self, address=1, port='/dev/ttyUSB0'):
        self.instrument = minimalmodbus.Instrument(port, address)
        self.instrument.serial.baudrate = 9600
        self.instrument.serial.timeout = 1.0  # Default setting leads to comm-errors
        print(self.instrument.serial)
        self.ranges = [0] * 8
        for i in range(1, 8):
            self.ranges[i] = {}
            self.ranges[i]['action'] = 'disable'
            self.ranges[i]['fullrange'] = '0'
        self.ranges[1]['action'] = 'voltage'
        self.ranges[1]['fullrange'] = '10'

        for i in range(1, 8):
            print(i)
            self.update_range_and_function(i, fullrange=self.ranges[i]['fullrange'],
                                           action=self.ranges[i]['action'])
            print('!')
github CINF / PyExpLabSys / machines / rasppi47 / data_logger.py View on Github external
def __init__(self, port):
        self.comm = minimalmodbus.Instrument('/dev/serial/by-id/' + port, 1)
        self.comm.serial.baudrate = 9600
        self.comm.serial.parity = serial.PARITY_EVEN
        self.comm.serial.timeout = 0.5
        self.temperature = -999
        threading.Thread.__init__(self)
        self.quit = False
github CINF / PyExpLabSys / PyExpLabSys / drivers / vogtlin.py View on Github external
Args:
            port (str): Device name e.g. "COM4" or "/dev/serial/by-id/XX-YYYYY
            slave_address (int): The integer slave address
            serial_com_kwargs (dict): Mapping with setting to value for the serial
                communication settings available for minimalmodbus at the module level.
                E.g. to set `minimalmodbus.BAUDRATE` use {'BAUDRATE': 9600}.
        """
        # Apply serial communications settings to minimalmodbus module
        self.serial_com_kwargs = dict(DEFAULT_COM_KWARGS)
        self.serial_com_kwargs.update(serial_com_kwargs)
        for key, value in self.serial_com_kwargs.items():
            setattr(minimalmodbus, key, value)

        # Initialize the instrument
        self.instrument = minimalmodbus.Instrument(port, slave_address)
        self._last_call = time()
github Miceuz / rs485-moist-sensor / utils / lib / chirp_modbus.py View on Github external
def __initSensor(self):
		self.sensor = minimalmodbus.Instrument(self.serialport, slaveaddress=self.address)
github smarthomeNG / plugins / systemair / __init__.py View on Github external
def init_serial_connection(self, serialport, slave_address):
        try:
            if self.instrument is None:
                self.instrument = minimalmodbus.Instrument(serialport, int(slave_address))
            return True
        except:
            self.instrument = None
            logger.error("Failed to initialize modbus on {serialport}".format(serialport=serialport))
            return False
github Miceuz / rs485-moist-sensor / utils / setBaud.py View on Github external
sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i)
			addressRead = sensor.read_register(0, functioncode=3)
			if(i == addressRead):
				print('FOUND!')
				return (True, i)
		except (IOError):
			print("nope...")
			pass
	return (False, 0)
# sensor.debug=True

(found, i) = scanModbus()
if found:
	print('Found sensor at address: ' + str(i))
	try:	
		sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i)
		print("Setting new baudrate: " + str(baudrates[BAUDRATE2]))
		sensor.write_register(1, value=BAUDRATE2, functioncode=6)
		minimalmodbus._SERIALPORTS={}
		minimalmodbus.BAUDRATE=baudrates[BAUDRATE2]

		sleep(0.2)
		sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i)
		print("reading address from holding register: ")
		print(sensor.read_register(0, functioncode=3))
	except:
		print "Could not change the address. Check your connections"
else:
	print('No sensor on the bus found')