Simultaneous LPT port access

2008-10-13 Thread Gatis
Hello!
Question: are my (following) considerations about simultaneous lpt
access true? Is "LPT server" needed? What could be possible
architecture of such component?
===
I'm writing program "alarm" that reads LPT input pin (activated by
motion sensor). 
If motion is sensed, program turns on notify device (beacon-connected
to LPT output pin) for 5 seconds. Than waits for a minute and repeats
"input read"/"notify switch on".
Now I want to add new function - fire alarm which in case of fire
turns on beacon permanently until fire alarm sensor switches off.
I'll try to implement frie alarm monitoring as new thread (my program
is without threads yet) because I have to poll lpt input from
firealarm every second.
But this means two threads are simultaneously reading/writing LPT
port. I guess it must not be allowed (does it?).
To access LPT I use following code:
IOports=open("/dev/port","r+b",0)
def GetChar(address):
IOports.seek(address)
return ord(IOports.read(1))
def PutChar(address,c):
IOports.seek(address)
IOports.write(chr(c))
class lpt:
def __init__(self,port=0x378):
self.address=port
def Put_Data(self,c):
PutChar(self.address,c)
def Get_Data(self):
return GetChar(self.address)
def Put_Status(self,c):
PutChar(self.address+1,c)
def Get_Status(self):
return GetChar(self.address+1)
def Put_Control(self,c):
PutChar(self.address+2,c)
def Get_Control(self):
return GetChar(self.address+2)
[found in
http://mail.python.org/pipermail/python-announce-list/2000-November/000567.html]
Simplest solution would be to add "LPT blocking" - if firealarm has
written and blocked LPT prot(by setting variable blockLPT), motion
alarm thread cannot any more change LPT output pin for beacon. 
But more elegant solution would be "LPT server" [Idea taken from
owfs-server] - thread that countinuously reads LPT inputs and serves
this info to all other threads. 
For writing - alarm threads sends write requests, LPT server executes
them one by one according to importance level (if house burns, don't
care for motion). 
===
Best regards,
Gatis Liepins--
http://mail.python.org/mailman/listinfo/python-list


Python script + v4lctl

2008-10-20 Thread Gatis
Hello!
Intro: 
I wrote script that in case of some event takes picture using usb
webcam [Creative Live! Cam Vista IM (VF0420)] and command line utility
v4lctl (from package xawtv).
Problem1:
To catch error and info messages from script I used:
sys.stdout = open('/tmp/log','a')
sys.stderr=sys.stdout
All writes to log file well, except v4lctl error messages. If script
is run from commandline, than v4lctl error messages are shown there.
How to catch these messages?
Problem2:
When script is run from /etc/init.d (in runlevel 2) during boot, no
pictures are taken. I can't tell error message, because of Problem1.
If I execute now v4lctl from commandline (while my script is running
in background), picture is taken.
If script is restarted (using same init.d startup script that was
used by pc to start my python script) pictures are taken - all works.
I set in rc2.d that script starts at the end of boot - "S99script" -
so it starts after webcam drivers are loaded.
I set delay of minute at the begining of script to allow pc to finish
boot - no results.
In dmesg there are error messages:
"v4lctl: segm: .. : error 4"
Command executed: v4lctl -c /dev/video0 snap jpeg full test.jpg
Using Linux Ubuntu 8. 
Drivers for webcam - using EasyCam
[https://help.ubuntu.com/community/EasyCam].
Where can be found v4lctl return codes?
Best regards,
Gatis Liepins--
http://mail.python.org/mailman/listinfo/python-list