How to use the minimalmodbus._twoByteStringToNum 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 testSanity(self):
        for value, numberOfDecimals, LsbFirst, signed, bytestring in self.knownValues:
            if not LsbFirst:
                resultvalue = minimalmodbus._twoByteStringToNum( \
                    minimalmodbus._numToTwoByteString(value, numberOfDecimals, LsbFirst, signed), \
                    numberOfDecimals, signed )
                self.assertEqual(resultvalue, value)

        if ALSO_TIME_CONSUMING_TESTS:
            for value in range(0x10000):
                resultvalue = minimalmodbus._twoByteStringToNum( minimalmodbus._numToTwoByteString(value) )
                self.assertEqual(resultvalue, value)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testKnownValues(self):
        for knownvalue, numberOfDecimals, LsbFirst, signed, bytestring in self.knownValues:
            if not LsbFirst:
                resultvalue = minimalmodbus._twoByteStringToNum(bytestring, numberOfDecimals, signed)
                self.assertEqual(resultvalue, knownvalue)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testSanity(self):
        for value, numberOfDecimals, LsbFirst, signed, bytestring in self.knownValues:
            if not LsbFirst:
                resultvalue = minimalmodbus._twoByteStringToNum( \
                    minimalmodbus._numToTwoByteString(value, numberOfDecimals, LsbFirst, signed), \
                    numberOfDecimals, signed )
                self.assertEqual(resultvalue, value)

        if ALSO_TIME_CONSUMING_TESTS:
            for value in range(0x10000):
                resultvalue = minimalmodbus._twoByteStringToNum( minimalmodbus._numToTwoByteString(value) )
                self.assertEqual(resultvalue, value)
github pyhys / minimalmodbus / test / test_minimalmodbus.py View on Github external
def testWrongInputValue(self):
        self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'ABC', 1)
        self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'A',   1)
        self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'AB',  -1)
github CINF / PyExpLabSys / PyExpLabSys / drivers / crowcon.py View on Github external
# We read 10 registers per detector
        # FIXME. This may exceed the maximum number of registers that can be read
        data = self.read_registers(2999, len(detector_numbers) * 10)

        detector_levels = {}
        for detector_number in detector_numbers:
            # Calculate the register shift for this detector. There are 10 registers
            # per detector, in order.
            reg_shift = 10 * (detector_number - 1)

            # Get the range and read the level
            detector_range = self.detector_configuration(detector_number).range
            # The level is the 0th register
            level_register = data[reg_shift]
            bytestring = _numToTwoByteString(level_register)
            level = _twoByteStringToNum(bytestring, numberOfDecimals=3, signed=True)\
                    * detector_range

            # Status is the 1st register (0-based)
            status = data[1 + reg_shift]
            status_out = []
            if status == 0:
                status_out.append('OK')
            else:
                # Format the number into bitstring and reverse it with [::-1]
                bit_string = '{:016b}'.format(status)[::-1]
                for bit_position, status_message in DETECTOR_STATUS.items():
                    if bit_string[bit_position] == '1':
                        status_out.append(status_message)

            # inhibit is the 4th register (0-based)
            inhibited_register = data[4 + reg_shift]