Source code for analogOut

from pypixxlib._libdpx import DPxGetDacNumChans, DPxSetDacValue, \
    DPxGetDacValue, DPxGetDacRange, DPxGetDacVoltage, DPxSetDacVoltage, \
    DPxEnableDacBuffChan, DPxDisableDacBuffChan, DPxIsDacBuffChan, \
    DPxEnableDacCalibRaw, DPxDisableDacCalibRaw, DPxIsDacCalibRaw, \
    DPxSetDacBuffBaseAddr, DPxGetDacBuffBaseAddr, DPxSetDacBuffReadAddr, \
    DPxGetDacBuffReadAddr, DPxSetDacBuffSize, DPxGetDacBuffSize, \
    DPxSetDacSchedOnset, DPxGetDacSchedOnset, DPxSetDacSchedRate, \
    DPxGetDacSchedRate, DPxSetDacSchedCount, DPxGetDacSchedCount, \
    DPxEnableDacSchedCountdown, DPxDisableDacSchedCountdown, \
    DPxIsDacSchedCountdown, DPxStartDacSched, DPxStopDacSched, \
    DPxIsDacSchedRunning, DPxDisableDacBuffAllChans, DPxWriteDacBuffer, \
    DPxSetDacSchedule, DPxGetDacStatus
    
from abc import ABCMeta
from pypixxlib.schedule import Schedule
from pypixxlib.dpxDevice import DpxExceptionDecorate


