def stop(self):"""Stop the daemon"""# Get the pid from the pidfiletry:pf = file(self.pidfile,'r')pid = int(pf.read().strip())pf.close()except IOError:pid = Noneif not pid:message = "pidfile %s does not exist. Daemon not running?\n"sys.stderr.write(message % self.pidfile)return # not an error in a restart

I`m having a bit of running before I`m walking problems.The problem was having no error messages to go on I didn`t know what the problem was with my code I added to the daemon script.I`m going to have to learn a little more about class set up !!!

o.k , my task is to control a Arduino via a cgi script.But why I need some form of daemon, was because each time I invoked the script which connected to the USB port with ‘self = serial.Serial('/dev/ttyUSB2', 19200, timeout=10)’ and would reinitialise the Arduino.

Quote

You might want to write your code first and daemonize it later.

Yep, that`s what I had to do to get it working, move my code just before the daemonize .

So not a daemon - which is a continuously running process. A daemon wouldn't use stdout - a CGI script may well do so, to return info to the calling client. And a CGI script would get input data using the CGI API (RFC3875). In Perl you'd use the CGI module to do this for you, but I have no idea how Python would do it.

Yes I can agree with that “a continuously running process” or a form of proxy service.It`s not the cgi part which is the problem, it`s the need to keep control of the USB port not let it reinitialise after each call.

so you need two parts? A Daemon that opens the ttyUSB and waits for commands. And a CGI-Program that can communicate with the daemon?

Why is reopening the serial port resetting the arduino? It shouldn't know if anything is accessing it or not. It's a serial port. But if you realy need the daemon, i would work like this

create a socket in /var/tmp. Open serial port, do your initialization, attach stdout and stdin to the socket. Done with the daemon part. But that should actually not be different then opening and closing ttyUSB every time.

Why is reopening the serial port resetting the arduino?I think it`s something to do with the rts / cts lines, which it uses as a auto reset for reprogramming.I`ve completed my demo program which work o.k now, not very pretty , but I will improve as my python programming skills improve.

def stop(self):"""Stop the daemon"""# Get the pid from the pidfiletry:pf = file(self.pidfile,'r')pid = int(pf.read().strip())pf.close()except IOError:pid = Noneif not pid:message = "pidfile %s does not exist. Daemon not running?\n"sys.stderr.write(message % self.pidfile)return # not an error in a restart