(self, data, auto_start=AUTO_START_UNSET, timeout=10.0)
Writes samples to the task or virtual channels you specify.

        This write method is dynamic, and is capable of accepting the
        samples to write in the various forms for most operations:
        
        - Scalar: Single sample for 1 channel.
        - List/1D numpy.ndarray: Multiple samples for 1 channel or 1
          sample for multiple channels.
        - List of lists/2D numpy.ndarray: Multiple samples for multiple
          channels.

        The data type of the samples passed in must be appropriate for
        the channel type of the task.

        For counter output pulse operations, this write method only
        accepts samples in these forms:
        
        - Scalar CtrFreq, CtrTime, CtrTick (from nidaqmx.types): 
          Single sample for 1 channel.
        - List of CtrFreq, CtrTime, CtrTick (from nidaqmx.types):
          Multiple samples for 1 channel or 1 sample for multiple 
          channels.

        If the task uses on-demand timing, this method returns only
        after the device generates all samples. On-demand is the default
        timing type if you do not use the timing property on the task to
        configure a sample timing type. If the task uses any timing type
        other than on-demand, this method returns immediately and does
        not wait for the device to generate all samples. Your
        application must determine if the task is done to ensure that
        the device generated all samples.

        Args:
            data (dynamic): Contains the samples to write to the task.

                The data you write must be in the units of the
                generation, including any custom scales. Use the DAQmx
                Create Channel methods to specify these units.
            auto_start (Optional[bool]): Specifies if this method
                automatically starts the task if you did not explicitly
                start it with the DAQmx Start Task method.

                The default value of this parameter depends on whether
                you specify one sample or many samples to write to each
                channel. If one sample per channel was specified, the
                default value is True. If multiple samples per channel
                were specified, the default value is False.
            timeout (Optional[float]): Specifies the amount of time in
                seconds to wait for the method to write all samples.
                NI-DAQmx performs a timeout check only if the method
                must wait before it writes data. This method returns an
                error if the time elapses. The default timeout is 10
                seconds. If you set timeout to
                nidaqmx.constants.WAIT_INFINITELY, the method waits
                indefinitely. If you set timeout to 0, the method tries
                once to write the submitted samples. If the method could
                not write all the submitted samples, it returns an error
                and the number of samples successfully written.
        Returns:
            int:

            Specifies the actual number of samples this method
            successfully wrote.
