Protocol decoders can use the OUTPUT_BINARY type to emit arbitrary data.
https://sigrok.org/wiki/Protocol_decoder_output#Binary_output

Then invoking sigrok-cli with option "-B, --protocol-decoder-binary
<binaryspec>" outputs this data to stdout where you can pipe or redirect to
a file.

Is it possible to write your decoder to emit OUTPUT_BINARY instead of
directly managing files inside the decoder?

On Tue, Dec 14, 2021 at 2:16 AM Helge Kruse <helge.kr...@gmx.net> wrote:

> My protocol decoder shall write some data to a file during invocation of
> the decode method. For that purpose I create the file once in the start
> method:
>
>
> class Decoder(srd.Decoder):
>      inputs = ['uart']
>      options = ( {'id':'path', 'desc':'', 'default':'/tmp/dat'}, )
>
>      def start(self):
>          self.file = open(self.options['path'], 'w')
>
>      def decode(self, ss, es, data):
>          self.file.write ("decode data")
>
>
> The decoder is invoked as this:
>
> sigrok-cli -P uart:rx=D0,mydecoder -i sample.sr
>
> The problem is that the file is empty. The file is not flushed or closed
> in the decoder code. I have a workaround:
>
>
>      def start(self):
>          self.file = open(self.options['path'], 'w')
>          self.file.close()
>
>      def decode(self, ss, es, data):
>          self.file = open(self.options['path'], 'a')
>          self.file.write ("decode data")
>          self.file.close()
>
>
> This is ugly is should be slow if the decoded data increases. Is there
> any way to get the decoder called before the sigrok-cli session closes?
>
>
> Regards,
> Helge
>
>
> _______________________________________________
> sigrok-devel mailing list
> sigrok-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sigrok-devel
>
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to