Example #1
0
def write_do(taskhandle, indata, intimeout=0):
    '''
    Write given data to given task
    in      taskhandle = Task handle
            indata = Samples to write as list of integers
            intimeout = Timeout for writing all samples, default 0 = try once

    out     ErrorText = Error text, None if no errors
    '''
    errortext = None
    #logger.info("Indata: {}".format(indata))
    if isinstance(indata, int):
        samplecount = 1
        datatype = uInt8
        data = datatype(indata)
    else:
        samplecount = len(indata)
        datatype = uInt8 * samplecount
        data = datatype(*indata)
    result = int32()
    samples = int32(samplecount)
    autostart = bool32(False)
    timeout = float64(intimeout)
    try:
        taskhandle.WriteDigitalU8(samples, autostart,
                                  timeout, DAQmx_Val_GroupByChannel, data,
                                  byref(result), None)
    except DAQError as err:
        errortext = err
    return errortext
Example #2
0
 def run(self):
     while not self._stop_signal.is_set():
         # Note to future self: see the comment inside EventNCallback() above
         samples_buffer = numpy.zeros((self.task.sample_buffer_size,), dtype=numpy.float64)
         try:
             self.task.ReadAnalogF64(DAQmx_Val_Auto, self.wait_period, DAQmx_Val_GroupByScanNumber, samples_buffer,
                                     self.task.sample_buffer_size, byref(self.task.samples_read), None)
         except DAQError:
             pass
         self.task.consumer.write((samples_buffer, self.task.samples_read.value))
Example #3
0
 def EveryNCallback(self):
     # Note to future self: do NOT try to "optimize" this but re-using the same array and just
     # zeroing it out each time. The writes happen asynchronously and if your zero it out too soon,
     # you'll see a whole bunch of 0.0's in the output. If you wanna go down that route, you'll need
     # cycler through several arrays and have the code that's actually doing the writing zero them out
     # mark them as available to be used by this call. But, honestly, numpy array allocation does not
     # appear to be a bottleneck at the moment, so the current solution is "good enough".
     samples_buffer = numpy.zeros((self.sample_buffer_size,), dtype=numpy.float64)
     self.ReadAnalogF64(DAQmx_Val_Auto, 0.0, DAQmx_Val_GroupByScanNumber, samples_buffer,
                        self.sample_buffer_size, byref(self.samples_read), None)
     self.consumer.write((samples_buffer, self.samples_read.value))
Example #4
0
def read_di(taskhandle, intimeout=0):
    '''
    Read data from given task
    in      Task handle
            Timeout for reading, default 0 = try once

    out     Read data
    '''
    value = uInt8()
    result = int32()
    bytespersample = int32()
    samples = int32(1)
    readarraysize = uInt32(1)
    timeout = float64(intimeout)
    taskhandle.ReadDigitalU8(samples, timeout, DAQmx_Val_GroupByScanNumber,
                             value, readarraysize, byref(result), None)
    return value.value
Example #5
0
def read_analog_io_RSE(taskhandle, samples, intimeout=100):
    '''
    Initialize task for reading from analog input port for Voltage measurement
    in    devport = Device/port e.g. Dev1/ai2
          Timeout for reading, default 100
    out   task = Task handle
    '''
    datatype = ctypes.c_double * samples
    data = datatype()
    result = int32()
    readarraysize = uInt32(samples)
    timeout = float64(intimeout)
    taskhandle.ReadAnalogF64(samples, timeout, DAQmx_Val_GroupByChannel, data,
                             readarraysize, byref(result), None)
    #sleep(0.1)
    for i in data:
        logger.info("Voltage level: {}".format(str(i)))
    return repr(data)
Example #6
0
def read_analog_io_Diff(taskhandle, samples, intimeout=100):
    '''
    Read data from given task
    in      Task handle
            Timeout for reading, default 100
    out     Read data
    '''
    datatype = ctypes.c_double * samples
    data = datatype()
    result = int32()
    readarraysize = uInt32(samples * 2)
    timeout = float64(intimeout)
    taskhandle.ReadAnalogF64(samples, timeout, DAQmx_Val_GroupByChannel, data,
                             readarraysize, byref(result), None)
    #sleep(0.1)
    for i in data:
        logger.info("Voltage level: {}".format(str(i)))
    return repr(data)
Example #7
0
 def EveryNCallback(self):
     samples_buffer = numpy.zeros((self.sample_buffer_size,), dtype=numpy.float64)
     self.ReadAnalogF64(DAQmx_Val_Auto, 0.0, DAQmx_Val_GroupByScanNumber, samples_buffer,
                        self.sample_buffer_size, byref(self.samples_read), None)
     self.consumer.write((samples_buffer, self.samples_read.value))