Writes samples to the task or virtual channels you specify.
Writes samples to the task or virtual channels you specify .
def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0):
        """
        Writes samples to the task or virtual channels you specify.

        This write method is dynamic, and is capable of accepting the
        samples to write in the various forms for most operations:
        
        - Scalar: Single sample for 1 channel.
        - List/1D numpy.ndarray: Multiple samples for 1 channel or 1
          sample for multiple channels.
        - List of lists/2D numpy.ndarray: Multiple samples for multiple
          channels.

        The data type of the samples passed in must be appropriate for
        the channel type of the task.

        For counter output pulse operations, this write method only
        accepts samples in these forms:
        
        - Scalar CtrFreq, CtrTime, CtrTick (from nidaqmx.types): 
          Single sample for 1 channel.
        - List of CtrFreq, CtrTime, CtrTick (from nidaqmx.types):
          Multiple samples for 1 channel or 1 sample for multiple 
          channels.

        If the task uses on-demand timing, this method returns only
        after the device generates all samples. On-demand is the default
        timing type if you do not use the timing property on the task to
        configure a sample timing type. If the task uses any timing type
        other than on-demand, this method returns immediately and does
        not wait for the device to generate all samples. Your
        application must determine if the task is done to ensure that
        the device generated all samples.

        Args:
            data (dynamic): Contains the samples to write to the task.

                The data you write must be in the units of the
                generation, including any custom scales. Use the DAQmx
                Create Channel methods to specify these units.
            auto_start (Optional[bool]): Specifies if this method
                automatically starts the task if you did not explicitly
                start it with the DAQmx Start Task method.

                The default value of this parameter depends on whether
                you specify one sample or many samples to write to each
                channel. If one sample per channel was specified, the
                default value is True. If multiple samples per channel
                were specified, the default value is False.
            timeout (Optional[float]): Specifies the amount of time in
                seconds to wait for the method to write all samples.
                NI-DAQmx performs a timeout check only if the method
                must wait before it writes data. This method returns an
                error if the time elapses. The default timeout is 10
                seconds. If you set timeout to
                nidaqmx.constants.WAIT_INFINITELY, the method waits
                indefinitely. If you set timeout to 0, the method tries
                once to write the submitted samples. If the method could
                not write all the submitted samples, it returns an error
                and the number of samples successfully written.
        Returns:
            int:

            Specifies the actual number of samples this method
            successfully wrote.
        """
        channels_to_write = self.channels
        number_of_channels = len(channels_to_write.channel_names)
        write_chan_type = channels_to_write.chan_type

        element = None
        if number_of_channels == 1:
            if isinstance(data, list):
                if isinstance(data[0], list):
                    self._raise_invalid_write_num_chans_error(
                        number_of_channels, len(data))

                number_of_samples_per_channel = len(data)
                element = data[0]

            elif isinstance(data, numpy.ndarray):
                if len(data.shape) == 2:
                    self._raise_invalid_write_num_chans_error(
                        number_of_channels, data.shape[0])

                number_of_samples_per_channel = len(data)
                element = data[0]

            else:
                number_of_samples_per_channel = 1
                element = data

        else:
            if isinstance(data, list):
                if len(data) != number_of_channels:
                    self._raise_invalid_write_num_chans_error(
                        number_of_channels, len(data))

                if isinstance(data[0], list):
                    number_of_samples_per_channel = len(data[0])
                    element = data[0][0]
                else:
                    number_of_samples_per_channel = 1
                    element = data[0]

            elif isinstance(data, numpy.ndarray):
                if data.shape[0] != number_of_channels:
                    self._raise_invalid_write_num_chans_error(
                        number_of_channels, data.shape[0])

                if len(data.shape) == 2:
                    number_of_samples_per_channel = data.shape[1]
                    element = data[0][0]
                else:
                    number_of_samples_per_channel = 1
                    element = data[0]

            else:
                self._raise_invalid_write_num_chans_error(
                    number_of_channels, 1)

        if auto_start is AUTO_START_UNSET:
            if number_of_samples_per_channel > 1:
                auto_start = False
            else:
                auto_start = True

        # Analog Input
        if write_chan_type == ChannelType.ANALOG_OUTPUT:
            data = numpy.asarray(data, dtype=numpy.float64)
            return _write_analog_f_64(
                self._handle, data, number_of_samples_per_channel, auto_start,
                timeout)

        # Digital Input
        elif write_chan_type == ChannelType.DIGITAL_OUTPUT:
            if self.out_stream.do_num_booleans_per_chan == 1:
                if (not isinstance(element, bool) and
                        not isinstance(element, numpy.bool_)):
                    raise DaqError(
                        'Write failed, because this write method only accepts '
                        'boolean samples when there is one digital line per '
                        'channel in a task.\n\n'
                        'Requested sample type: {0}'.format(type(element)),
                        DAQmxErrors.UNKNOWN.value, task_name=self.name)

                data = numpy.asarray(data, dtype=numpy.bool)
                return _write_digital_lines(
                    self._handle, data, number_of_samples_per_channel,
                    auto_start, timeout)
            else:
                if (not isinstance(element, six.integer_types) and
                        not isinstance(element, numpy.uint32)):
                    raise DaqError(
                        'Write failed, because this write method only accepts '
                        'unsigned 32-bit integer samples when there are '
                        'multiple digital lines per channel in a task.\n\n'
                        'Requested sample type: {0}'.format(type(element)),
                        DAQmxErrors.UNKNOWN.value, task_name=self.name)

                data = numpy.asarray(data, dtype=numpy.uint32)
                return _write_digital_u_32(
                    self._handle, data, number_of_samples_per_channel,
                    auto_start, timeout)

        # Counter Input
        elif write_chan_type == ChannelType.COUNTER_OUTPUT:
            output_type = channels_to_write.co_output_type

            if number_of_samples_per_channel == 1:
                data = [data]

            if output_type == UsageTypeCO.PULSE_FREQUENCY:
                frequencies = []
                duty_cycles = []
                for sample in data:
                    frequencies.append(sample.duty_cycle)
                    duty_cycles.append(sample.freq)

                frequencies = numpy.asarray(frequencies, dtype=numpy.float64)
                duty_cycles = numpy.asarray(duty_cycles, dtype=numpy.float64)

                return _write_ctr_freq(
                    self._handle, frequencies, duty_cycles,
                    number_of_samples_per_channel, auto_start, timeout)

            elif output_type == UsageTypeCO.PULSE_TIME:
                high_times = []
                low_times = []
                for sample in data:
                    high_times.append(sample.high_time)
                    low_times.append(sample.low_time)

                high_times = numpy.asarray(high_times, dtype=numpy.float64)
                low_times = numpy.asarray(low_times, dtype=numpy.float64)

                return _write_ctr_time(
                    self._handle, high_times, low_times,
                    number_of_samples_per_channel, auto_start, timeout)

            elif output_type == UsageTypeCO.PULSE_TICKS:
                high_ticks = []
                low_ticks = []
                for sample in data:
                    high_ticks.append(sample.high_tick)
                    low_ticks.append(sample.low_tick)

                high_ticks = numpy.asarray(high_ticks, dtype=numpy.uint32)
                low_ticks = numpy.asarray(low_ticks, dtype=numpy.uint32)

                return _write_ctr_ticks(
                    self._handle, high_ticks, low_ticks,
                    number_of_samples_per_channel, auto_start, timeout)
        else:
            raise DaqError(
                'Write failed, because there are no output channels in this '
                'task to which data can be written.',
                DAQmxErrors.WRITE_NO_OUTPUT_CHANS_IN_TASK.value,
                task_name=self.name)
