Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
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)
def testWrongInputValue(self):
self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'ABC', 1)
self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'A', 1)
self.assertRaises(ValueError, minimalmodbus._twoByteStringToNum, 'AB', -1)
# 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]