From: Uwe Hermann Date: Fri, 23 Sep 2016 20:19:57 +0000 (+0200) Subject: uart: Emit 2 bytes for 9-bit UART binary output. X-Git-Tag: libsigrokdecode-0.5.0~134 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=98b8913915e8649cca83f543e84fbf128707b5fb;p=libsigrokdecode.git uart: Emit 2 bytes for 9-bit UART binary output. For 5..8 data bits the binary output will be 1 byte, for 9 data bits it will be 2 bytes (big-endian). This fixes bug #708. --- diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 093f3fc..6bba653 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -179,6 +179,7 @@ class Decoder(srd.Decoder): self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_binary = self.register(srd.OUTPUT_BINARY) self.out_ann = self.register(srd.OUTPUT_ANN) + self.bw = (self.options['num_data_bits'] + 7) // 8 def metadata(self, key, value): if key == srd.SRD_CONF_SAMPLERATE: @@ -279,8 +280,9 @@ class Decoder(srd.Decoder): if formatted is not None: self.putx(rxtx, [rxtx, [formatted]]) - self.putbin(rxtx, [rxtx, bytes([b])]) - self.putbin(rxtx, [2, bytes([b])]) + bdata = b.to_bytes(self.bw, byteorder='big') + self.putbin(rxtx, [rxtx, bdata]) + self.putbin(rxtx, [2, bdata]) self.databits[rxtx] = []