Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setBaudrate(self, baudrate):
if(baudrate < 0 or baudrate > 7):
raise ValueError("Baudrate index has to be [0..7]")
self.sensor.write_register(1, value=baudrate, functioncode=6)
minimalmodbus._SERIALPORTS={}
minimalmodbus.BAUDRATE = self.baudrates[baudrate]
self.__initSensor()
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)
except (IOError):
print("nope...")
pass
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()
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):
print("nope...")
pass
return (False, 0)