[visionegg] Re: parallel port 2nd

Hi Christoph,

Your two questions about the parallel port are essentially the same. "inp()" returns a byte (well, actually it's a Python int, but it will always be 0-255). When you've pointed it to the parallel port like "inp(0x379)", 8 bits of the parallel port get stored in the return value. This happens according to the standard method for encoding multi-pin digital signals. In Python, this would be (obviously the system drivers don't run Python...)

result = 0
for n in range(8):
    result += bit[n]*(2**n)

therefore to get bit[n], you want to do something like

for n in range(8):
    bit[n] = result & 2**n

So, if all you care about in your code is bit 4, you can just do bit4 = result & 0x10. So, modify your code from
input_value = raw_lpt_module.inp(0x379)

to input_value = raw_lpt_module.inp(0x379) & 0x10

======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

Other related posts: