How to use the canmatrix.canmatrix.Signal function in canmatrix

To help you get started, we’ve selected a few canmatrix 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 ebroecker / canmatrix / test / test_codec.py View on Github external
def test_decode_signal(self):
        s1 = Signal('signal', signalSize=8)
        self.assertEqual(s1.raw2phys(1), 1)
        self.assertEqual(s1.raw2phys(127), s1.max)
        self.assertEqual(s1.raw2phys(-128), s1.min)

        s2 = Signal('signal', signalSize=10, is_signed=False)
        self.assertEqual(s2.raw2phys(10), 10)
        self.assertEqual(s2.raw2phys(s2.max), 1023)
        self.assertEqual(s2.raw2phys(s2.min), 0)

        s3 = Signal('signal', signalSize=8, factor=2)
        self.assertEqual(s3.raw2phys(5), 10)
        self.assertEqual(s3.raw2phys(127), s3.max)
        self.assertEqual(s3.raw2phys(-128), s3.min)

        s4 = Signal('signal', signalSize=8, is_signed=False, factor=5)
        self.assertEqual(s4.raw2phys(2), 10)
        self.assertEqual(s4.raw2phys(255), s4.max)
        self.assertEqual(s4.raw2phys(0), s4.min)

        s5 = Signal('signal', signalSize=8, offset=2)
        self.assertEqual(s5.raw2phys(8), 10)
        self.assertEqual(s5.raw2phys(127), s5.max)
        self.assertEqual(s5.raw2phys(-128), s5.min)

        s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.raw2phys(5), 10)
github ebroecker / canmatrix / test / test_codec.py View on Github external
s1 = Signal('signal', signalSize=8)
        self.assertEqual(s1.raw2phys(1), 1)
        self.assertEqual(s1.raw2phys(127), s1.max)
        self.assertEqual(s1.raw2phys(-128), s1.min)

        s2 = Signal('signal', signalSize=10, is_signed=False)
        self.assertEqual(s2.raw2phys(10), 10)
        self.assertEqual(s2.raw2phys(s2.max), 1023)
        self.assertEqual(s2.raw2phys(s2.min), 0)

        s3 = Signal('signal', signalSize=8, factor=2)
        self.assertEqual(s3.raw2phys(5), 10)
        self.assertEqual(s3.raw2phys(127), s3.max)
        self.assertEqual(s3.raw2phys(-128), s3.min)

        s4 = Signal('signal', signalSize=8, is_signed=False, factor=5)
        self.assertEqual(s4.raw2phys(2), 10)
        self.assertEqual(s4.raw2phys(255), s4.max)
        self.assertEqual(s4.raw2phys(0), s4.min)

        s5 = Signal('signal', signalSize=8, offset=2)
        self.assertEqual(s5.raw2phys(8), 10)
        self.assertEqual(s5.raw2phys(127), s5.max)
        self.assertEqual(s5.raw2phys(-128), s5.min)

        s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.raw2phys(5), 10)
        self.assertEqual(s6.raw2phys(255), s6.max)
        self.assertEqual(s6.raw2phys(0), s6.min)

        s7 = Signal('signal', signalSize=16, is_signed=False, factor=0.001)
        self.assertEqual(s7.raw2phys(65535), s7.max)
github ebroecker / canmatrix / test / test_codec.py View on Github external
s3 = Signal('signal', signalSize=8, factor=2)
        self.assertEqual(s3.raw2phys(5), 10)
        self.assertEqual(s3.raw2phys(127), s3.max)
        self.assertEqual(s3.raw2phys(-128), s3.min)

        s4 = Signal('signal', signalSize=8, is_signed=False, factor=5)
        self.assertEqual(s4.raw2phys(2), 10)
        self.assertEqual(s4.raw2phys(255), s4.max)
        self.assertEqual(s4.raw2phys(0), s4.min)

        s5 = Signal('signal', signalSize=8, offset=2)
        self.assertEqual(s5.raw2phys(8), 10)
        self.assertEqual(s5.raw2phys(127), s5.max)
        self.assertEqual(s5.raw2phys(-128), s5.min)

        s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.raw2phys(5), 10)
        self.assertEqual(s6.raw2phys(255), s6.max)
        self.assertEqual(s6.raw2phys(0), s6.min)

        s7 = Signal('signal', signalSize=16, is_signed=False, factor=0.001)
        self.assertEqual(s7.raw2phys(65535), s7.max)
        self.assertEqual(s7.raw2phys(0), s7.min)
        self.assertEqual(s7.raw2phys(50123), 50.123)

        s8 = Signal('signal', signalSize=8, is_signed=False, factor=0.00005)
        self.assertEqual(s8.raw2phys(255), s8.max)
        self.assertEqual(s8.raw2phys(0), s8.min)
        self.assertEqual(s8.raw2phys(1), 5e-05)
        self.assertEqual(s8.raw2phys(2), 0.0001)
        self.assertAlmostEqual(s8.raw2phys(3), 0.00015)
