I am also unexperinced with Python and had to learn how to implement a
decoder. Here are some hints that help me. Instead of using print I use
the Python log system. Here are the code lines of my decoder that are
related to logging.
class Decoder(srd.Decoder):
options = (
{ 'id': 'log', 'desc': 'Write log file "D:\\pnet.log"',
'default': 'no', 'values': ('yes', 'no')},
)
def __init__(self):
self.reset()
def reset(self):
self.logger = loggin.getLogger('pnet')
def start(self):
loggin.basicConfiguration(filename='D:/pnet.log', level=loggin.INFO)
if self.options['log'] != 'no':
self.logger.setLevel(logging.DEBUG)
# show that logging is working
self.logger.info("decoder start")
def decode(self, ss, es, data):
# actual information
self.logger.info('decode')
self.logger.debug('ss:{d} es:{d}'.format(ss,es))
This shows the basic idea. The benefit of writing to a file is that you
can log a huge amount of lines and use an editor of your choice to
search for interesting information. Further you can also use it with
sigrok-cli.
Also recommended to read:
https://docs.python.org/3/howto/logging-cookbook.html
Best regards,
Helge
Am 14.11.2020 um 13:05 schrieb Test Jarfalla:
> Hello,
>
> Many thanks for the replies, some - I realize - I should have figured by
> myself, but some were good for clarification.
>
> I should point out that I'm totally new to Python so there is a lot of
> guessing going on when working on the decoder.
>
> What seems a bit odd to me is that there appears to be variables and
> functions that are default or inherited by sigrokdecoder? Is there any way
> to figure out what variables and properties/functions that are available?
> One example is self.has_channel. Maybe it's already somewhere in the
> documentation, but it's not apparent to me.
> I would very much like to use the pulseview log window that you mention. Is
> there any way I there can generate a list (through print() for example) of
> available variables and properties?
>
> I have tried the print statement in a protocol decoder, but don't get
> really expected result.
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel