Mark Rogers mark@quarella.co.uk
Occasionally I have the need to write some communications software, typically something that connects to a serial or TCP port, writes requests and reads responses, writing the results into a database. [...] What is the "best" way to approach something like this? Are some programming languages better than others for this? What's the best way to ensure a script restarts if it fails for some reason?
I think the best approach is to build on well-tested available libraries. I used Perl, but I expect Python and other languages have good libraries too. Perl did have the benefit of both serial and TCP connections being under IO::Socket and behaving in fairly similar ways.
The best way to ensure a script restarts if it fails is to run it from something like daemon or maybe even init (with inittab), but beware that the device or connection may be left in an unclean state after a crash and set restart parameters so that the fastest possible series of crashes and restarts won't harm the device.
Good luck!