github ebroecker / canmatrix / test / test_codec.py View on Github external
self.assertEqual(s5.phys2raw(), 0)
        self.assertEqual(s5.phys2raw(10), 8)
        self.assertEqual(s5.phys2raw(s5.max), 127)
        self.assertEqual(s5.phys2raw(s5.min), -128)

        s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.phys2raw(), 0)
        self.assertEqual(s6.phys2raw(10), 5)
        self.assertEqual(s6.phys2raw(s6.max), 255)
        self.assertEqual(s6.phys2raw(s6.min), 0)

        s7 = Signal('signal', signalSize=8)
        s7.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s7.phys2raw(), 5)

        s8 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        s8.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s8.phys2raw(), 5)

        s9 = Signal('signal', signalSize=16, is_signed=False, factor=0.001)
        self.assertEqual(s9.phys2raw(), 0)
        self.assertEqual(s9.phys2raw(s9.max), 65534)
        self.assertEqual(s9.phys2raw(s9.min), 0)
        self.assertEqual(s9.phys2raw(50.123), 50123)

        s10 = Signal('signal', signalSize=8, is_signed=False, factor=0.00005)
        self.assertEqual(s10.phys2raw(), 0)
        self.assertEqual(s10.phys2raw(s10.max), 255)
        self.assertEqual(s10.phys2raw(s10.min), 0)
        self.assertEqual(s10.phys2raw(0.005), 100)
        self.assertEqual(s10.phys2raw(0.003), 60)
github ebroecker / canmatrix / test / test_codec.py View on Github external
s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.phys2raw(), 0)
        self.assertEqual(s6.phys2raw(10), 5)
        self.assertEqual(s6.phys2raw(s6.max), 255)
        self.assertEqual(s6.phys2raw(s6.min), 0)

        s7 = Signal('signal', signalSize=8)
        s7.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s7.phys2raw(), 5)

        s8 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        s8.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s8.phys2raw(), 5)

        s9 = Signal('signal', signalSize=16, is_signed=False, factor=0.001)
        self.assertEqual(s9.phys2raw(), 0)
        self.assertEqual(s9.phys2raw(s9.max), 65534)
        self.assertEqual(s9.phys2raw(s9.min), 0)
        self.assertEqual(s9.phys2raw(50.123), 50123)

        s10 = Signal('signal', signalSize=8, is_signed=False, factor=0.00005)
        self.assertEqual(s10.phys2raw(), 0)
        self.assertEqual(s10.phys2raw(s10.max), 255)
        self.assertEqual(s10.phys2raw(s10.min), 0)
        self.assertEqual(s10.phys2raw(0.005), 100)
        self.assertEqual(s10.phys2raw(0.003), 60)
github ebroecker / canmatrix / test / test_codec.py View on Github external
def test_bitstruct_format(self):
        """"""
        s1 = Signal('signal')
        self.assertEqual(s1.bitstruct_format(), 's8')
github ebroecker / canmatrix / test / test_codec.py View on Github external
self.assertEqual(s4.phys2raw(s4.max), 255)
        self.assertEqual(s4.phys2raw(s4.min), 0)

        s5 = Signal('signal', signalSize=8, offset=2)
        self.assertEqual(s5.phys2raw(), 0)
        self.assertEqual(s5.phys2raw(10), 8)
        self.assertEqual(s5.phys2raw(s5.max), 127)
        self.assertEqual(s5.phys2raw(s5.min), -128)

        s6 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        self.assertEqual(s6.phys2raw(), 0)
        self.assertEqual(s6.phys2raw(10), 5)
        self.assertEqual(s6.phys2raw(s6.max), 255)
        self.assertEqual(s6.phys2raw(s6.min), 0)

        s7 = Signal('signal', signalSize=8)
        s7.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s7.phys2raw(), 5)

        s8 = Signal('signal', signalSize=8, is_signed=False, offset=5)
        s8.addAttribute('GenSigStartValue', '5')
        self.assertEqual(s8.phys2raw(), 5)

        s9 = Signal('signal', signalSize=16, is_signed=False, factor=0.001)
        self.assertEqual(s9.phys2raw(), 0)
        self.assertEqual(s9.phys2raw(s9.max), 65534)
        self.assertEqual(s9.phys2raw(s9.min), 0)
        self.assertEqual(s9.phys2raw(50.123), 50123)

        s10 = Signal('signal', signalSize=8, is_signed=False, factor=0.00005)
        self.assertEqual(s10.phys2raw(), 0)
        self.assertEqual(s10.phys2raw(s10.max), 255)
