Skip to content
david d zuhn edited this page Oct 16, 2018 · 3 revisions

Welcome to the non-blocking CMRI wiki!

This is a non-blocking implementation of the CMRI protocols, useful for model railroading application (and other stuff as well). By using a non-blocking state machine, the 99% of the Arduino cycles not used in processing CMRI messages can be used for other purposes.

What other purposes? Blinking lights for one. That was the driver for this library. I want to control lights from a JMRI/PanelPro screen, and let the Arduino handle the blinking for me, not JMRI.

What else? Oh, who knows. There are probably a whole pile of other things you might want to do. Play sounds, maybe? Control other devices that need something closer to "real time" control. I don't know what you might use this for. So please, let me know. Because I would love to hear what you are doing with this code.

API Overview

The API is designed so that a use sketch will define a CMRI object, give it an input stream (for the serial line), and the define functions that will be called to get the value of an input line, or to change the value of an output when necessary.

Once this object is defined, you call the check() method inside your loop() function. This method will handle everything CMRI related, performing all of the serial I/O operations and calling the I/O handler functions. If there's nothing to do when you call check() (and most of the time, there won't be, because the Arduino CPU is so much faster than a CMRI serial line), the call returns quickly (a small number of microseconds) and the loop() processing code can continue on with the other desired processing.

Clone this wiki locally