hil_task_write_digital hil_task_write navigation bar

Table of Contents

hil_task_write_other

Deprecated

The HIL API MATLAB functions have been deprecated in favour of the new quanser.hardware.hil class, which has support for code generation for Quanser targets. Hence, with the new hil class it is possible to run MATLAB scripts in real-time on Quanser targets, while making use of the Quanser hardware.

Writes the specified other samples to the task's internal buffer.

Syntax

[samples_written, err] = hil_task_write_other(task, values)
    

Description

Writes the specified other samples to the task's internal buffer. The number of samples is determined by the number of columns in the values matrix and must be less than or equal to the internal buffer size assigned to the task in the hil_task_create_other_writer or hil_task_create_other_reader_other_writer call. This function will block until the requested number of samples can be written or the task is stopped. Note that the samples are only transferred to the internal buffer. The samples may not appear at the outputs until later. Use hil_task_flush to wait for all samples to be written to the 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

task

Task handle returned by hil_task_create_other_writer or hil_task_create_other_reader_other_writer.

values

A matrix of other values. There must be one row for each channel and one column for each sample.

Outputs

samples_written

The number of samples written. This number will be equal to the number of samples specified unless the total number of samples specified in hil_task_start has expired or the task has been stopped.

err

A negative error code or zero on success.

Examples

% Creates a task to write to other channels 0 and 3, with an internal buffer of 1000 samples.
task  = hil_task_create_other_writer(board, 1000, [0 3]);

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

% Writes 500 samples to other channels 0 and 3. Won't block until internal buffer full.
hil_task_write_other(task, values);

% Start the task using SYSTEM_CLOCK_1 at 1 kHz. Collect up to 5000 samples.
hil_task_start(task, -1, 1000, 5000);

for i=1:10
    % Uniformly distributed random values between -5V and +5V.
    values = 5*(rand(2,500)-0.5)*2;

    % Writes 500 samples to other channels 0 and 3. Won't block until internal buffer full.
    n = hil_task_write_other(task, values);
    ...
end;

% Make sure any samples remaining in the internal buffer have been written to the outputs.
hil_task_flush(task);
hil_task_stop(task);
hil_task_delete(task);
    

See Also

 

navigation bar