1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/python
# .+
#
# .context : PortIO
# .title : Toggle parallel port lines
# .kind : command shell
# .author : Fabrizio Pollastri <mxgbot@gmail.com>
# .site : Torino - Italy
# .creation : 13-Nov-2008
# .copyright : (c) 2008-2012 Fabrizio Pollastri
# (c) 2012 Stjepan Henc <sthenc@gmail.com> python 3 porting.
# .license : GNU General Public License (see below)
#
# This file is part of "PortIO, python low level I/O for Linux x86".
#
# PortIO is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# PortIO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# .-
import sys, time, os
import portio
# check for root privileges
if os.getuid():
print('You need to be root! Exiting.')
sys.exit()
# acquire permission for I/O on lp0
status = portio.ioperm(0x378, 1, 1)
if status:
print('ioperm:',os.strerror(status))
sys.exit()
# toggle forever the data lines of lp0
data = 0
while 1:
lp0in = portio.inb(0x378)
portio.outb(data,0x378)
print('read %x from lp0, written %x to lp0' % (lp0in,data))
data = ~data & 0xff
time.sleep(3)
#### END
|