How to use the minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL 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 / test / test_minimalmodbus.py View on Github external
def setUp(self):
        dummy_serial.VERBOSE = False
        dummy_serial.RESPONSES = RESPONSES
        dummy_serial.DEFAULT_RESPONSE = 'NotFoundInResponseDictionary'

        minimalmodbus.serial.Serial = dummy_serial.Serial
        minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True # Mimic a WindowsXP serial port
        self.instrument = minimalmodbus.Instrument('DUMMYPORTNAME', 1) # port name, slave address (in decimal)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def setUp(self):
        dummy_serial.VERBOSE = False
        dummy_serial.RESPONSES = RESPONSES
        dummy_serial.DEFAULT_RESPONSE = 'NotFoundInResponseDictionary'
        minimalmodbus.serial.Serial = dummy_serial.Serial
        minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = False
        self.instrument = minimalmodbus.Instrument('DUMMYPORTNAME', 1) # port name, slave address (in decimal)
github Miceuz / rs485-moist-sensor / utils / setBaud.py View on Github external
import minimalmodbus
import serial
from time import sleep

baudrates=[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200]


parser = argparse.ArgumentParser()
parser.add_argument('baudrate', metavar='BAUD', type=int, choices=range(0, 7), help='Current baudrate')
parser.add_argument('newbaudrate', metavar='NEWBAUD', type=int, choices=range(0, 7), help='Baudrate index to set')
args = parser.parse_args()

ADDRESS1 = 1
BAUDRATE2 = args.newbaudrate

minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True
minimalmodbus.PARITY=serial.PARITY_NONE
minimalmodbus.STOPBITS = 2
minimalmodbus.BAUDRATE=baudrates[args.baudrate]

minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True


def scanModbus():
	for i in range(1, 248):
		try:
			print('Trying address: ' + str(i))
			sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i)
			addressRead = sensor.read_register(0, functioncode=3)
			if(i == addressRead):
				print('FOUND!')
				return (True, i)
github Miceuz / rs485-moist-sensor / utils / lib / chirp_modbus.py View on Github external
def __init__(self, address, serialport, serialbaudrate=DEFAULT_BAUDRATE, serialparity=DEFAULT_PARITY, serialstopbits=DEFAULT_STOPBITS):
		minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True
		minimalmodbus.PARITY=serial.PARITY_NONE
		minimalmodbus.STOPBITS = serialstopbits
		minimalmodbus.BAUDRATE=serialbaudrate
		self.address = address
		self.serialport = serialport
		self.__initSensor()
github starze / openhab2 / openhab2 / scripts / readNilan.py View on Github external
#!/usr/bin/env python3
# -*- coding: ISO-8859-1 -*-
# https://github.com/starze/openhab2 
# https://github.com/roggmaeh/nilan-openhab

import minimalmodbus
import serial
import os, sys
import csv
import httplib2

minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 30, mode='rtu') # port name, slave address (in decimal)
instrument.serial.port
instrument.serial.baudrate = 19200   # Baud
instrument.serial.bytesize = 8
instrument.serial.parity   = serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout  = 2   # seconds
#instrument.debug = True

h = httplib2.Http()

with open('nilan_modbus.csv') as csvfile:

	reader = csv.DictReader(csvfile, delimiter=',')
	for row in reader:
		if row['Register Type'] == "Input":
github Miceuz / rs485-moist-sensor / utils / setAddress.py View on Github external
import argparse

import minimalmodbus
import serial
from time import sleep


parser = argparse.ArgumentParser()
parser.add_argument('address', metavar='ADDR', type=int, choices=range(1, 248), help='An address to set')
args = parser.parse_args()

ADDRESS1 = 1
ADDRESS2 = args.address

minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True
minimalmodbus.PARITY=serial.PARITY_NONE
minimalmodbus.STOPBITS = 2
minimalmodbus.BAUDRATE=19200

minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True

def scanModbus():
	for i in range(1, 248):
		try:
			print('Trying address: ' + str(i))
			sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i)
			addressRead = sensor.read_register(0, functioncode=3)
			if(i == addressRead):
				print('FOUND!')
				return (True, i)
		except (IOError):
github smarthomeNG / plugins / systemair / __init__.py View on Github external
def __init__(self, smarthome, serialport, slave_address="1", update_cycle="30"):
        self._sh = smarthome
        self.instrument = None
        self.slave_address = int(slave_address)
        self._update = {}
        self._update_coil = {}
        self.serialport = serialport
        self.slave_address = slave_address
        minimalmodbus.TIMEOUT = 3
        minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL=True
        self._sh.scheduler.add('Modbus systemair', self._read_modbus, prio=5, cycle=int(update_cycle))
        self.my_reg_items = []
        self.mod_write_repeat = 20  # if port is already open, e.g on auto-update,
                                    # repeat mod_write attempt x times a 1 seconds