n8ur has asked for the wisdom of the Perl Monks concerning the following question:

Sorry for the non-useful title, but I can't think of a simple description that covers what I'm trying to do.

I am writing a program to do data logging via a GPIB interface card, using Linux and the drivers/library from the linux-gpib.sourceforge.net project (but don't let that scare you off... my question isn't related to the details of GPIB).

What I need to do is keep my program running as a daemon at all times, but be able to communicate with it to control the instruments on the GPIB bus, start and stop writing to log files, etc.

I'm envisioning something that I could telnet to and issue a basic set of commands with verification that the command has been accepted.

On top of that, I *think* (but am not sure) that this would be a good application for threads, as this program will be communicating with three or four different devices on the bus, each of which is doing its thing independently of the others. The thread would handle sending commands to the instrument, reading the response, massaging the data, then writing it to a log file.

I wonder if someone would be kind enough to help me put together at least a skeleton of what a program like this might look like -- in particular, how to launch and manage threads via a telnet interface. I'm happy to fill in the blanks, but I'm not sure how to lay the program out at a high level.

Thanks!

John

  • Comment on Controllable daemon, threads, and other things

Replies are listed 'Best First'.
Re: Controllable daemon, threads, and other things
by 5mi11er (Deacon) on Jan 28, 2005 at 23:25 UTC
    My only suggestion is to look at and study the source to other "things" that do similar tasks. ndc (name daemon control) from the bind/dns processes is the one good one I can think of off the top of my head. There are probably many others...

    -Scott

Re: Controllable daemon, threads, and other things
by zentara (Cardinal) on Jan 29, 2005 at 13:54 UTC
    Design it one step at a time. First learn to set up a daemon and talk to it through a socket port. Then setup the daemon to start x number of threads when it initiates, and just put the threads to sleep. Then figure out the thread code blocks needed for watching your cards. One step at a time. It may be easier to log to different files for each thread to avoid clashes when writing to the log files. It sounds pretty complex, and I doubt if someone is going to be able to provide an "instant skeleton" for it. But you might get lucky. :-)

    So maybe you should repost your question, like: "How do I setup a daemon and talk to it through sockets?" That is your first big step. (As always, groups.google for it first..."perl daemon socket communication" gets you some code on the first page.)


    I'm not really a human, but I play one on earth. flash japh
Re: Controllable daemon, threads, and other things
by Anonymous Monk on Jan 31, 2005 at 11:33 UTC
    Check out Making Servers Dynamically Configurable in the Jan. '05 issue of The Perl Journal. You could also contact the author.