Simultaneous LPT port access

Gatis gatisl at inbox.lv
Mon Oct 13 05:52:02 EDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081013/7f23f15e/attachment.html>


More information about the Python-list mailing list