Table of Contents
hil_task_read_write
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. |
Reads and writes the specified number of samples to the task's internal buffer.
[analog_input_voltages, encoder_counts, digital_input_values, other_input_values, samples_read, err] = ... hil_task_read_write(task, samples, analog_output_voltages, pwm_duty_cycles, digital_output_values, other_output_values)
Reads and writes the specified number of samples to the task's internal buffer. This function will block until the requested number of samples have been read or can be written or the task is stopped. Note that the written 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.
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 hil_set_digital_directions function. All the channels which will be used as digital inputs or outputs must be configured accordingly using this function. Failure to configure the digital I/O may result in the hil_task_read_write function failing to read or write the digital I/O as expected.
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.
task
Task handle returned by hil_task_create_reader_writer.
num_samples
The number of samples to read and write. This number must be less than or equal to the internal buffer size assigned to the task in the hil_task_create_reader_writer call.
analog_output_voltages
A matrix of analog voltages to write. There must be one row for each channel and one column for each sample. If no analog output channels were specified in the call to hil_task_create_reader_writer 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 in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
digital_output_values
A matrix of logical values to write. Values may be 0 or 1. There must be one row for each channel and one column for each sample. If no digital output channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
other_output_values
A matrix of other output values to write. There must be one row for each channel and one column for each sample. If no other channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
analog_input_voltages
A matrix of analog voltages read, as doubles. There is one row for each channel and one column for each sample. If no analog input channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
encoder_counts
A matrix of encoder counts read, as int32s. There is one row for each channel and one column for each sample. If no encoder input channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
digital_input_values
A matrix of digital values read, as int8s. There is one row for each channel and one column for each sample. If no digital input channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
other_input_values
A matrix of other values read, as doubles. There is one row for each channel and one column for each sample. If no other input channels were specified in the call to hil_task_create_reader_writer then this parameter may be an empty matrix, [].
samples_read
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.
% Creates a task to read analog channels 0 and 3 and digital channel 5, and write to analog channel 7, with an internal buffer of 1000 samples. task = hil_task_create_reader_writer(board, 1000, [0 3], [], 5, [], 7, [], [], []); % Uniformly distributed random voltages between -5V and +5V. volts = 5*(rand(2,500)-0.5)*2; % Random logical values. bits = (rand(1,500) >= 0.5); % Writes 500 samples to analog channels 0 and 3 and digital channel 5. Won't block until internal buffer full. hil_task_write(task, volts, [], bits, []); % 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 voltages between -5V and +5V. volts = 5*(rand(2,500)-0.5)*2; % Random logical values. bits = (rand(1,500) >= 0.5); % Reads 500 samples from analog channel 7 and writes 500 samples to analog channels 0 and 3 and digital channel 5. [v, c, d, x, n] = hil_task_read_write(task, 500, volts, [], bits, []); ... 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
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.