Source code for digitalOut

from pypixxlib._libdpx import DPxGetDoutNumBits, DPxSetDoutValue, \
    DPxGetDoutValue, DPxEnableDoutButtonSchedules, DPxDisableDoutButtonSchedules, \
    DPxIsDoutButtonSchedules, DPxEnableDoutBacklightPulse, \
    DPxDisableDoutBacklightPulse, DPxIsDoutBacklightPulse, \
    DPxSetDoutBuffBaseAddr, DPxGetDoutBuffBaseAddr, DPxSetDoutBuffReadAddr, \
    DPxGetDoutBuffReadAddr, DPxSetDoutBuffSize, DPxGetDoutBuffSize, \
    DPxSetDoutSchedOnset, DPxGetDoutSchedOnset, DPxSetDoutSchedRate, \
    DPxGetDoutSchedRate, DPxSetDoutSchedCount, DPxGetDoutSchedCount, \
    DPxEnableDoutSchedCountdown, DPxDisableDoutSchedCountdown, \
    DPxIsDoutSchedCountdown, DPxStartDoutSched, DPxStopDoutSched, DPxIsDoutSchedRunning, \
    DPxEnableDoutPixelMode, DPxDisableDoutPixelMode, DPxIsDoutPixelMode, \
    DPxEnableDoutPixelModeGB, DPxDisableDoutPixelModeGB, DPxIsDoutPixelModeGB, \
    DPxTriggerToRGB, DPxRGBToTrigger, DPxGetVidVFreq, DPxSetDoutSched, DPxSetDoutSchedule, \
    DPxWriteDoutBuffer
from abc import ABCMeta
from pypixxlib.schedule import Schedule
from pypixxlib.dpxDevice import DpxExceptionDecorate
import sys

