Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I am writing a custom protocol analyzer. But I could not find a way to do initialization when a new session is started. I have static variables which keep values all the time, but I don't know how to initialize those variables when new session is started.
It would be great if someone could help me.
Best Regards, Shun
Hi Shun,
I'd say it's a better practice to keep state variables as member fields of your parser class rather using globals. But it's not written in stone, of course.
To reset state vairables/fields on every session start, process log.StdRecordCode.SessionStart in your log.Converter.convert(...) routine and do initialization from there. Also, you want to override log.Converter.reset() and do initialization here, too (reset() will get called when a user force-clears the log, rebuilds the log by adding a filter, etc).
log.StdRecordCode.SessionStart
log.Converter.convert(...)
log.Converter.reset()
reset()
You can check the official Modbus Analyzer for reference (there are two versions now, a new one based on dynamic layouts and the legacy once).
Also, there're new tutorials on writing protocol analyzers and packet templates using dynamic layouts, check it out:
https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html https://ioninja.com/doc/developer-manual/tutorial-ias-packet-dylayout.html
Hi Vladimir,
thank you very much for your quick reply. It was exactly what I needed, and I was able to solve my issue. I'm implementing this protocol analyzer for the first time while figuring out how it works. Definitely some refactoring is necessary afterwards. Thanks for your help.
Glad to hear it helped! Let me know if you have more questions regarding this protocol analyzer of yours. Which protocol is that, by the way?