Send command on serial port : "Invalid argument at position 1. Value must be a scalar." why ?

foundVISA = visadevlist;
visadevlist and visadev are not supported on Linux.
resourceCOM = foundVISA(foundVISA.Model == "9214",:).ResourceName; % 9214 Model pulse generator from QC
resourceCOM = resourceCOM(contains(resourceCOM,"9214")); % Extract resourceCOM which contains "9214"
pulseGenerator = visadev(resourceCOM);
% writeline(pulseGenerator,"*RST"); % send RESET to pulse generator for resets parameters to default
instrumentInfo = writeread(pulseGenerator,"*IDN?");
fprintf("Instrument identification information: %s",instrumentInfo);
"Invalid argument at position 1. Value must be a scalar."
what i do wrong ? Thanks for your help.

 Accepted Answer

According to visadev doc page, its constructor accepts a scalar string or a char array.
In your code,
resourceCOM = foundVISA(foundVISA.Model == "9214",:).ResourceName; % 9214 Model pulse generator from QC
resourceCOM = resourceCOM(contains(resourceCOM,"9214")); % Extract resourceCOM which contains "9214"
pulseGenerator = visadev(resourceCOM);
In the first line, you're trying to filter the foundVISA table based on the Model and get the ResourceName.
In the second line, you're filtering the resulting resourceCOM to only get entries which contain "9214".
If your filtering operations result in multiple entries (more than one "ResourceName" containing "9214"), then resourceCOM isn't a scalar, it's a vector or an array of strings. When you then try to create a pulseGenerator object using the visadev function, it expects a scalar string argument, but you're providing a non-scalar resourceCOM, hence the error.
You should choose which resource you want to pass based on some criteria. For example, simply use the first resource returned.
if ~isempty(resourceCOM)
resourceCOM = resourceCOM(1);
end
pulseGenerator = visadev(resourceCOM);

More Answers (0)

Categories

Find more on Instrument Control Toolbox in Help Center and File Exchange

Products

Release

R2023a

Asked:

on 10 Jul 2023

Answered:

on 10 Jul 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!