quanser.hardware.hil.write_other_buffer quanser.hardware.hil.read_analog_write_analog_buffer navigation bar

Table of Contents

quanser.hardware.hil.write_buffer

Writes the specified samples to the selected channels at the indicated sampling rate.

Syntax

[samples_written, err] = board.write_buffer(...
    clock, frequency, analog_channels, pwm_channels, digital_channels, other_channels, ...
    analog_voltages, pwm_duty_cycles, digital_values, other_values)
    

Description

Writes the specified samples to the selected channels at the indicated sampling rate. The number of samples is determined by the number of columns in the matrix parameters. Channel numbers are zero-based. Specify an empty matrix, [], to specify no channels.

Warning Many cards allow the digital I/O lines to be programmed as inputs or outputs. The digital I/O lines are configured as inputs or outputs using the set_digital_directions function. All the channels which will be used as digital outputs must be configured as outputs using this function. Failure to configure the digital I/O may result in the write_buffer function failing to write those outputs.

If no err output is provided then it throws an exception if an error occurs. In generated code it prints the error message. Use hil_get_error_message to get the message associated with an error code.

Parameters

board

The board instance returned by the quanser.hardware.hil.open function.

clock

The clock to use as a timebase for the buffered operation. Hardware clocks are numbered incrementally starting at 0, with 0 meaning HARDWARE_CLOCK_0, 1 meaning HARDWARE_CLOCK_1, etc. The number of clocks available depends on the board selected. Refer to Clocks for more information.

Select a board type from the list for board-specific details: .

frequency

The sampling frequency in Hertz at which samples will be collected.

analog_channels

A vector of analog channel numbers. This parameter may be an empty matrix, [].

Select a board type from the list for board-specific details: .

pwm_channels

A vector of PWM channel numbers. This parameter may be an empty matrix, [].

Select a board type from the list for board-specific details: .

digital_channels

A vector of digital channel numbers. This parameter may be an empty matrix, [].

Select a board type from the list for board-specific details: .

other_channels

A vector of other channel numbers. This parameter may be an empty matrix, [].

Select a board type from the list for board-specific details: .

analog_values

A matrix of analog voltages. There is one row for each analog channel and one column for each sample. If no analog channels were specified then this parameter may be an empty matrix, [].

pwm_duty_cycles

In PWM duty cycle mode, this argument is a matrix of PWM duty cycles. Values may range from -1.0 to +1.0. Sign indicates direction for bipolar PWM outputs.

In PWM frequency mode, this argument is a matrix of PWM frequencies in Hertz. Sign indicates direction for bipolar PWM outputs.

In PWM period mode, this argument is a matrix of PWM periods in seconds. Sign indicates direction for bipolar PWM outputs.

There must be one row for each PWM output channel and one column for each sample. If no PWM channels were specified then this parameter may be an empty matrix, [].

digital_values

A matrix of logical values. Values must be 0 or 1. There is one row for each digital channel and one column for each sample. If no digital channels were specified then this parameter may be an empty matrix, [].

other_values

A matrix of other values. There is one row for each other channel and one column for each sample. If no other channels were specified then this parameter may be an empty matrix, [].

Outputs

samples_written

The number of samples written. This value will equal the number of samples specified unless the operation was canceled.

err

A negative error code or zero on success.

Examples

% Uniformly distributed random voltages between -5V and +5V.
volt = 5*(rand(2, 5000)-0.5)*2;

% Uniformly distributed random duty cycles between -1 and +1.
duty = (rand(2, 5000)-0.5)*2;

% Random logical values
bit  = (rand(2, 5000) >= 0.5);

% Uniformly distributed random values between 0 and 1.
xtra = rand(2, 5000);

% Writes 5000 samples to analog channel 0, PWM channel 4, digital channel 2 and other channel 1 at 1 kHz using SYSTEM_CLOCK_1
board.write_buffer(-1, 1000, 0, 4, 2, 1, volt, cnt, bit, xtra);
    

See Also

 

navigation bar