Making a little progress on this on the weekend. As promised, I'm doing a GUI for the program shown before. I'm doing this as a separate thing, as I'm having to kinda learn GTK2, Glade, and well, isn't that enough? The gui is coming along fine so far, but this is like creating the universe in a sense. It's not taking much code at all -- all you have to do is specify the properties of the universe so it works out, stars from, life appears and evolves and so on - might be as simple as choosing the right Calibu-Yau space for the string theory, or saying "let there be light" as in "let there be a space where Maxwell's equations are true" but boy, the homework is killer....
There's a fairly cool advantage here. Perl doesn't natively know how to "yield" to the opsys when it's in a forever loop polling the serial input (with time resolution better than a second). This isn't normally much of a problem, but it makes for nasty looking plots on the system resources, since Linux is cool enough to let you eat an entire core or thread doing that until things get busy, and it makes the program look like a real hog. With GTK and its pals, I can schedule polling for say 1/4 second intervals, and have the serial input code just do nothing if there's nothing to do right then (no complete lines), and that suspends the entire process until either the next tick, or someone clicks on it. For the moment, I'm also using STDIO on the terminal to emit debug and "I got here" type messages as I debug the code. Once you learn this, it doesn't seem so hard, but it's definitely another world from using DevStudio on Windows if you were used to that (and I was, more than a little). Neither worse nor better, maybe better -- I like the events auto-magically getting hooked up, and can tolerate the way Glade works to design a UI, so far. But the learning curve is quite steep -- Glade doesn't do it all for you and create the routines that happen on events. The old version did that, but generated code that changed everytime you edited the UI stuff, which wiped out any event-specific code you'd added, yuck. Devstudio would orphan code in that case, which would cause a different type of problem later...toss a coin, this is going to work in the end, and work well. This code should also play in Windows too, the way I'm writing it so far, with zero changes needed and not even a re compile -- take that, DevStudio
Here's what it looks like so far. The window on the right is going to get the output of the standard counter (like a terminal program or text editor), the left pane will fill with option check and radio buttons etc, and the gnu plot window will be elsewhere on the screen - its own process, which BTW is a good way to make things easy on the machine, we just let the opsys decide who gets cycles when. In a real situaion, there might after all be several other programs running for logging, and we might even add database connection to this one to shove this into a DB instead of "just a log file". Which also implies that at some point, I'll need to add a feature to put gnuplot on any of these logfiles, which will be simply named as something like StdCYYYY_MM_DD_HH_MM_SS.log so you don't have to type names and they'll be sortable easily.

- Screenshot of infant gui and coding tools
When I get this a little (or a lot) closer, I'll be able to cut and paste the real code that does things into this framework easily. As I said, in theory it should even work in windows. Right now, there are a collection of files that go with this. The glade file that is loaded to generate the GUI, and a file for initializing the serial port. Then there will be log files created. I am hoping to find a way to bundle the first two inside the perl program itself for simplicity...I know there's a way, even if I have more than one file...
This might not be the best way to do "cross platform" -- we'll have to see. It might be more trouble (for the user) to get windows installed with perl and all the other stuff than it would be to get them to install virtual box, install linux (which has all this junk already, or nearly all) and run it that way. It's kind of more fun in some ways to have your own little "cloud". I go the other way here, and run Windows in a window -- seems more reliable and solid and hey, that's where that stuff belongs - in a sandbox.
Edit: here's what the gui code looks like. Not usable as is (doesn't do much) but establishes a simple framework and "how to get rolling with this junk" kind of boilerplate.
- SC.txt
- Gui code for standard counter - the beginning
- (3.57 KiB) Downloaded 419 times
And here's the code from the previous post -- the rest of it. Merging these won't be hard I think.
- StdCntr.txt
- the not-gui code that does the real work
- (8.22 KiB) Downloaded 417 times
I'll be able to get rid of the "poll forever" as I do the merge, and have a sub called at intervals from the GUI to do that sort of thing, and only do it while we are running. I'll probably need a little code to toss out a line from the serial port after we tell the hardware to reset as we're probably already in the middle of one, or will get a borked one right then - better to start on second #1 or 2, and have it right than garble as the first line in a log file.
Anyone who wants to look this code over, a syntax highlighting editor is the tool of choice. Perl looks like gibberish enough even with that. Gedit, Padre, Geany all are free in linux, there might be some free option on one of the latter for windows, dunno -- I run perl there, but don't write it there.
Edit: I forgot to add the .glade file to this upload, and since I feel like this is useful for backup and example as is, here is that file too. It describes the UI for the project. I don't see or edit this, I use Glade to edit it graphically. If it's like most XML, you'd go blind reading it anyway. note that in general I have to rename all these with a .txt extension or the board won't allow them to upload. That's because some might be evil code that would hurt users. So any of these might need a name change to be used.
- StdC.txt
- Glade file for GUI
- (5.04 KiB) Downloaded 421 times