[docs]class DigitalOut(Schedule, metaclass=ABCMeta): """The Dout class is used to set and get all values related to the Dout. """ @DpxExceptionDecorate def __init__(self): pass
[docs] @DpxExceptionDecorate def getNbrOfBit(self): """Gets the number of bits available. Returns: int: Number of bits. """ return DPxGetDoutNumBits()
[docs] @DpxExceptionDecorate def setBitValue(self, value, bit_mask): """ Sets the value of the bits. This method allows the user to set the bit value for the subsystem. The mask is one value representing all bits from the port. The given bit_mask will set the direction of all digital input bits. For each bit which should drive its port, the corresponding bit_mask value should be set to 1. For example, ``bit_mask = 0x0000F`` will enable the port for the first 4 bits on the right. All other ports will be disabled. User can then use the first 4 bits to drive the port. Args: value (int): value of bits. bit_mask (int): Set bit to 1 will enable the port for that bit. Set bit to 0 will disable it. See Also: :class:`getBitValue` """ DPxSetDoutValue(value, bit_mask)
[docs] @DpxExceptionDecorate def getBitValue(self): """Gets the current value of the bits. Returns: int: value of bit. See Also: :class:`setBitValue` """ return DPxGetDoutValue()
[docs] @DpxExceptionDecorate def setButtonSchedules(self, enable): """Sets the schedule start on button press mode. This method allows the user to enable or disable the transition log events on acquired data. When enabled, digital output schedules are done following a digital input button press. When disabled, digital output schedules have to be started manually. Args: enable (Bool): True to activate the log event mode, False otherwise. See Also: :class:`isButtonSchedulesEnabled` """ if enable == True: DPxEnableDoutButtonSchedules() else: DPxDisableDoutButtonSchedules()
[docs] @DpxExceptionDecorate def isButtonSchedulesEnabled(self): """Verifies if the schedule start on button press mode is enabled. Returns: enable (Bool): True if the mode is enabled, False otherwise. See Also: :class:`setButtonSchedules` """ if DPxIsDoutButtonSchedules() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def setBacklightPulse(self, enable): """Sets the back light pulse mode. This method allows the user to enable or disable the back light pulse mode. When enabled, the LCD back light LEDs are gated by bit 15 of the digital output. It can be used to make a tachistoscope by pulsing bit 15 of the digital output with a schedule. When disabled, the outputs work normally and are unaffected. Args: enable (Bool): True to activate the back light pulse mode, False otherwise. See Also: :class:`isBacklightPulseEnabled` """ if enable == True: DPxEnableDoutBacklightPulse() else: DPxDisableDoutBacklightPulse()
[docs] @DpxExceptionDecorate def isBacklightPulseEnabled(self): """Verifies if the back light pulse mode is enabled. Returns: enable (Bool): True if back light pulse mode is enabled, False otherwise. See Also: :class:`setBacklightPulse` """ if DPxIsDoutBacklightPulse() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def setBaseAddress(self, value): """Sets the Ram buffer start address. This method allows the user to set the RAM buffer start address used in schedules. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ return DPxSetDoutBuffBaseAddr(value)
[docs] @DpxExceptionDecorate def getBaseAddress(self): """Gets the Ram buffer start address. This method allows the user to get the RAM buffer start address used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use setBufferSize() Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetDoutBuffBaseAddr()
[docs] @DpxExceptionDecorate def setReadAddress(self, address): """Sets the Ram buffer read address. This method allows the user to set the RAM buffer read address used in schedules. This address is used by schedule to know where the data should be first read from. The schedules will then read the following data to the address following the RAM buffer read address. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ DPxSetDoutBuffReadAddr(address)
[docs] @DpxExceptionDecorate def getReadAddress(self): """Gets the Ram buffer read address. This method allows the user to get the RAM buffer read address used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetDoutBuffReadAddr()
[docs] @DpxExceptionDecorate def setBufferSize(self, buffer_size): """Sets the Ram buffer size. This method allows the user to set the RAM buffer size used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use ``setBaseAddress()``. The given size is in bytes and must be an even value. Args: buffer_size (int): Any value in a range of 0 up to the RAM size. """ DPxSetDoutBuffSize(buffer_size)
[docs] @DpxExceptionDecorate def getBufferSize(self): """Gets the Ram buffer size. This method allows the user to get the RAM buffer size used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetDoutBuffSize()
[docs] @DpxExceptionDecorate def setScheduleOnset(self, onset): """Sets the schedule onset value. This method allows the user to set the nanosecond delay between schedule start and first sample. If no delay is required, this method doesn't need to be used. Default value is 0. Args: onset (int): Any positive value equal to or greater than 0. """ DPxSetDoutSchedOnset(onset)
[docs] @DpxExceptionDecorate def getScheduleOnset(self): """Gets the schedule onset value. This method allows the user to get the schedule onset value used in schedules. The onset represents a nanosecond delay between schedule start and first sample. Returns: int: Any positive value equal to or greater than 0. """ return DPxGetDoutSchedOnset()
[docs] @DpxExceptionDecorate def setScheduleRate(self, rate, unit='hz'): """Sets the schedule rate. This method allows the user to set the schedule rate. Since the rate can be given with different units, the method also needs to have a unit associated with the rate. If no delay is required, this method doesn't need to be used. Default value is 0. Args: rate (int): Any positive value equal to or greater than 0. unit (str): hz : rate updates per second, maximum 10 MHz. video : rate updates per video frame, maximum 10 MHz. nano : rate updates period in nanoseconds, minimum 100 ns. """ DPxSetDoutSchedRate(rate, unit)
[docs] @DpxExceptionDecorate def getScheduleRate(self): """Gets the schedule rate value. This method allows the user to get the schedule rate value used in schedules. The rate represents the speed at which the schedule updates. Returns: int: Any positive value equal to or greater than 0. """ schedule_rate = DPxGetDoutSchedRate() return schedule_rate[0]
[docs] @DpxExceptionDecorate def getScheduleUnit(self): """Gets the schedule unit value. This method allows the user to get the schedule unit value used in schedules. Returns: int: Any positive value equal to or greater than 0. See Also: :class:`getScheduleRate`, :class:`setScheduleRate` """ schedule_unit = DPxGetDoutSchedRate() return schedule_unit[1]
[docs] @DpxExceptionDecorate def setScheduleCount(self, count): """Sets the schedule count. This method allows the user to set the schedule count for a schedule with a fixed number of sample. In which case, the schedule will decrement at a given rate and stop when the count reaches 0. Args: count (int): Any positive value greater than 0. See Also: :class:`getScheduleCount`, :class:`setScheduleCountDown` """ DPxSetDoutSchedCount(count)
[docs] @DpxExceptionDecorate def getScheduleCount(self): """Gets the schedule count value. This method allows the user to get the current count for a schedule. Returns: int: Any positive value equal to or greater than 0. See Also: :class:`setScheduleCount`, :class:`setScheduleCountDown` """ return DPxGetDoutSchedCount()
[docs] @DpxExceptionDecorate def setScheduleCountDown(self, enable): """Sets the schedule count down mode. This method allows the user to enable or disable the count down on a schedule. When enabled, the schedule decrements at the given rate and stops automatically when the count hits 0. When disabled, the schedule increments at the given rate and is stopped by calling stopSchedule(). Args: enable (Bool): True if count down is enabled, False otherwise. See Also: :class:`setScheduleCount`, :class:`stopSchedule`, :class:`isCountDownEnabled` """ if enable == True: DPxEnableDoutSchedCountdown() else: DPxDisableDoutSchedCountdown()
[docs] @DpxExceptionDecorate def isCountDownEnabled(self): """Verifies the schedule count down mode. Returns: enable (Bool): True if the schedule is decrementing at every sample, False otherwise. See Also: :class:`setScheduleCount`, :class:`stopSchedule`, :class:`setScheduleCountDown` """ if DPxIsDoutSchedCountdown() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def startSchedule(self): """Starts a schedule. Schedules may be configured in different ways, affecting their behavior. Before a schedule is started, the user should make sure that it is properly set in the right mode. See Also: :class:`stopSchedule`, :class:`setReadAddress`, :class:`setBaseAddress`, :class:`setScheduleOnset`, :class:`setScheduleRate`, :class:`setScheduleCountDown`, :class:`setScheduleCount` """ DPxStartDoutSched()
[docs] @DpxExceptionDecorate def stopSchedule(self): """Stops the active schedule for a given subsystem. Depending on how the schedules are configured, it may not be necessary to call this method. When a schedule is using a count down, it is not needed to stop the schedule. See Also: :class:`startSchedule`, :class:`setReadAddress`, :class:`setBaseAddress`, :class:`setScheduleOnset`, :class:`setScheduleRate`, :class:`setScheduleCountDown`, :class:`setScheduleCount` """ DPxStopDoutSched()
[docs] @DpxExceptionDecorate def isScheduleRunning(self): """Verifies if a schedule is currently running on the subsystem. Returns: schedule_running (Bool): True if a schedule is currently running, False otherwise. See Also: :class:`startSchedule`, :class:`stopSchedule`, :class:`getScheduleRunningState` """ if DPxIsDoutSchedRunning() == 0: schedule_running = False else: schedule_running = True return schedule_running
[docs] @DpxExceptionDecorate def getScheduleRunningState(self): """Gets the schedule state for the subsystem. Returns: schedule_state (str): "running" if a schedule is currently running, "stopped" otherwise. See Also: :class:`startSchedule`, :class:`stopSchedule`, :class:`isScheduleRunning` """ if DPxIsDoutSchedRunning() == 0: self.schedule_state = "stopped" else: self.schedule_state = "running" return self.schedule_state
[docs] @DpxExceptionDecorate def enablePixelMode(self): """Enables pixel mode. When this function is enabled, the digital outputs show the RGB value of first upper left pixel of the screen. In this case, digital outputs cannot be used for other purposes. This feature is only available on VIEWPixx with firmware revision 31 and higher. Any firmware for DATAPixx3. See Also: :class:`disablePixelMode`, :class:`isPixelModeEnabled` """ DPxEnableDoutPixelMode()
[docs] @DpxExceptionDecorate def disablePixelMode(self): """Disables pixel mode. When this function is disabled, the digital ouputs do not show the RGB value of first upper left pixel of the screen. The digital outputs can then be used normally. This is the default mode. This feature is only available on VIEWPixx with firmware revision 31 and higher. Any firmware for DATAPixx3. See Also: :class:`enablePixelMode`, :class:`isPixelModeEnabled` """ DPxDisableDoutPixelMode()
[docs] @DpxExceptionDecorate def enablePixelModeGB(self): """Enables pixel mode GB. When this function is enabled, the digital output 8-24 show the GB value of first upper left pixel of the screen. In this case, digital outputs 8-24 cannot be used for other purposes, but digital outputs 0-7 can. This feature is only available on VIEWPixx with firmware revision 48 and higher. Any firmware for DATAPixx3. See Also: :class:`disablePixelMode`, :class:`isPixelModeEnabled` """ DPxEnableDoutPixelModeGB()
[docs] @DpxExceptionDecorate def disablePixelModeGB(self): """Disables pixel mode GB. When this function is disabled, the digital ouputs do not show the GB value of first upper left pixel of the screen. The digital outputs can then be used normally. This is the default mode. This feature is only available on VIEWPixx with firmware revision 48 and higher. Any firmware for DATAPixx3. See Also: :class:`enablePixelMode`, :class:`isPixelModeEnabled` """ DPxDisableDoutPixelModeGB()
[docs] @DpxExceptionDecorate def isPixelModeEnabled(self): """Verifies if the pixel mode is enabled on digital outputs. Returns: enable (Bool): True if the mode is enabled, False otherwise. See Also: :class:`enablePixelMode`, :class:`disablePixelMode` """ if DPxIsDoutPixelMode() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def isPixelModeGBEnabled(self): """Verifies if the pixel mode GB is enabled on digital outputs. Returns: enable (Bool): True if the mode is enabled, False otherwise. See Also: :class:`enablePixelMode`, :class:`disablePixelMode` """ if DPxIsDoutPixelModeGB() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def RGBToTrigger(self, color): """Helper function determines expected trigger from a given RGB 255 colour tuple. Returns: int: trigger value in decimal (base 10) :Low-level C definition: none See Also: :class:`enablePixelMode`, :class:`disablePixelMode`, :class:`TriggerToRGB` """ DPxRGBToTrigger(color)
[docs] @DpxExceptionDecorate def TriggerToRGB(self, trigger): """Helper function determines pixel mode RGB 255 colour value based on desired 24-bit trigger (in decimal, base 10) Returns: list: list of containing [R, G, B] in RGB 255 :Low-level C definition: none See Also: :class:`enablePixelMode`, :class:`disablePixelMode`, :class:`RGBToTrigger` """ DPxTriggerToRGB(trigger)
[docs] @DpxExceptionDecorate def setDoutSchedule(self, scheduleOnset, scheduleRate, maxScheduleFrames, bufferAddress=int(8e6), numBufferFrames=None): """ Implements a digital output schedule in a DATAPixx. Mimics the behavior of Datapixx('SetDoutSchedule') in MATLAB. Args: scheduleOnset (float): the audio schedule delay in seconds scheduleRate (int or list): the sampling rate of the digital output schedule in one of several formats: 1) 'scheduleRate' is an integer, specifying the sampling rate in Hertz 2) 'scheduleRate' is a list with 2 elements. the first element is an integer indicating the sampling rate. the second element is either an integer or a string indicating the sampling rate units. allowable values for the second element are in the 'int' and 'str' columns below: int str description 0 'hz' sampling rate specified in Hertz 1 'video' sampling rate specified in DATAPixx video frames 2 'nano' sampling rate specified in nanoseconds NOTE: regardless of the choosen format, sampling rate cannot exceed 10 MHz maxScheduleFrames (int): the number of samples after which the digital output schedule stops sampling. if maxScheduleFrames > numBufferFrames, the digital output schedule loops back to sample datum at the start address of the digital output buffer. bufferAddress (int): memory location in DATAPixx RAM default=int(8e6) numBufferFrames (int): number of digital output schedule samples written into DATAPixx RAM. NOTE: these are specified in bytes, while the data format is int16. therefore, numBufferFrames = maxScheduleFrames*2 default = maxScheduleFrames*2 Exceptions: 1) scheduleOnset is not of type float or is less than 0 2) scheduleOnset is greater than 4.295 seconds 3) scheduleRate does not obey supported format 4) scheduleRate specifies sampling rate greater than 10 MHz, regardless of format 5) maxScheduleFrames is not of type int or is less than 0 6) maxScheduleFrames is zero and numBufferFrames was omitted 7) bufferAddress is not of type int or is less than 0 or is odd 8) numBufferFrames is not of type int or is less than 0 """ ############################## check inputs # check scheduleOnset DPxSetDoutSchedule(scheduleOnset, scheduleRate, maxScheduleFrames, bufferAddress, numBufferFrames)
[docs] def setDoutBuffer(self, bufferData, addr=int(8e6)): """ Writes the digital output waveform data in 'bufferData' to the DATAPixx RAM at memory address 'bufferAddress'. Mimics the behavior of Datapixx('WriteDoutBuffer') in MATLAB. 1) 'bufferData' must be of type int scaled between (0,65535) 2) 'bufferData' can be either a list or a numpy.array 3) 'bufferData' must be shaped as (N,) Args: bufferData (list or numpy.array): contains waveform data. if a list, must be castable to a numeric numpy.array bufferAddress (int): memory location in DATAPixx RAM. default = int(8e6) Exceptions: 1) bufferData cannot be casted into a numpy.array of type int 2) bufferData is empty 3) bufferData has more than 1 dimension 4) bufferAddress is not of type int or is less than 0 or is odd """ DPxWriteDoutBuffer(bufferData, addr)