How to use minimalmodbus - 10 common examples

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 parse_commandline(argv):
    # Do manual parsing of command line,
    # as none of the modules in the standard library handles python 2.6 to 3.x

    mode = minimalmodbus.MODE_RTU
    baudrate = DEFAULT_BAUDRATE
    portname = DEFAULT_PORT_NAME

    for arg in argv:
        if arg.startswith("-ascii"):
            mode = minimalmodbus.MODE_ASCII

        elif arg.startswith("-rtu"):
            mode = minimalmodbus.MODE_RTU

        elif arg.startswith("-b"):
            if len(arg) < 3:
                _print_out("Wrong usage of the -b option. Use -b9600")
                sys.exit()
            baudrate = int(arg[2:])
github pyhys / minimalmodbus / tests / test_deltaDTB4824.py View on Github external
def parse_commandline(argv):
    # Do manual parsing of command line,
    # as none of the modules in the standard library handles python 2.6 to 3.x

    mode = minimalmodbus.MODE_RTU
    baudrate = DEFAULT_BAUDRATE
    portname = DEFAULT_PORT_NAME

    for arg in argv:
        if arg.startswith("-ascii"):
            mode = minimalmodbus.MODE_ASCII

        elif arg.startswith("-rtu"):
            mode = minimalmodbus.MODE_RTU

        elif arg.startswith("-b"):
            if len(arg) < 3:
                _print_out("Wrong usage of the -b option. Use -b9600")
                sys.exit()
            baudrate = int(arg[2:])

        elif arg.startswith("-D"):
            if len(arg) < 3:
                _print_out(
                    "Wrong usage of the -D option. Use -D/dev/ttyUSB0 or -DCOM4"
                )
                sys.exit()
            portname = arg[2:]

    return portname, mode, baudrate
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 pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testKnownValues(self):
        minimalmodbus._checkInt(47, minvalue=None,  maxvalue=None, description='ABC')
        minimalmodbus._checkInt(47, minvalue=40,    maxvalue=50, description='ABC')
        minimalmodbus._checkInt(47, minvalue=-40,   maxvalue=50, description='ABC')
        minimalmodbus._checkInt(47, description='ABC', maxvalue=50, minvalue=40)
        minimalmodbus._checkInt(47, minvalue=None,  maxvalue=50, description='ABC')
        minimalmodbus._checkInt(47, minvalue=40,     maxvalue=None, description='ABC')
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testInputNotString(self):
        for value in _NOT_STRINGS:
            self.assertRaises(TypeError, minimalmodbus._print_out, value)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testWriteRegisterSuppressErrorMessageAtWrongCRC(self):
        try:
            self.instrument.write_register(51, 99) # Slave gives wrong CRC
        except ValueError:
            minimalmodbus._print_out('Minimalmodbus: An error was suppressed.')
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def assertRaises(self, excClass, callableObj, *args, **kwargs):
        """Prints the caught error message (if :data:`SHOW_ERROR_MESSAGES_FOR_ASSERTRAISES` is :const:`True`)."""
        if SHOW_ERROR_MESSAGES_FOR_ASSERTRAISES:
            try:
                unittest.TestCase.assertRaises(self, _NonexistantError, callableObj, *args, **kwargs)
            except:
                minimalmodbus._print_out( '\n    ' + repr(sys.exc_info()[1]) )
        else:
            unittest.TestCase.assertRaises(self, excClass, callableObj, *args, **kwargs)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testKnownValues(self):
        minimalmodbus._print_out('ABCDEFGHIJKL')
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testNotNumericInput(self):
        for value in _NOT_NUMERICALS:
            self.assertRaises(TypeError, minimalmodbus._checkNumerical, value, minvalue=40.0)
        for value in _NOT_NUMERICALS_OR_NONE:
            self.assertRaises(TypeError, minimalmodbus._checkNumerical, 47.0,  minvalue=value, maxvalue=50.0,  description='ABC')
            self.assertRaises(TypeError, minimalmodbus._checkNumerical, 47.0,  minvalue=40.0,  maxvalue=value, description='ABC')
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testKnownValues(self):
        minimalmodbus._checkNumerical(47, minvalue=None, maxvalue=None, description='ABC')
        minimalmodbus._checkNumerical(47, minvalue=40, maxvalue=50, description='ABC')
        minimalmodbus._checkNumerical(47, minvalue=-40, maxvalue=50, description='ABC')
        minimalmodbus._checkNumerical(47, description='ABC', maxvalue=50, minvalue=40)
        minimalmodbus._checkNumerical(47, minvalue=None, maxvalue=50, description='ABC')
        minimalmodbus._checkNumerical(47, minvalue=40, maxvalue=None, description='ABC')
        minimalmodbus._checkNumerical(47.0, minvalue=40)
        minimalmodbus._checkNumerical(47, minvalue=40.0, maxvalue=50, description='ABC')
        minimalmodbus._checkNumerical(47.0, minvalue=40, maxvalue=None, description='ABC' )
        minimalmodbus._checkNumerical(47.0, minvalue=40.0, maxvalue=50.0, description='ABC' )