[docs]class AnalogOut(Schedule, metaclass=ABCMeta): """Class which implements the DAC features. It contains all the necessary methods to use the analog outputs of a VPixx device. """
[docs] @DpxExceptionDecorate def getNbrOfChannel(self): """Gets the number of channels available. Returns: int: Number of channels. """ return DPxGetDacNumChans()
[docs] @DpxExceptionDecorate def setChannelValue(self, value, channel): """Sets the current value of a channel. This method allows the user to modify the output value of a given channel. Args: value (int): Value of the channel. It is a 16-bit 2's complement signed number. channel (int): Channel number. See Also: :class:`getChannelValue` """ DPxSetDacValue(value, channel)
[docs] @DpxExceptionDecorate def getChannelValue(self, channel): """Gets the current value of a channel. This method allows the user to know the value of a given channel. The return value is a 16-bit 2's complement signed number. Value can be obtained for channels 0 to 17. Returns: int: value of the channel. See Also: :class:`setChannelValue` """ return DPxGetDacValue(channel)
[docs] @DpxExceptionDecorate def getChannelRange(self, channel): """Gets the range of a channel. Returns: tuple: Range of the channel. The returned value is a tuple with the minimum range followed by the maximum range. Both values are integers. """ return DPxGetDacRange(channel)
[docs] @DpxExceptionDecorate def getChannelVoltage(self, channel): """Gets the current voltage of a channel. Returns: float: voltage of the channel. See Also: :class:`setChannelVoltage` """ return DPxGetDacVoltage(channel)
[docs] @DpxExceptionDecorate def setChannelVoltage(self, voltage, channel): """Sets the current Voltage of a channel. This method allows the user to modify the output voltage of a given channel. The voltage is +-10V for channels 0 and 1, and +-5V for channels 2 and 3. Args: voltage (float): Value of the channel. channel (int): Channel number. See Also: :class:`getChannelVoltage` """ DPxSetDacVoltage(voltage, channel)
[docs] @DpxExceptionDecorate def setChannelRamBuffering(self, enable, channel=None): """Sets the ram buffering mode. This method allows the user to enable or disable ram buffering on a given channel. When enabled, a given channel is buffered in ram. Enabling RAM buffering can only be done for channels 0 to 15. Args: enable (Bool): True if hardware calibration is enabled, False otherwise. channel (int): Channel number to enable or disable. Passing None will set all channels. See Also: :class:`isChannelRamBuffering` """ all_channels = 16 if enable == True: if channel == None: for i in range(all_channels): DPxEnableDacBuffChan(i) else: DPxEnableDacBuffChan(channel) else: if channel == None: DPxDisableDacBuffAllChans() else: DPxDisableDacBuffChan(channel)
[docs] @DpxExceptionDecorate def isChannelRamBuffering(self, channel): """Verifies the ram buffering mode. This method allows the user to know if a ram buffering is enabled for a given channel. Args: channel (int): Channel number to query. Returns: Bool: True if the given channel is buffered, False otherwise. See Also: :class:`setChannelRamBuffering` """ if DPxIsDacBuffChan(channel) == 0: enable = False else: enable = True return enable
[docs] @DpxExceptionDecorate def setHardwareCalibration(self, enable): """Sets the hardware calibration mode. This method allows the user to enable or disable the hardware calibration mode. When enabled, the ADC data bypasses the hardware calibration. When disabled, the ADC data passes by the hardware calibration. Args: enable (Bool): True if hardware calibration is enabled, False otherwise. See Also: :class:`isHardwareCalibration` """ if enable == True: DPxEnableDacCalibRaw() else: DPxDisableDacCalibRaw()
[docs] @DpxExceptionDecorate def isHardwareCalibration(self): """Verifies the hardware calibration mode. Returns: Bool: True if hardware calibration is enabled, False otherwise. See Also: :class:`setHardwareCalibration` """ if DPxIsDacCalibRaw() == 0: enable = False else: enable = True return enable
[docs] @DpxExceptionDecorate def setBaseAddress(self, address): """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. See Also: :class:`getReadAddress`, :class:`setReadAddress`, :class:`getBaseAddress` """ DPxSetDacBuffBaseAddr(address)
[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. See Also: :class:`getReadAddress`, :class:`setReadAddress`, :class:`setBaseAddress` """ return DPxGetDacBuffBaseAddr()
[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 the schedule to know where the data should be first read from. The schedule 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. See Also: :class:`getReadAddress`, :class:`getBaseAddress` """ DPxSetDacBuffReadAddr(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. See Also: :class:`setReadAddress`, :class:`getBaseAddress` """ return DPxGetDacBuffReadAddr()
[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. See Also: :class:`getBufferSize` """ DPxSetDacBuffSize(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. See Also: :class:`setBufferSize` """ return DPxGetDacBuffSize()
[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. See Also: :class:`getScheduleUnit`, :class:`getScheduleRate`, :class:`setScheduleRate` """ DPxSetDacSchedOnset(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. See Also: :class:`getScheduleUnit`, :class:`getScheduleRate`, :class:`setScheduleRate` """ return DPxGetDacSchedOnset()
[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. Args: rate (int): Any positive value equal to or greater than 0. unit (str): hz : samples per second, maximum 1 MHz. video : samples per video frame, maximum 1 MHz. nano : sample period in nanoseconds, minimum 1000 ns. See Also: :class:`getScheduleUnit`, :class:`getScheduleRate`, :class:`getScheduleOnset` """ DPxSetDacSchedRate(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. See Also: :class:`getScheduleUnit`, :class:`setScheduleRate`, :class:`getScheduleOnset` """ schedule_rate = DPxGetDacSchedRate() 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 = DPxGetDacSchedRate() 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 samples. 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` """ DPxSetDacSchedCount(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 DPxGetDacSchedCount()
[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: DPxEnableDacSchedCountdown() else: DPxDisableDacSchedCountdown()
[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 DPxIsDacSchedCountdown() !=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` """ DPxStartDacSched()
[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 required to stop the schedule. See Also: :class:`startSchedule`, :class:`setReadAddress`, :class:`setBaseAddress`, :class:`setScheduleOnset`, :class:`setScheduleRate`, :class:`setScheduleCountDown`, :class:`setScheduleCount` """ DPxStopDacSched()
[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 DPxIsDacSchedRunning() == 0: schedule_running = False else: schedule_running = True return schedule_running
[docs] @DpxExceptionDecorate def writeBuffer(self, bufferData, bufferAddress=0, channelList=None): """Writes the data that will be used by the DAC buffer to drive the analogue outputs. Args: bufferData (multi-dimension list): nChans x nFrame list where each row of the matrix contains the sample data for one DAC channel. Each column of the list contains one sample for each DAC channel. bufferAddress (int): The byte address in Datapixx RAM where the buffer should start. Default value of zero. Streaming value of -1 not implemented yet. channelList (list): channelList by default is channel 0...nChans channels. If provided, it needs to be a list of size nChans. Returns: int: nextBufferAddress, the next address availible to write to memory after the DAC buffer. """ DPxWriteDacBuffer(bufferData, bufferAddress, channelList)
[docs] @DpxExceptionDecorate def setSchedule(self, scheduleOnset, scheduleRate, rateUnits, maxScheduleFrames, channelList=None, bufferBaseAddress=0, numBufferFrames=None): """Configure a schedule for autonomous DAC analog signal acquisition. This function is used to fully setup an acquisition schedule on the device. Regardless of the actual format chosen, the resulting sample rate cannot exceed 1 MHz. It returns a dictionary that is needed when reading data or updating the buffer. Use ReadAdcBuffer to upload the acquired data from this address after calling StartAdcSchedule. Note that every call to StartAdcSchedule must be preceeded by a call to SetAdcSchedule (ie: multiple calls to StartAdcSchedule each require their own call to SetAdcSchedule). Args: onSet (float): The desired delay (in double precision seconds) between schedule initiation, and the first ADC sample acquisition. rateValue (int): The rate at which the ADC's acquire successive samples. rateUnits (str): This can have three values: "Hz" for samples/seconds, "video" for samples/video frame or "nano" for seconds/samples maxScheduleFrames (int): If the dataset has a known length, then maxScheduleFrames should be that number. If it is a dynamic length, pass 0. channelList (list): List of the DAC channels which should be updated from the waveform buffer. The list should contain 1 or more integers in the range 0 toGetDacNumChannels-1. bufferBaseAddress (int): The start of the RAM buffer which should hold the acquired data inside the Datapixx. Default value is 4e6. numBufferFrames (int): Specifies the desired size of the acquisition buffer in the Datapixx RAM. Default value of maxScheduleFrames. If maxScheduleFrames is larger than numBufferFrames (or 0), then each time the acquisition frame counter reaches a multiple of numBufferFrames, the acquisition buffer address automatically wraps back to bufferBaseAddress. This circular buffer effect can be used for acquiring arbitrarily long analog datasets. Simply monitor newBufferFrames returned by GetAdcStatus, and use ReadAdcBuffer in streaming mode to upload newly acquired data from the Datapixx RAM to the host. Returns: DACDictionary (dict): Returns a dictionary which has some global information which must be passed to other DAC functions. """ DPxSetDacSchedule(scheduleOnset, scheduleRate, rateUnits, maxScheduleFrames, channelList, bufferBaseAddress, numBufferFrames)
[docs] @DpxExceptionDecorate def getStatus(self, inDict): """Updates the information dictionary for the DAC schedule. Args: inDict (dict): The dictionary returned by the schedule setup Updates the dictionary with the following information: "scheduleRunning" is True if the DAC schedule is currently running, or False if stopped. "scheduleOnset" is the programmed delay in seconds between StartAdcSchedule execution, and the first ADC sample acquisition. "scheduleRate" is the rate at which subsequent ADC samples are acquired. "scheduleRateUnits" is the programmed units of scheduleRate: "Hz" is samples per second, "video" is samples per video frame, "nano" is seconds per sample "numDacSchedChans" is the number of ADC channels scheduled for acquisition. "channelList" is the list of channels and their reference, if enabled. "bufferBaseAddress" is the acquisition data buffer base address within the Datapixx. "bufferSize" is the number of bytes in the acquisition data buffer. "numBufferFrames" is the total number of samples which fit in the acquisition data buffer. "currentReadFrame" is the buffer frame which will be read by the next streaming call to ReadAdcBuffer. "maxScheduleFrames", if non-0, is the value of currentWriteFrame which will automatically stop the schedule. """ DPxGetDacStatus(inDict)