def regSet(self, dev_type, addr, data): try: self._devAddrSet(dev_type) except Exception as e: self.logger.error("Set device address fail, error: " + str(e)) raise try: portio.iopl(3) except Exception as e: self.logger.error("LPC.regGet: iopl() enable failed") raise try: portio.ioperm(self.lpcAddr + addr, 4, 1) except Exception as e: self.logger.error("LPC.regGet: ioperm() enable failed") raise try: portio.outb(data, self.lpcAddr + addr) except Exception as e: self.logger.error("LPC.regGet: outb() failed") try: portio.ioperm(self.lpcAddr + addr, 4, 0) except Exception as e: self.logger.error("LPC.regGet: ioperm() disable failed") raise try: portio.iopl(0) except Exception as e: self.logger.error("LPC.regGet: iopl() disable failed") raise
def initializelocalports(): writetodebuglog("i","Initializing local I/O ports.") if hw == 0: GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(prt_i1,GPIO.IN) GPIO.setup(prt_i2,GPIO.IN) GPIO.setup(prt_i3,GPIO.IN) GPIO.setup(prt_i4,GPIO.IN) GPIO.setup(prt_ro1,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro2,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro3,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro4,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo1,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo2,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo3,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo4,GPIO.OUT,initial=GPIO.LOW) else: status = portio.ioperm(lptaddresses[lpt_prt],1,1) if status: writetodebuglog("e","ERROR #17: Cannot access I/O port:" + str(hex(lptaddresses[lpt_prt])) + "!") sys.exit(17) status = portio.ioperm(lptaddresses[lpt_prt] + 1,1,1) if status: writetodebuglog("e","ERROR #17: Cannot access I/O port:" + str(hex(lptaddresses[lpt_prt] + 1)) + "!") sys.exit(17) portio.outb(0,lptaddresses[lpt_prt])
def inicializate(self): error = False try: for register in [self.EC_DATA, self.EC_SC]: status = portio.ioperm(register, 1, 1) if status: error = True logger.error('ioperm:', os.strerror(status)) else: logger.info('acces to :' + str(hex(register))) if error: return False else: return True except TypeError as te: logger.error(te) return False
def __init__(self): if portio.ioperm(0x123, 1, 1): raise Exception("Could not gain IO permissions!") self.value = 0 portio.outb(self.value, 0x123)
#!/usr/bin/env python import sys, time, os import portio if os.getuid(): print 'you need to be root! Exiting.' sys.exit() status = portio.ioperm(0xEE0, 1, 1) if status: print 'ioperm:', os.strerror(status) sys.exit() while 1: ignition = portio.inb(0x0EE0) & 4 if ignition == 4: print 'ignition ok', ignition time.sleep(60) else: os.system("shutdown now -h")
#!/usr/bin/python3 import portio portio.iopl(3) portio.ioperm(0x2E, 2, 1) portio.outb_p(0x87, 0x2E) portio.outb_p(0x01, 0x2E) portio.outb_p(0x55, 0x2E) portio.outb_p(0x55, 0x2E) portio.outb_p(0x07, 0x2E) portio.outb_p(0x03, 0x2F) portio.outb_p(0xF0, 0x2E) f = portio.inb_p(0x2F) f ^= 0x08 portio.outb_p(f, 0x2F)
# # Distributed under the terms of the GNU General Public License (GPL). # This program 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. # # This program 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 portio # init that stuff status_a = portio.ioperm(0x378, 1, 1) status_b = portio.ioperm(0x379, 1, 1) if status_a and status_b: print 'ioperm 0x378:', os.strerror(status_a) print 'ioperm 0x379:', os.strerror(status_b) sys.exit() portio.outb(0x0, 0x378) # output the button box to standard out while True: print portio.inb(0x379)
GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(prt_i1,GPIO.IN) GPIO.setup(prt_i2,GPIO.IN) GPIO.setup(prt_i3,GPIO.IN) GPIO.setup(prt_i4,GPIO.IN) GPIO.setup(prt_ro1,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro2,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro3,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_ro4,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo1,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo2,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo3,GPIO.OUT,initial=GPIO.LOW) GPIO.setup(prt_lo4,GPIO.OUT,initial=GPIO.LOW) else: status = portio.ioperm(lptaddresses[lpt_prt],1,1) if status: print("ERROR #17: Cannot access I/O port:",hex(lptaddresses[lpt_prt])); sys.exit(17) status = portio.ioperm(lptaddresses[lpt_prt] + 1, 1, 1) if status: print("ERROR #17: Cannot access I/O port:",hex(lptaddresses[lpt_prt] + 1)); sys.exit(17) portio.outb(0,lptaddresses[lpt_prt]) while True: print(" * What do you like?") selection = input(" \ 1: Check I1-4 inputs\n \ 2: Check RO1-4 relay contact outputs\n \ 3: Check LO1-4 open collector outputs\n \
def start(self): status = portio.ioperm(self.base_addr, 24, 1) if status: raise Exception('ioperm: '+os.strerror(status))
# # 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 for ever 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