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).
Hi. Is there a possibility that we can be able to read the values of properties in the script? For example, if you have a serial session, I would like to be able to read, say "RX total bytes"; even if I be able to read this on a "onLogRecord" event, it would be fine. Thanks in advance for your time.
You mean, to read values from the "Information" pane? Yes, that is technically possible, but could you give a use case that would require such a feature? There might be a better way to achieve the same...
Well, in building test benches, keeping an eye on things like total bytes, throughput and status of lines like DSR/DTR and even RTS and CTS (when they are used as IO) is important. Although I don't need information like CRC things, but I assume for other use cases accessing that can be useful.
Well, in building test benches, keeping an eye on things like total bytes, throughput and status of lines like DSR/DTR and even RTS and CTS (when they are used as IO) is important.
Right. The proper way of getting notifications about all of these events is through the onLogRecord callback. Every time a new record appears in the log, your onLogRecord is called; you analyze the recordCode and react accordingly.
onLogRecord
recordCode
I still don't see the benefit of reading these values from the "Information" pane -- they are updated on-timer and are generally not in-sync with your onLogRecordCode.
onLogRecordCode
Although I don't need information like CRC things, but I assume for other use cases accessing that can be useful.
Checksums in the "Information" pane are updated when a user manually selects ranges in the log. In other words, they are updated based on UI events, and as such, they can't be relied upon from scripts. If checksums are important for your script, you must calculate them in your onLogRecord (e.g., using helper functions in files like scripts/common/crc16.jnc).
scripts/common/crc16.jnc
Maybe, a concrete example of what you try to get? Most likely, it's doable from onLogRecord...
For example, can you please provide an example how to read the status of RTS/CTS for example from the script either in main() or onLogRecord?
Sure. The basic idea is to listen for new log records and update your variables holding the state of RTS/CTS lines accordingly. You would need SerialLogRecordCode.PortOpened to get the initial line state on port open, SerialLogRecordCode.RtsChanged to track RTS changes, and SerialLogRecordCode.StatusLineChanged to track CTS changes.
SerialLogRecordCode.PortOpened
SerialLogRecordCode.RtsChanged
SerialLogRecordCode.StatusLineChanged
In the sample below, I simply print the states of those lines to the session system log (Menu -> View -> System Log). Feel free to change it according to the requirements of your script.
import "io_base.jncx" import "io_Serial.jnc" import "Serial/SerialLogRecordCode.jnc" bool g_rts; bool g_cts; void onLogRecord( uint64_t timestamp, uint64_t recordCode, void const* p, size_t size ) { switch (recordCode) { case SerialLogRecordCode.PortOpened: SerialOpenParams const* params = (SerialOpenParams const*)p; g_rts = params.m_rts; g_cts = (params.m_statusLines & io.SerialStatusLines.Cts) != 0; printf("Initial RTS: %d CTS: %d\n", g_rts, g_cts); break; case SerialLogRecordCode.RtsChanged: g_rts = *(bool const*) p; printf("RTS changed: %d\n", g_rts); break; case SerialLogRecordCode.StatusLineChanged: SerialStatusLineChangedParams const* params = (SerialStatusLineChangedParams const*)p; if (params.m_mask & io.SerialStatusLines.Cts) { g_cts = (params.m_lines & io.SerialStatusLines.Cts) != 0; printf("CTS changed: %d\n", g_cts); } break; } }