def __init__(self): self._data = 0xFF self.mode = 0 #commands are bit flipped self.CMD_WRITE_ENABLE = 0x60 #0x06 self.CMD_WRITE_DISABLE= 0x20 #0x04 self.CMD_READ_STATUS=0xA0 #0x05 self.CMD_READ_BYTES=0xC0 #0x03 self.CMD_READ_ID=0xD5 #0xAB self.CMD_WRITE_STATUS=0x80 #0x01 self.CMD_WRITE_BYTES=0x40 #0x02 self.CMD_ERASE_BULK=0xE3 #0xC7 self.CMD_ERASE_SECTOR=0x1B #0xD8 if sys.platform=='win32': try: import parallel except ImportError: print "Can't find pyparallel module" print "pyparallel is available at: " print "http://pyserial.sourceforge.net/pyparallel.html" print "Supports Windows NT/2k/XP trough giveio.sys" sys.exit() self.pport = parallel.Parallel() else: try: import parallel except ImportError: print "Can't find pyparallel module" print "pyparallel is available at: " print "http://pyserial.sourceforge.net/pyparallel.html" print "Supports Linux trough ppdev driver" sys.exit() self.pport = parallel.Parallel()
def __init__(self, W=256, H=64, dev=0, fastwrite=True): p = parallel.Parallel(dev) self.setWR = p.setDataStrobe # pin 1 self.setCD = p.setAutoFeed # pin 14 self.setRD = p.setInitOut # pin 16 self.setCS = p.setSelect # pin 17 self.setRD(1) self.setData = p.setData # pins 2-9 self.W = W self.H = H # enable the fast write if using the default wiring and the C library is installed self.sendData = self.slowData if fastwrite: try: assert self.setWR == p.setDataStrobe assert self.setCD == p.setAutoFeed from ctypes import cdll from sys import prefix self._pydisplay = cdll.LoadLibrary( prefix + '/lib/python/site-packages/_pydisplay.so') self.fd = p._fd self.sendData = self.fastData print 'gu300: using fast I/O library' except: self.sendData = self.slowData print 'gu300: fast I/O library not available, using pyparallel' self.init()
def __init__(self, port=0): """Create a parallel port input and output. Parameters: ----------- port : int, optional The port to use (default=0). """ if not isinstance(parallel, ModuleType): message = """SimpleParallelPort can not be initialized. The Python package 'pyParallel' is not installed.""" raise ImportError(message) if float(parallel.VERSION) < 0.2: raise ImportError("Expyriment {0} ".format(__version__) + "is not compatible with PyParallel {0}.".format( parallel.VERSION) + "\nPlease install PyParallel 0.2 or higher.") Input.__init__(self) Output.__init__(self) self._port = port self._parallel = parallel.Parallel(self._port) self.input_history = False # dummy
def get_available_ports(): """Return an array of strings representing the available parallel ports. If pyparallel is not installed, 'None' will be returned. Returns ------- ports : list array of strings representing the available parallel ports """ if not isinstance(parallel, ModuleType): return None ports = [] if platform.startswith("linux"): #for Linux operation systems dev = listdir('/dev') for p in dev: if p.startswith("parport"): ports.append(p) elif platform == "dawin": #for MacOS pass else: #for windows, os2 for p in range(256): try: p = parallel.Parallel(p) ports.append("LTP{0}".format(p + 1)) except: pass ports.sort() return ports
def open_door(self): """ Opens the door No big deal, just opens it with the parallel port """ # Abrir el puerto paralelo try: port = parallel.Parallel() # Depending on the number given to setData(.) it will turn a number # pins, translating the number passed as a parameter into binary. # # D0 D1 D2 D3 D4 D5 D6 D7 # 1 2 4 8 16 32 64 128 # # For example, giving a '3' will turn on both D0 and D1, and giving # '8' will only turn on de D3 # This is hardware related! port.setData(int(self.config['pin'])) # Make this a config option? sleep(5) # Apagando.... port.setData(0) except e: #-- Error al abrir el puerto paralelo logger.error("Error al abrir puerto (%s)\n") sys.exit(e)
def __init__(self, W=256, H=64, dev=0): p = parallel.Parallel(dev) # don't like this wiring? change it! self.setWR = p.setDataStrobe # pin 1 self.getRDY = p.getInBusy # pin 11 self.setData = p.setData # pins 2-9 self.W = W self.H = H # enable the fast write if using the default wiring and the C library is installed try: assert self.setWR == p.setDataStrobe assert self.getRDY == p.getInBusy from ctypes import cdll from sys import prefix self._pydisplay = cdll.LoadLibrary( prefix + '/lib/python/site-packages/_pydisplay.so') self.write = self.fastWrite self.fd = p._fd print 'gu3900: using fast I/O library' except: self.write = self.slowWrite print 'gu3900: fast I/O library not available, using pyparallel' self.init()
def pre_mainloop(self): """ Initialize non-modifiable variables. Users should not modify variables within this region unless they are certain of what they are doing. """ self._init_pygame() time.sleep(2) self.current = datetime.now() self.ANTIALIAS = 1 self.COUNTDOWN = 0 self.fps = 60 self.CUE, self.PREDELAY, self.STIM, self.POSTDELAY = 1, 2, 3, 4 self.sequence = BCI.wordlist(os.path.normpath(self.wordPath)) self.currentTick = 1 self.currentStim = 0 # Current number of stimulus self.nSym = len(self.sequence) # Number of symbols self.nStim = int(self.nSym) # Total number of stimuli self.screenCenter = (self.screenPos[2] / 2, self.screenPos[3] / 2) self.state = self.COUNTDOWN self.state_finished = False self.p = parallel.Parallel() dir = os.path.dirname( sys.modules[__name__].__file__) # Get current dir self.sound = pygame.mixer.Sound(dir + "/Tone.wav") self.stimTime = BCI.fpsConvert( self.stimLen, self.fps ) #BCI.fpsConvert(100,self.fps) # How long the stimulus is displayed (in frames) self.preDelayTime = BCI.fpsConvert( self.preDelayLen - 30, self.fps ) # How long to wait before response is accepted # How long to wait before response is accepted self.postDelayTime = BCI.fpsConvert( self.postDelayLen - 30, self.fps) #Gives 1500 when predelay set at 90 self.cueTime = BCI.fpsConvert(self.cueLen, self.fps)
def __init__(self, portNum=0, pins={ 'data': 0, 'clock': 2, 'latch': 3 }, dummyModeOk=False, numChannels=1): """ If dummyModeOk is set, a failure to open the parallel port will be ignored, and further output commands will have no effect. This might be useful for testing. """ try: self.port = parallel.Parallel(port=portNum) except (OSError, AttributeError): if not dummyModeOk: raise self.port = DummyPort() self.port.setData(0) self._dataVal = 1 << pins['data'] self._clockVal = 1 << pins['clock'] self._latchVal = 1 << pins['latch'] self.numChannels = numChannels self.otherBits = 0 # always sent to the port
def prepare(self): """ Prepare the item. In this case this means doing little. """ # Pass the word on to the parent item.item.prepare(self) # get the global pp instance and initialize it if # necessary global _pp if _pp is None: try: _pp = parallel.Parallel() except OSError: warnings.warn("Could not access /dev/parport0.") self.pp = _pp # This function prepares a self._duration_func() function based # on the compensation and duration variables. self.prepare_duration() # Report success return True
def __init__(self): super(LedThread, self).__init__() self.blinkOn = False self.sleep = 0 if platform.release() == "XP": self._pport = parallel.Parallel() else: self._pport = None
def create_eeg_port(): try: import parallel port = parallel.Parallel() port.setData(0x00) return port except: raise Exception("Can't connect to EEG")
def open(self): import parallel try: self.port = parallel.Parallel(port=self.portNum) except IOError: print "may need 'rmmod lp'" raise self.device = self.port.device
def __init__(self, port): """Initialise the ParallelStream.""" if not parallel: raise IOError('PySerial Parallel module not found. Parallel port communication not available.') try: self._parallel = parallel.Parallel(port) except TypeError: raise IOError('Invalid port specification.') self._port = port
def setUp(self): try: from mpi4py import MPI comm = MPI.COMM_WORLD self.num_MPI_workers = comm.Get_size() self.rank = comm.Get_rank() except ImportError: self.num_MPI_workers = 1 self.rank = 0 self.my_parallel = parallel_mod.Parallel()
def __init__(self, value=0xFF, port=0): '''Opens port and sets data.''' self.data = self.ON if value else self.OFF try: self.port = parallel.Parallel("/dev/parport{}".format(int(port))) except IOError: import sys print("\n\nplease read the NOTE in the program docstring\n\n", file=sys.stderr) raise self.port.setData(self.data)
def __init__(self, hostname='127.0.0.1', port=4444, blocksize=4096): self.port = parallel.Parallel() self.port.setData(self.RESET_PORT) self.sock = socket(AF_INET, SOCK_STREAM) self.sock.connect((hostname, port)) self.blocksize = blocksize self.in_block = False self.num_blocks = 0 self.mode = None
def __init__(self, devname): dataRegAdr = int(devname[4:], 16) self.parport = parallel.Parallel( ) #parallel.Parallel( int( devname[4:], 16 ) ) # pyParallel is stupid in that it does not allow non standard port numbers # so this does what the constructor should do .. self.parport.dataRegAdr = dataRegAdr self.parport.statusRegAdr = dataRegAdr + 1 self.parport.ctrlRegAdr = dataRegAdr + 2 self.parport.ctrlReg = windll.simpleio.inp(self.parport.ctrlRegAdr)
def __init__(self, W=40, dev=0): p = parallel.Parallel(dev) self.setWR = p.setDataStrobe # pin 1 self.getBusy = p.getInBusy # pin 11 self.setCS = p.setAutoFeed # pin 14 self.setData = p.setData # pins 2-9 self.W = W self.init()
def getDevices(): import parallel available = [] if not 'parallel' in dir(): sys.stderr.write('pyParallel is not installed\n') else: for i in range(4): try: p = parallel.Parallel(i) available.append('%s%d' % (InterfaceName, i + 1)) del (p) except: pass return available
def __init__(self, dev=0): p = parallel.Parallel(dev) self.setA0 = p.setAutoFeed # pin 14 self.setE1 = p.setInitOut # pin 16 self.setE2 = p.setSelect # pin 17 self.setData = p.setData # pins 2-9 self.W = 122 self.H = 32 self.init()
def __init__(self, dev=0): if USE_FCNTL: self.fd = os.open('/dev/parport%d' % dev, os.O_RDWR) fcntl.ioctl(self.fd, 0x708F) # mark parport as exclusive fcntl.ioctl(self.fd, 0x708B) # claim the parport else: import parallel p = parallel.Parallel(dev) self.setWR = p.setDataStrobe # pin 1 self.getBUSY = p.getInBusy # pin 11 self.setData = p.setData # pins 2-9 self.setWR(1) self.init()
def main(): para = parallel.Parallel() monitor = PeakMonitor(SINK_NAME, METER_RATE) for sample in monitor: sample = sample >> DISPLAY_SCALE if sample > 18: para.setData(0x3) else: if sample > 18: para.setData(0x3) else: para.setData(0x0) bar = '>' * sample spaces = ' ' * (MAX_SPACES - sample) print ' %3d %s%s\r' % (sample, bar, spaces), sys.stdout.flush()
def __init__(self, W=128, H=64, dev=0): p = parallel.Parallel(dev) # don't like this wiring? change it! self.setCS1 = p.setDataStrobe # pin 1 self.setCS2 = p.setAutoFeed # pin 14 self.setE = p.setInitOut # pin 16 self.setRS = p.setSelect # pin 17 self.setData = p.setData # pins 2-9 self.W = W self.H = H self.init()
def __init__(self, address='/dev/parport0'): """Set the device node of your parallel port common port addresses:: LPT1 = /dev/parport0 LPT2 = /dev/parport1 LPT3 = /dev/parport2""" import parallel as pyp if not hasattr(pyp, 'Parallel'): # We failed to import pyparallel properly # We probably ended up with psychopy.parallel instead... raise Exception('Failed to import pyparallel - is it installed?') self.port = pyp.Parallel(address)
def __init__(self, W=40, dev=0): p = parallel.Parallel(dev) # don't like this wiring? change it! self.setWR = p.setDataStrobe # pin 1 self.setA0 = p.setAutoFeed # pin 14 self.setRD = p.setInitOut # pin 16 self.setCS = p.setSelect # pin 17 self.setData = p.setData # pins 2-9 self.W = W self.RD = 1 self.init()
def __init__(self, dev=0): self.W = 280 self.H = 120 p = parallel.Parallel(dev) p.setAutoFeed(0) p.setInitOut(0) p.setSelect(0) # don't like this wiring? change it! self.setWR = p.setDataStrobe # pin 1 self.getBUSY = p.getInBusy # pin 11 self.setData = p.setData # pins 2-9 self.init()
def __init__(self, port_num=None): """ Initializes the feedback. You should not override this method, override on_init instead. If you must override this method, make sure to call ``Feedback.__init__(self, pp)`` before anything else in your overridden __init__ method. """ self._data = None self.logger = logging.getLogger("FB." + self.__class__.__name__) """Inherited by all sub classes. Use this for logging.""" self.logger.debug("Loaded my logger.") # Setup the parallel port self._pport = None if sys.platform == 'win32': try: from ctypes import windll self._pport = windll.inpout32 except: self.logger.warning( "Could not load inpout32.dll. Please make sure it is located in the system32 directory" ) else: try: import parallel self._pport = parallel.Parallel() except: self.logger.warning( "Unable to open parallel port! Please install pyparallel to use it." ) if port_num != None: self._port_num = port_num # used in windows only'' else: self._port_num = 0x378 self._playEvent = Event() self._shouldQuit = False # Initialize with dummy values so we cann call safely .cancel self._triggerResetTimer = Timer(0, None) self._triggerResetTime = 0.01 self.udp_markers_host = '127.0.0.1' self.udp_markers_port = 12344
def _parallel(self, **kwargs): try: self.parallel = parallel.Parallel() except Exception as ex: self.stdout.write(self.style.ERROR('Parallel port not detected')) self.stdout.write(self.style.ERROR(str(ex))) return for pin in range(8): Actuator.objects.get_or_create(name='parport-d%d' % pin, defaults={ 'strategy': 'iot.parport.DataPin', 'strategy_options': { 'pin': pin } }) self.stdout.write( self.style.SUCCESS('Parallel port detected successfully'))
def __init__(self, port=None): """Interface to the CRS 'AudioFile' device. Parameters ---------- port: int or None, optional The `port` value, as required by `pyparallel`. """ if not parallel_imported: raise ImportError("Could not import pyparallel") if port is None: port = 0 self._device = parallel.Parallel(port=port) self.play = self.trigger self.start = None self.stop = None
def __init__(self): self.p = parallel.Parallel() self.data = 0 self.out(0) #reset pins time.sleep(0.050) #wait more than 30ms #send the reset sequece (3 times the same pattern) self.out(LCD8BITS) #set 8 bit interface self.toggleE() #toggle LCD_E, the enable pin time.sleep(0.005) #wait a bit self.toggleE() #toggle LCD_E, the enable pin time.sleep(0.005) #wait a bit self.toggleE() #toggle LCD_E, the enable pin time.sleep(0.005) #wait a bit self.out(LCD4BITS) #now set up the 4 bit interface self.toggleE() #toggle LCD_E, the enable pin time.sleep(0.002) #wait until instr is finished self.instr(LCD2LINES) #set 2 lines display self.instr(LCDCURSOROFF) #hide cursor self.instr(LCDCLEAR) #clear display