def write ( self , data , auto_start = AUTO_START_UNSET , timeout = 10.0 ) : channels_to_write = self . channels number_of_channels = len ( channels_to_write . channel_names ) write_chan_type = channels_to_write . chan_type element = None if number_of_channels == 1 : if isinstance ( data , list ) : if isinstance ( data [ 0 ] , list ) : self . _raise_invalid_write_num_chans_error ( number_of_channels , len ( data ) ) number_of_samples_per_channel = len ( data ) element = data [ 0 ] elif isinstance ( data , numpy . ndarray ) : if len ( data . shape ) == 2 : self . _raise_invalid_write_num_chans_error ( number_of_channels , data . shape [ 0 ] ) number_of_samples_per_channel = len ( data ) element = data [ 0 ] else : number_of_samples_per_channel = 1 element = data else : if isinstance ( data , list ) : if len ( data ) != number_of_channels : self . _raise_invalid_write_num_chans_error ( number_of_channels , len ( data ) ) if isinstance ( data [ 0 ] , list ) : number_of_samples_per_channel = len ( data [ 0 ] ) element = data [ 0 ] [ 0 ] else : number_of_samples_per_channel = 1 element = data [ 0 ] elif isinstance ( data , numpy . ndarray ) : if data . shape [ 0 ] != number_of_channels : self . _raise_invalid_write_num_chans_error ( number_of_channels , data . shape [ 0 ] ) if len ( data . shape ) == 2 : number_of_samples_per_channel = data . shape [ 1 ] element = data [ 0 ] [ 0 ] else : number_of_samples_per_channel = 1 element = data [ 0 ] else : self . _raise_invalid_write_num_chans_error ( number_of_channels , 1 ) if auto_start is AUTO_START_UNSET : if number_of_samples_per_channel > 1 : auto_start = False else : auto_start = True # Analog Input if write_chan_type == ChannelType . ANALOG_OUTPUT : data = numpy . asarray ( data , dtype = numpy . float64 ) return _write_analog_f_64 ( self . _handle , data , number_of_samples_per_channel , auto_start , timeout ) # Digital Input elif write_chan_type == ChannelType . DIGITAL_OUTPUT : if self . out_stream . do_num_booleans_per_chan == 1 : if ( not isinstance ( element , bool ) and not isinstance ( element , numpy . bool_ ) ) : raise DaqError ( 'Write failed, because this write method only accepts ' 'boolean samples when there is one digital line per ' 'channel in a task.\n\n' 'Requested sample type: {0}' . format ( type ( element ) ) , DAQmxErrors . UNKNOWN . value , task_name = self . name ) data = numpy . asarray ( data , dtype = numpy . bool ) return _write_digital_lines ( self . _handle , data , number_of_samples_per_channel , auto_start , timeout ) else : if ( not isinstance ( element , six . integer_types ) and not isinstance ( element , numpy . uint32 ) ) : raise DaqError ( 'Write failed, because this write method only accepts ' 'unsigned 32-bit integer samples when there are ' 'multiple digital lines per channel in a task.\n\n' 'Requested sample type: {0}' . format ( type ( element ) ) , DAQmxErrors . UNKNOWN . value , task_name = self . name ) data = numpy . asarray ( data , dtype = numpy . uint32 ) return _write_digital_u_32 ( self . _handle , data , number_of_samples_per_channel , auto_start , timeout ) # Counter Input elif write_chan_type == ChannelType . COUNTER_OUTPUT : output_type = channels_to_write . co_output_type if number_of_samples_per_channel == 1 : data = [ data ] if output_type == UsageTypeCO . PULSE_FREQUENCY : frequencies = [ ] duty_cycles = [ ] for sample in data : frequencies . append ( sample . duty_cycle ) duty_cycles . append ( sample . freq ) frequencies = numpy . asarray ( frequencies , dtype = numpy . float64 ) duty_cycles = numpy . asarray ( duty_cycles , dtype = numpy . float64 ) return _write_ctr_freq ( self . _handle , frequencies , duty_cycles , number_of_samples_per_channel , auto_start , timeout ) elif output_type == UsageTypeCO . PULSE_TIME : high_times = [ ] low_times = [ ] for sample in data : high_times . append ( sample . high_time ) low_times . append ( sample . low_time ) high_times = numpy . asarray ( high_times , dtype = numpy . float64 ) low_times = numpy . asarray ( low_times , dtype = numpy . float64 ) return _write_ctr_time ( self . _handle , high_times , low_times , number_of_samples_per_channel , auto_start , timeout ) elif output_type == UsageTypeCO . PULSE_TICKS : high_ticks = [ ] low_ticks = [ ] for sample in data : high_ticks . append ( sample . high_tick ) low_ticks . append ( sample . low_tick ) high_ticks = numpy . asarray ( high_ticks , dtype = numpy . uint32 ) low_ticks = numpy . asarray ( low_ticks , dtype = numpy . uint32 ) return _write_ctr_ticks ( self . _handle , high_ticks , low_ticks , number_of_samples_per_channel , auto_start , timeout ) else : raise DaqError ( 'Write failed, because there are no output channels in this ' 'task to which data can be written.' , DAQmxErrors . WRITE_NO_OUTPUT_CHANS_IN_TASK . value , task_name = self . name )