Source code for analogIn

from pypixxlib._libdpx import DPxGetAdcNumChans, DPxGetAdcValue, \
    DPxGetAdcRange, DPxGetAdcVoltage, DPxSetAdcBuffChanRef, \
    DPxGetAdcBuffChanRef, DPxEnableAdcBuffChan, \
    DPxDisableAdcBuffChan, DPxIsAdcBuffChan, DPxEnableAdcCalibRaw, \
    DPxDisableAdcCalibRaw, DPxEnableDacAdcLoopback, \
    DPxDisableDacAdcLoopback, DPxIsDacAdcLoopback, DPxEnableAdcFreeRun, \
    DPxDisableAdcFreeRun, DPxIsAdcFreeRun, DPxSetAdcBuffBaseAddr, \
    DPxGetAdcBuffBaseAddr, DPxSetAdcBuffWriteAddr, DPxGetAdcBuffWriteAddr, \
    DPxSetAdcBuffSize, DPxGetAdcBuffSize, DPxSetAdcSchedOnset, \
    DPxGetAdcSchedOnset, DPxSetAdcSchedRate, DPxGetAdcSchedRate, \
    DPxSetAdcSchedCount, DPxGetAdcSchedCount, DPxEnableAdcSchedCountdown, \
    DPxDisableAdcSchedCountdown, DPxIsAdcSchedCountdown, DPxStartAdcSched, \
    DPxStopAdcSched, DPxIsAdcSchedRunning, DPxEnableAdcLogTimetags, \
    DPxDisableAdcLogTimetags, DPxIsAdcLogTimetags, DPxIsAdcCalibRaw, \
    DPxDisableAdcBuffAllChans, DPxSetAdcSchedule, DPxReadAdcBuffer, DPxGetAdcStatus
from abc import ABCMeta
from pypixxlib.schedule import Schedule
from pypixxlib.dpxDevice import DpxExceptionDecorate

#from . import Schedule
#from . import DpxExceptionDecorate


