def FetchMeasurement( self, channelList="0", buf=None, timeout=1, arrayMeasurement=None, ): """ Returns the waveform from a previously initiated acquisition that the digitizer acquires for the specified channel. numpy array needs to be Fortran ordered. """ numAcquiredWaveforms = self.ActualNumWfms(channelList) numberOfChannels = len(','.split(channelList)) arrayActualRecordLength = ViInt32(0) status = self.CALL('ActualMeasWfmSize', self, ViInt32(arrayMeasurement), byref(arrayActualRecordLength)) if buf is None: buf = zeros([ arrayActualRecordLength.value, numberOfChannels * numAcquiredWaveforms ], order="F", dtype=numpy.float64) samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] else: samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] if numberOfRecords < numAcquiredWaveforms * numberOfChannels: self.FetchNumberRecords = numberOfRecords / numberOfChannels assert numAcquiredWaveforms == numberOfRecords assert self.RecordLength >= samplesPerRecord data_type = { numpy.float64: '', numpy.int8: 'Binary8', numpy.int16: 'Binary16', numpy.int32: 'Binary32' }[buf.dtype.type] wfmInfoArray = wfmInfo * numAcquiredWaveforms self.info = wfmInfoArray() status = self.CALL("FetchArrayMeasurement" + data_type, self, ViConstString(channelList), ViReal64(timeout), ViInt32(arrayMeasurement), arrayActualRecordLength, buf.ctypes.data, byref(self.info)) x = [] for i in self.info: xstart = i.absoluteInitialX.value xstep = i.xIncrement.value xn = i.actualSamples.value x = numpy.append( x, [numpy.arange(xstart, xstart + xn * xstep, xstep)]) xshape = x.reshape((len(self.info), self.info[0].actualSamples.value)) return xshape, buf.T
def ConfigureHorizontalTiming(self, sampleRate=20000000, numPts=1000, refPosition=0.5, numRecords=1, enforceRealtime=True): """ Configures the common properties of the horizontal subsystem for a multirecord acquisition in terms of minimum sample rate. """ self.RecordLength = numPts status = self.CALL('ConfigureHorizontalTiming', self, ViReal64(sampleRate), ViInt32(numPts), ViReal64(refPosition), ViInt32(numRecords), ViBoolean(enforceRealtime)) return
def ConfigureAcquisition(self, acqType=VAL.NORMAL): """ Configures how the digitizer acquires data and fills the wave- form record. """ acquisitionType = ViInt32(acqType) status = self.CALL("ConfigureAcquisition", self, acquisitionType)
def ExportSignal(self, signal=NISCOPE_VAL_REF_TRIGGER, outputTerminal=NISCOPE_VAL_RTSI_0, signalIdentifier=""): """ Configures the digitizer to generate a signal that other devices can detect when configured for digital triggering or sharing clocks. The signal parameter speci- fies what condition causes the digitizer to generate the signal. The outputTerminal parameter specifies where to send the signal on the hardware (such as a PFI connector or RTSI line). In cases where multiple instances of a particular signal exist, use the signalIdentifier input to specify which instance to control. For normal signals, only one instance exists and you should leave this parameter set to the empty string. You can call this function multiple times and set each available line to a different signal. To unprogram a specific line on device, call this function with the signal you no longer want to export and set outputTerminal to NISCOPE_VAL_NONE. """ status = self.CALL("ExportSignal", self, ViInt32(signal), ViConstString(signalIdentifier), ViConstString(outputTerminal)) return status
def Fetch( self, channelList="0", buf=None, timeout=1, ): """ Returns the waveform from a previously initiated acquisition that the digitizer acquires for the specified channel. numpy array needs to be Fortran ordered. """ if six.PY3: if isinstance(channelList, str): channelList = channelList.encode('ascii') numAcquiredWaveforms = self.ActualNumWfms(channelList) numberOfChannels = len(b','.split(channelList)) if buf is None: buf = zeros( [self.RecordLength, numberOfChannels * numAcquiredWaveforms], order="F", dtype=numpy.float64) samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] else: samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] if numberOfRecords < numAcquiredWaveforms * numberOfChannels: self.FetchNumberRecords = numberOfRecords / numberOfChannels assert numAcquiredWaveforms == numberOfRecords assert self.RecordLength >= samplesPerRecord data_type = { numpy.float64: '', numpy.int8: 'Binary8', numpy.int16: 'Binary16', numpy.int32: 'Binary32' }[buf.dtype.type] wfmInfoArray = wfmInfo * numAcquiredWaveforms self.info = wfmInfoArray() # Enclosing CALL into try except because the exception # that is likely to be raised is overflow warnings. # Without the try-except, no data will be returned at all. try: status = self.CALL("Fetch" + data_type, self, ViConstString(channelList), ViReal64(timeout), ViInt32(samplesPerRecord), buf.ctypes.data, byref(self.info)) except Exception as e: message = e.args[0] if six.PY3: message = message.decode('ascii') if message.startswith('Warning'): warnings.warn(message) else: raise return buf
def AcquisitionStatus(self): """ Returns status information about the acquisition to the status output parameter. """ acq_status = ViInt32() status = self.CALL("AcquisitionStatus", self, byref(acq_status)) return acq_status.value
def ActualNumWfms(self, channelList="0"): """ Helps you to declare appropriately sized waveforms. NI-SCOPE handles the channel list parsing for you. """ chan = ViConstString(channelList) numWfms = ViInt32() self.CALL("ActualNumWfms", self, chan, byref(numWfms)) return numWfms.value
def errorHandler(self, errorCode): MAX_FUNCTION_NAME_SIZE = 55 IVI_MAX_MESSAGE_LEN = 255 IVI_MAX_MESSAGE_BUF_SIZE = IVI_MAX_MESSAGE_LEN + 1 MAX_ERROR_DESCRIPTION = (IVI_MAX_MESSAGE_BUF_SIZE * 2 + MAX_FUNCTION_NAME_SIZE + 75) errorSource = create_string_buffer(MAX_FUNCTION_NAME_SIZE) errorDescription = create_string_buffer(MAX_ERROR_DESCRIPTION) self.CALL("errorHandler", self, ViInt32(errorCode), errorSource, errorDescription) return errorDescription.value
def ActualNumWfms(self, channelList="0"): """ Helps you to declare appropriately sized waveforms. NI-SCOPE handles the channel list parsing for you. """ if six.PY3: if isinstance(channelList, str): channelList = channelList.encode('ascii') chan = ViConstString(channelList) numWfms = ViInt32() self.CALL("ActualNumWfms", self, chan, byref(numWfms)) return numWfms.value
def ActualRecordLength(self): """ Returns the actual number of points the digitizer acquires for each channel. After configuring the digitizer for an acquisition , call this function to determine the size of the waveforms that the digitizer acquires. The value is equal to or greater than the minimum number of points specified in any of the Configure Horizontal functions. Allocate a ViReal64 array of this size or greater to pass as the waveformArray of the ReadWaveform and FetchWaveform functions. """ record = ViInt32() self.CALL("ActualRecordLength", self, byref(record)) return record.value
def ConfigureVertical(self, channelList="0", voltageRange=10, offset=0, coupling=COUPLING.DC, probeAttenuation=1, enabled=True): """ Configures the most commonly configured attributes of the digi- tizer vertical subsystem, such as the range, offset, coupling, probe attenuation, and the channel. """ status = self.CALL("ConfigureVertical", self, ViConstString(channelList), ViReal64(voltageRange), ViReal64(offset), ViInt32(coupling), ViReal64(probeAttenuation), ViBoolean(enabled)) return status
def Fetch( self, channelList="0", buf=None, timeout=1, ): """ Returns the waveform from a previously initiated acquisition that the digitizer acquires for the specified channel. numpy array needs to be Fortran ordered. """ numAcquiredWaveforms = self.ActualNumWfms(channelList) numberOfChannels = len(','.split(channelList)) if buf is None: buf = zeros( [self.RecordLength, numberOfChannels * numAcquiredWaveforms], order="F", dtype=numpy.float64) samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] else: samplesPerRecord = buf.shape[0] numberOfRecords = buf.shape[1] if numberOfRecords < numAcquiredWaveforms * numberOfChannels: self.FetchNumberRecords = numberOfRecords / numberOfChannels assert numAcquiredWaveforms == numberOfRecords assert self.RecordLength >= samplesPerRecord data_type = { numpy.float64: '', numpy.int8: 'Binary8', numpy.int16: 'Binary16', numpy.int32: 'Binary32' }[buf.dtype.type] wfmInfoArray = wfmInfo * numAcquiredWaveforms self.info = wfmInfoArray() status = self.CALL("Fetch" + data_type, self, ViConstString(channelList), ViReal64(timeout), ViInt32(samplesPerRecord), buf.ctypes.data, byref(self.info)) return buf
def ConfigureTrigger(self, trigger_type='Immediate', **settings): """ Configures scope trigger type and settings. For each trigger type distinct settings must be defined. Parameter Valid Values trigger_type 'Edge' 'Hysteresis' 'Window' 'Window' 'Software' 'Immediate' 'Digital' 'Video' Trigger Type Settings Default Value 'Immediate' N/A 'Edge' triggerSource TRIGGER_SOURCE.EXTERNAL level 0 slope SLOPE.POSITIVE triggerCoupling COUPLING.DC holdoff 0 delay 0 'Hysteresis' triggerSource '0' level 0 hysteresis 0.05 slope SLOPE.POSITIVE triggerCoupling COUPLING.DC holdoff 0 delay 0 'Window' triggerSource '0' lowLevel 0 highLevel 0.1 windowMode TRIGGER_WINDOW.ENTERING_WINDOW triggerCoupling COUPLING.DC holdoff 0 delay 0 'Software' holdoff 0 delay 0 'Digital' triggerSource '0' slope SLOPE.POSITIVE holdoff 0 delay 0 'Video' triggerSource '0' enableDCRestore False signalFormat TV_TRIGGER_SIGNAL_FORMAT.VAL_PAL event TV_TRIGGER_EVENT.FIELD1 lineNumber 0 polarity TV_TRIGGER_POLARITY.TV_POSITIVE triggerCoupling COUPLING.DC holdoff 0 delay 0 """ args = { 'Edge': lambda triggerSource=TRIGGER_SOURCE.EXTERNAL, level=0, slope=SLOPE. POSITIVE, triggerCoupling=COUPLING.DC, holdoff=0, delay=0: (ViConstString(triggerSource), ViReal64(level), ViInt32(slope), ViInt32(triggerCoupling), ViReal64(holdoff), ViReal64(delay)), 'Hysteresis': lambda triggerSource='0', level=0, hysteresis=0.05, slope=SLOPE. POSITIVE, triggerCoupling=COUPLING.DC, holdoff=0, delay=0: (ViConstString(triggerSource), ViReal64(level), ViReal64( hysteresis), ViInt32(slope), ViInt32(triggerCoupling), ViReal64(holdoff), ViReal64(delay)), 'Window': lambda triggerSource='0', lowLevel=0, highLevel=0.1, windowMode= TRIGGER_WINDOW.ENTERING_WINDOW, triggerCoupling=COUPLING.DC, holdoff=0, delay=0: (ViConstString(triggerSource), ViReal64(lowLevel), ViReal64(highLevel), ViInt32(windowMode), ViInt32( triggerCoupling), ViReal64(holdoff), ViReal64(delay)), 'Software': lambda holdoff=0, delay=0: (ViReal64(holdoff), ViReal64(delay)), 'Immediate': lambda: (), 'Digital': lambda triggerSource='0', slope=SLOPE.POSITIVE, holdoff=0, delay=0: (ViConstString(triggerSource), ViInt32(slope), ViReal64(holdoff), ViReal64(delay)), 'Video': lambda triggerSource='0', enableDCRestore=False, signalFormat= TV_TRIGGER_SIGNAL_FORMAT.VAL_PAL, event=TV_TRIGGER_EVENT.FIELD1, lineNumber=0, polarity=TV_TRIGGER_POLARITY.POSITIVE, triggerCoupling=COUPLING.DC, holdoff=0, delay=0: (ViConstString(triggerSource), ViBoolean(enableDCestore), ATTR_TV_TRIGGER_SIGNAL_FORMAT(signalFormat), ViInt32(event), ViInt32(lineNumber), ViInt32(polarity), ViInt32(triggerCoupling), ViReal64(holdoff), ViReal64(delay)), }[trigger_type](**settings) status = self.CALL("ConfigureTrigger" + trigger_type, self, *args)