'''
2011-08-07 Erik Chang
	- for reading/writing mcc triggers with PyUniversalLibrary
	- completing the reading part first
'''

import UniversalLibrary as UL
from psychopy import core

class dio(object):
	def __init__(self, dir, BoardNum):
		UL.cbDConfigPort(BoardNum, UL.FIRSTPORTA, dir)
		UL.cbDConfigPort(BoardNum, UL.FIRSTPORTB, dir)
		
		#self.BitID = BitID
		self.BoardNum = BoardNum
		
	def read(self):
		#data  = UL.cbDBitIn(self.BoardNum, UL.FIRSTPORTA, self.BitID, 0)
		data  = UL.cbDIn(self.BoardNum, UL.FIRSTPORTA, 0)
		return data

		'''
		cbDBitIn(int BoardNum, int PortType, 
			int BitNum, 
			unsigned short *BitValue)

		this function treats all of the DIO ports 
		of a particular type on a board as a single port. 
		It lets you read the state of any individual bit 
		within this port. 
		
		
		
		'''
		
	def write(self, outvalue):
		#UL.cbDBitOut(self.BoardNum, UL.FIRSTPORTA, self.BitID, outvalue)
		UL.cbDOut(self.BoardNum, UL.FIRSTPORTA, outvalue)
'''		
	#This function will read from all lines of PortB		
	def portread(self):
		data  = UL.cbDIn(self.BoardNum, UL.FIRSTPORTB, 0)
		return data

	def portwrite(self, outvalue):
		data  = UL.cbDOut(self.BoardNum, UL.FIRSTPORTB, outvalue)
		return data
'''