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

Reply via email to