Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")
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
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
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()
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('!')
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
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()
def __initSensor(self):
self.sensor = minimalmodbus.Instrument(self.serialport, slaveaddress=self.address)
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
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')