github ebroecker / canmatrix / test / test_codec.py View on Github external
def test_encode_signal(self):
        s1 = Signal('signal', signalSize=8)
        self.assertEqual(s1.phys2raw(), 0)
        self.assertEqual(s1.phys2raw(1), 1)
        self.assertEqual(s1.phys2raw(s1.max), 127)
        self.assertEqual(s1.phys2raw(s1.min), -128)

        s2 = Signal('signal', signalSize=10, is_signed=False)
        self.assertEqual(s2.phys2raw(), 0)
        self.assertEqual(s2.phys2raw(10), 10)
        self.assertEqual(s2.phys2raw(s2.max), 1023)
        self.assertEqual(s2.phys2raw(s2.min), 0)

        s3 = Signal('signal', signalSize=8, factor=2)
        self.assertEqual(s3.phys2raw(), 0)
        self.assertEqual(s3.phys2raw(10), 5)
        self.assertEqual(s3.phys2raw(s3.max), 127)
        self.assertEqual(s3.phys2raw(s3.min), -128)

        s4 = Signal('signal', signalSize=8, is_signed=False, factor=5)
        self.assertEqual(s4.phys2raw(), 0)
        self.assertEqual(s4.phys2raw(10), 2)
        self.assertEqual(s4.phys2raw(s4.max), 255)
        self.assertEqual(s4.phys2raw(s4.min), 0)

        s5 = Signal('signal', signalSize=8, offset=2)
        self.assertEqual(s5.phys2raw(), 0)
        self.assertEqual(s5.phys2raw(10), 8)
        self.assertEqual(s5.phys2raw(s5.max), 127)
        self.assertEqual(s5.phys2raw(s5.min), -128)
github ebroecker / canmatrix / test / test_codec.py View on Github external
def test_encode_signal(self):
        s1 = Signal('signal', signalSize=8)
        self.assertEqual(s1.phys2raw(), 0)
        self.assertEqual(s1.phys2raw(1), 1)
        self.assertEqual(s1.phys2raw(s1.max), 127)
        self.assertEqual(s1.phys2raw(s1.min), -128)

        s2 = Signal('signal', signalSize=10, is_signed=False)
        self.assertEqual(s2.phys2raw(), 0)
        self.assertEqual(s2.phys2raw(10), 10)
        self.assertEqual(s2.phys2raw(s2.max), 1023)
        self.assertEqual(s2.phys2raw(s2.min), 0)

        s3 = Signal('signal', signalSize=8, factor=2)
        self.assertEqual(s3.phys2raw(), 0)
        self.assertEqual(s3.phys2raw(10), 5)
        self.assertEqual(s3.phys2raw(s3.max), 127)
        self.assertEqual(s3.phys2raw(s3.min), -128)
github christiansandberg / canopen / canopen / pdo / base.py View on Github external
frame = canmatrix.Frame(pdo_map.name,
                                    Id=pdo_map.cob_id,
                                    extended=0)
            for var in pdo_map.map:
                is_signed = var.od.data_type in objectdictionary.SIGNED_TYPES
                is_float = var.od.data_type in objectdictionary.FLOAT_TYPES
                min_value = var.od.min
                max_value = var.od.max
                if min_value is not None:
                    min_value *= var.od.factor
                if max_value is not None:
                    max_value *= var.od.factor
                name = var.name
                name = name.replace(" ", "_")
                name = name.replace(".", "_")
                signal = canmatrix.Signal(name,
                                          startBit=var.offset,
                                          signalSize=var.length,
                                          is_signed=is_signed,
                                          is_float=is_float,
                                          factor=var.od.factor,
                                          min=min_value,
                                          max=max_value,
                                          unit=var.od.unit)
                for value, desc in var.od.value_descriptions.items():
                    signal.addValues(value, desc)
                frame.addSignal(signal)
            frame.calcDLC()
            db.frames.addFrame(frame)
        formats.dumpp({"": db}, filename)
        return db