Archive for category PD Software

Colored reports for text and HTML in Python

One of the things that I face regularly is report generation. Often they’re free form, by which I mean not tables full of tabulated data.

Output from my htmlAnsii() class

Output from my htmlAnsii() class

Just “is this ok, is that ok, 27 of the other happened”, that sort of thing. I like to use color — green if everything is ok, red if it isn’t and so on.

I’m often out where I want the report in a web browser. But then again, I’m often at my desk, signed in to a console and I want it there. The environments couldn’t be much more different; HTML tags on the one hand, within the wrapper of a page, and ANSII escape sequences on the other. And they’re both kind of annoying and error-prone to write out explicitly, especially when you’re doing it a lot.

What to do?
Read the rest of this entry »

Tags: , , , , , , , , , ,

Making Python’s sqlite3 import easy as 1 2 3

Lurking within the normal Python 2.x distribution is the sqlite3 import, which is an amazingly powerful, mostly SQL compatible database engine that can be used in any project without restriction.

That’s the up side. The down side is, as a fairly complete database, there are many options and varied ways it can be used, and managing actual database transactions isn’t all that simple — to do it right, even a single query takes about sixteen lines of code. And yes, if you want maximum flexibility and the ability to use every feature in sqlite3, that’s how you should do it.

But. Most database operations are very straightforward. You want to issue a single command to the database, or a query. Perhaps you want to write a bunch of data and then commit it all at once so that the database doesn’t contain part of the data from a more complex transaction. Those are by far the most common use cases for me, and I suspect that’s true for others as well.

Frankly, it’s difficult enough dealing with the SQL query language itself. Why make actually using it harder than it has to be?
Read the rest of this entry »

Tags: , , , , , ,

Catching ALL exceptions in Python

When working with Python, sometimes, more than anything else, you need to know what went wrong. Quite aside from all the debate about what you should do in response, and particularly when developing, you need more than just a vague idea that your CGI bailed and that there might (or might not) be some usable indication of this in the system web logs.

Even when working in a pure command line context, you may need to catch anything and everything. If you do, the following gives you a basic model of just how to do it.

import sys try: a = 5 / 0 except Exception,e: # the Exception class provides messages print 'Exception caught, message: '+str(e) raise SystemExit # bail out (optional) except: # other exceptions e = sys.exc_info() # so we mine sys library info instead print 'Non-Exception class Exception caught, message: '+str(e) raise SystemExit # bail out (optional) else: # and, well, sometimes things work out. print 'it worked, no exception!' # whoo hoo... finally: # always happens print 'Glad THAT ordeal is over -- one way or another.' print 'And here we are. Aren't we?' # you only get here if things worked out

Try out the above with code you know will work, like a=1 immediately subordinate to the try: clause, and then with code you know won’t work, like a=5/0 and see what it does.

Something to keep in mind: The ELSE clause of a TRY block only runs if execution proceeds off the end of the TRY section. So if you have two statements in the TRY section, and the first one runs but the second one does not, the ELSE clause will not execute. The EXCEPT clause will due to the exception. FINALLY always, always runs, even if the EXCEPT clause has an exit in it.

You can think of the ELSE as being functionally equivalent to just putting code right after the TRY-EXCEPT-ELSE-FINALLY sequence if you build an unavoidable exit into the EXCEPT portion. Of course, it’s nice to put related code in, because that makes the functionality and intent more obvious. And if you don’t have an exit there… then ELSE can be quite useful, as it won’t run if the TRY block fails, but the code after the entire TRY-EXCEPT-ELSE-FINALLY sequence will.

Hope someone finds this useful. Took me a while to dig through it all and wrap my head around even the basic idea that sometimes, you just need to know!

Tags: , , , , ,

New OSX and Windows version of SdrDx – 2.08

SdrDx 2.08 supercedes the UDP interface in 2.07 (UDP still present in case you’ve coded for it) with a TCP server interface that is capable of supporting multiple clients. It turns out there’s a rather serious bug in OSX that prevents UDP connections from being opened with more than one client, so TCP is better for now.

As with the UDP interface, I’ve included a basic TCP client example written in Python.

In addition, beginning with SdrDx 2.08, the program will let you know if and when upgrades are available to you in the program’s title bar, as long as you have an Internet connection when you start it.

The TCP interface now has many additional commands as compared to the previous version’s UDP command set, and so far we’ve got an alpha version of an iPad client that displays waterfall, spectrum, demod envelope, allows tuning and other control, and plays back audio — all using the new TCP interface. In addition, during the beta period, tuning control for a screwdriver antenna was implemented using the TCP interface and Python.

I have a multi-VFO (26 of them, A-Z) application I’ve made available (OSX only so far) that works with the new TCP interface as well, giving you copious radio-like VFO control over SdrDx. Each VFO remembers frequency and all related display settings, so you can frequency hop like a little radio bunny. (cough) Sorry. :)

SdrDx 2.08 provides for frequency offset, which in turn allows it to be used more easily with up-converters such as those that might be part of a FUNcube installation.

There are various other changes, mostly small tweaks and bugfixes. Enjoy!

Screen shot: http://www.flickr.com/photos/fyngyrz/7488025818/
Downloads: http://fyngyrz.com/?p=915
Documentation: http://fyngyrz.com/sdrdxdoc/sitemap.html
Changes: http://fyngyrz.com/sdrdxdoc/changes208.html

Tags: , , , , , , , , , , , ,

Online Docs for SdrDx

I am pleased to introduce online documentation for SdrDx. This marks a sea change, where we move from a text file, buried in the distribution, to a system where everyone is looking at the same document, one that is easier to read, to look at and in general to deal with. It includes a table of contents, an index, visual cues for user interface elements and so on.

The link is on the SdrDx page, and the next release of SdrDx will take you there directly.

Comments and corrections are welcome, of course.

Tags: , , , , ,

New version of SdrDx – 2.00

Please see this post for details on SdrDx 2.00.

Tags: , , , , ,

New Version of SdrDx (Mac / OS X version of CuteSDR)

Please see this post for the latest details on v1.07.

Tags: , , , ,

SdrDx –OS X and Windows SDR Software

SdrDx2.13gI’ve been working on developing OSX/Mac and Windows versions of SdrDx. At this time, SdrDx for OSX and Windows supports RFSPACE, FunCube Pro, Andrus MK1.5, AFEDRI, FunCube Pro Plus, Peaberry, and Softrock SDR receivers.

In addition, SdrDx can be made to support any SDR with a sound card interface, including I/Q input via your native or auxiliary sound card, with a little scripting work; the Peaberry and Softrock support demonstrate this mechanism using Python.

SdrDx (running on the Mac) is shown to the right. SdrDx is a closed-source, free application.

SdrDx, in combination with your SDR, is an extremely powerful receiver. Reception, recording, playback, analysis, processing — it’s all there, and it’s all been made as easy to use as possible. Extensive documentation covers every aspect of operating the software, as well as providing numerous examples and images to help you along. If you’re an expert radio user, you’re sure to settle right in. If you’re still learning, you can look forward to software that lets your capabilities grow with your knowledge.
Read the rest of this entry »

Tags: , , , , , , , ,