[docs]class AnalogIn(Schedule, metaclass=ABCMeta): """Class which contains the ADC features. These functions should only be called from your device's ``adc`` parameter: ``my_device.adc.function()``. The functions below are used to configure and use Analog In of your VPixx Device. """
[docs] @DpxExceptionDecorate def getNbrOfChannel(self): """Gets the number of channels available. Returns: int: Number of channels. """ return DPxGetAdcNumChans()
[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. """ return DPxGetAdcValue(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 DPxGetAdcRange(channel)
[docs] @DpxExceptionDecorate def getChannelVoltage(self, channel): """Gets the current voltage of a channel. Returns: float: voltage of the channel. """ return DPxGetAdcVoltage(channel)
[docs] @DpxExceptionDecorate def setChannelReference(self, channel, reference): """Sets a reference to a channel. 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: channel (int): Channel number to associate with a reference. reference (String): Valid argument is one of the following predefined constants.\n - gnd : Referenced to ground. - diff : Referenced to adjacent analog input. - ref0 : Referenced to REF0 analog input. - ref1 : Referenced to REF1 analog input. See Also: :class:`getChannelReference` """ DPxSetAdcBuffChanRef(channel, reference)
[docs] @DpxExceptionDecorate def getChannelReference(self, channel): """Gets the reference associated with a channel. Args: channel (int): channel to query. Returns: String: one of the following predefined constants.\n - gnd : Referenced to ground. - diff : Referenced to adjacent analog input. - ref0 : Referenced to REF0 analog input. - ref1 : Referenced to REF1 analog input. See Also: :class:`setChannelReference` """ return DPxGetAdcBuffChanRef(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): DPxEnableAdcBuffChan(i) else: DPxEnableAdcBuffChan(channel) else: if channel == None: DPxDisableAdcBuffAllChans() else: DPxDisableAdcBuffChan(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 DPxIsAdcBuffChan(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: DPxEnableAdcCalibRaw() else: DPxDisableAdcCalibRaw()
[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 DPxIsAdcCalibRaw() == 0: enable = False else: enable = True return enable
[docs] @DpxExceptionDecorate def setLoopback(self, enable): """Sets the digital inputs and outputs loopback mode. This method allows the user to enable or disable the loopback between digital output ports and digital inputs. When enabled, the digital outputs send their data to the digital inputs. When disabled, the digital inputs will not get the digital outputs data. Args: enable (Bool): True if loopback is enabled, False otherwise. See Also: :class:`isLoopbackEnabled` """ if enable == True: DPxEnableDacAdcLoopback() else: DPxDisableDacAdcLoopback()
[docs] @DpxExceptionDecorate def isLoopbackEnabled(self): """Verifies the digital inputs and outputs loop back mode. Returns: Bool: True if transitions are being stabilized, False otherwise. See Also: :class:`setLoopback` """ if DPxIsDacAdcLoopback() == 0: enable = False else: enable = True return enable
[docs] @DpxExceptionDecorate def setFreeRunMode(self, enable): """Sets the continuous acquisition mode. This method allows the user to enable or disable the continuous acquisition (free running) mode. When enabled, the ADCs convert continuously. Doing so can add up to 4 microseconds random latency to scheduled samples. When disabled, the ADCs only convert on schedule ticks. This can be used for microsecond-precise sampling. Args: enable (Bool): True if loopback is enabled, False otherwise. See Also: :class:`isFreeRunEnabled` """ if enable == True: DPxEnableAdcFreeRun() else: DPxDisableAdcFreeRun()
[docs] @DpxExceptionDecorate def isFreeRunEnabled(self): """Verifies the continuous acquisition mode state. Returns: Bool: True if continuous acquisition is activated, False otherwise. See Also: :class:`setFreeRunMode` """ if DPxIsAdcFreeRun() == 0: free_run = False else: free_run = True return free_run
[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. """ DPxSetAdcBuffBaseAddr(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. """ return DPxGetAdcBuffBaseAddr()
[docs] @DpxExceptionDecorate def setWriteAddress(self, address): """Sets the Ram buffer write address. This method allows the user to set the RAM buffer write address used in schedules. This address is used by the schedule to know where the data should be first written to. The schedule will then write the following data to the address following the RAM buffer write address. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ DPxSetAdcBuffWriteAddr(address)
[docs] @DpxExceptionDecorate def getWriteAddress(self): """Gets the Ram buffer write address. This method allows the user to get the RAM buffer write address used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAdcBuffWriteAddr()
[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. """ DPxSetAdcBuffSize(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 DPxGetAdcBuffSize()
[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 does not need to be used. Default value is 0. Args: onset (int): Any positive value equal to or greater than 0. """ DPxSetAdcSchedOnset(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 DPxGetAdcSchedOnset()
[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. nanosecond delay between schedule start and first sample. If no delay is required, this method does not need to be used. Default value is 0. Args: rate (int): Any positive value equal to or greater than 0. unit (String): Any of the following predefined constants:\n - hz : samples per second, maximum 200 kHz. - video : samples per video frame, maximum 200 kHz. - nano : sample period in nanoseconds, minimum 5000 ns. """ DPxSetAdcSchedRate(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 = DPxGetAdcSchedRate() 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 = DPxGetAdcSchedRate() 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` """ DPxSetAdcSchedCount(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 DPxGetAdcSchedCount()
[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: DPxEnableAdcSchedCountdown() else: DPxDisableAdcSchedCountdown()
[docs] @DpxExceptionDecorate def isCountDownEnabled(self): """Verifies the schedule count down mode. Returns: Bool: True if the schedule is decrementing at every sample, False otherwise. See Also: :class:`setScheduleCount`, :class:`stopSchedule`, :class:`setScheduleCountDown` """ if DPxIsAdcSchedCountdown() !=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:`setWriteAddress`, :class:`setBaseAddress`, :class:`setScheduleOnset`, :class:`setScheduleRate`, :class:`setScheduleCountDown`, :class:`setScheduleCount` """ DPxStartAdcSched()
[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:`setWriteAddress`, :class:`setBaseAddress`, :class:`setScheduleOnset`, :class:`setScheduleRate`, :class:`setScheduleCountDown`, :class:`setScheduleCount` """ DPxStopAdcSched()
[docs] @DpxExceptionDecorate def isScheduleRunning(self): """Verifies if a schedule is currently running on the subsystem. Returns: Bool: True if a schedule is currently running, False otherwise. See Also: :class:`startSchedule`, :class:`stopSchedule` """ if DPxIsAdcSchedRunning() == 0: schedule_running = False else: schedule_running = True return schedule_running
[docs] @DpxExceptionDecorate def setLogTimetags(self, enable): """Sets the timetag mode on the data samples. This method allows the user to enable or disable the timetag on acquired data. When enabled, each buffered sample is preceded with a 64-bit nanosecond timetag. When disabled, buffered data has no timetags. Args: enable (Bool): True to activate the timetag mode, False otherwise. See Also: :class:`isLogTimetagsEnabled` """ if enable == True: DPxEnableAdcLogTimetags() else: DPxDisableAdcLogTimetags()
[docs] @DpxExceptionDecorate def isLogTimetagsEnabled(self): """Verifies if the timetag mode is enabled. Returns: Bool: True if timetag mode is enabled, False otherwise. See Also: :class:`setLogTimetags` """ if DPxIsAdcLogTimetags() == 0: enabled = False else: enabled = True return enabled
[docs] @DpxExceptionDecorate def setSchedule(self, onSet, rateValue, rateUnits, maxScheduleFrames, channelList = None, bufferBaseAddr = 4e6, numberBufferFrames=None): """Configure a schedule for autonomous ADC 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 200 kHz. 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): The channelList can have two formats, a list of the channels you want to use, or a list of the channels you want to use in the first row, and the 2nd row contains the differential. The first row of the list contains 1 or more integers in the range 0 to GetAdcNumChannels-1. This is the list of ADC channels which will be acquired. The second row of the matrix indicates the differential voltage references for each acquired channel. The list must have this format: [[chanNum, ref]...] or 1D list [chanNum, chanNum2, ...]. The reference is selected using a string with value "gnd", "diff", "ref0" or "ref1". Code "gnd" is used when no differential subtraction is required during acquisition. All analog inputs are referenced to ground, also known as single-ended acquisition. Code "diff" implements fully differential inputs, subtracting the adjacent channel's voltage before acquiring (eg: acquiring ADC0 with code = "diff" would subtract the ADC1 voltage from the ADC0 voltage, writing the result to the acquisition buffer). When using this mode, data is typically acquired only on the even channels, effectively halving the number of available channels. Code "ref0" implements a differential input referenced to the REF0 analog input (see the Datapixx user manual for pinouts). This has the benefits of high-impedance differential inputs, without having to sacrifice half of the channels as with fully differential inputs. Code "ref1" implements a differential input referenced to the REF1 analog input. It is possible to use different codes for different analog channels in a single acquisition schedule. For example ADC0 and ADC1 could be acquired single-ended while ADC2 is referenced to ADC3, and ADC4/5/6/7 could be referenced to REF0. It is also possible to pass only a single row of ADC channels to channelList. In this case, all of the ADC channels will be acquired single-ended. 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: AdcDictionary (dict): Returns a dictionary which has some global information which must be passed to other ADC functions. """ DPxSetAdcSchedule(onSet, rateValue, rateUnits, maxScheduleFrames, channelList, bufferBaseAddr, numberBufferFrames)
[docs] @DpxExceptionDecorate def readBuffer(self, inDict, numFrames = 0, customReadAddr = None): """Reads data from the ADC buffer. Args: inDict (dict): The dictionary returned by the schedule setup numFrames (int): Number of frames of information to retrieve from the ADC buffer. Leave to 0 to read the full buffer, which is the default argument. customReadAddr (int): The byte address in Datapixx RAM where the buffered data can be found. If this argument is not provided, it will take on the value of bufferBaseAddress passed to the last call to SetAdcSchedule. Specifying abufferAddress of -1 will cause data to be streamed from the buffer which was defined in the last call to SetAdcSchedule. Returns: [data], [timetag] (list,list): Returns a tuple of list, where the first one is the data and the second one are its timetags. The data will be nChan*numFrames, where nChan is the number of channels activated for recording. See Also: :class:`DPxEnableAdcSchedCountdown`, :class:`DPxSetAdcSchedule` """ DPxReadAdcBuffer(inDict, numFrames, customReadAddr)
[docs] @DpxExceptionDecorate def getStatus(self, inDict): """Updates the information dictionary for the ADC schedule. Args: inDict (dict): The dictionary returned by the schedule setup Updates the dictionary with the following information: "dacAdcLoopback" is True if ADC inputs are driven internally by DAC outputs, or False if ADC inputs report real analog inputs. "freeRunning" is True if ADC hardware is sampling continuously, or False if it only samples on ADC acquisition schedule ticks. "scheduleRunning" is True if the analog acquisition 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 "numAdcSchedChans" 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. "currentWriteFrame" is the buffer frame which will be written by the next acquired ADC sample. "currentReadFrame" is the buffer frame which will be read by the next streaming call to ReadAdcBuffer. "newBufferFrames" = currentWriteFrame - currentReadFrame. This is the maximum number of frames which can be read by the next call to ReadAdcBuffer in streaming mode, without causing a streaming underflow. "maxScheduleFrames", if non-0, is the value of currentWriteFrame which will automatically stop the schedule. """ DPxGetAdcStatus(inDict)