Effacer les filtres
Effacer les filtres

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

24 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Deep
Deep le 10 Juil 2023
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);

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by