Send command on serial port : "Invalid argument at position 1. Value must be a scalar." why ?
21 views (last 30 days)
Show older comments
foundVISA = visadevlist;
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.
0 Comments
Accepted Answer
Deep
on 10 Jul 2023
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);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!