FIFO buffer for controlling RS232 devices?
bob
Posts: 296
Anybody has implemented kind of flow control or a timed FIFO buffer approach for controlling a serial device? Instead of sending to the device directly, just call a function with the command as a parameter and the function will keep track of all arriving commands to be send and que them and send with a predefined pause in between so that the controlled device would not miss a thing.
0
Comments
I typically will do a queue for all rs232 stuff.. they're not that hard to build and manage and just generally seem to keep things moving more smoothly. It has a built-in collision insurance that makes programming over large systems less quirky.
My method is to make a larger buffer for holding the message. (usually 5 to 10-ish commands) Then keep an array of wait times for devices that require different wait times depending upon the command (projectors, older Plasmas, etc...) or just a standard wait time for devices that don't really care much.
Then just watch for length in the buffer and do something about it when you find something.
the data_event from the main program works something like this (using simplified code)
Then you could, for example, put something down in define_program to watch for strings
Then in the function
this is, of coure, overly simplified. You'd need to do some checking for bad commands/string and deal with that. You'd probably also need to track device status and whatnot. It is important to watch the flag that starts and stops the whole mess as bad commands, buffer overruns or whatever can get it stuck. Sometimes that kind of thing can be a real bear to figure out once you've written a whole bunch of code.
I actually use a timeline for this kind of thing because I can really tweak the delay times much better and can squeeze them down so the whole thing runs more quickly and efficiently.
There's lots of ways to do this and I'm sure someone else can give you clever ideas to make it happen.