Multiple Com Ports with the same Name
Show older comments
Hello there...I am working on a gui, created with guide (R2016a) which is supposed to open a serial communication port with an µC. All I am trying to implement there I did with several Matlab-Scripts and couple of uicontrols before and it worked quite well.
My problem here is the following: With the first pushbutton, I am trying to open a serial com port.
s1 = serial('COM3');
assignin('base','s1',serial('COM3'));
fopen(s1);
This actually works quite well. Except the output of
instrfind
right after the first three lines does get me two different indices with the same name. Like this:
>> instrfind
Instrument Object Array
Index: Type: Status: Name:
1 serial open Serial-COM3
2 serial closed Serial-COM3
My guess this comes due to the two callings of 'serial'. You might be asking WHY i did this: I need to 'fwrite' or 'fread' some bits with another Pushbutton of the gui and I did not found any other way than to
s1 = evalin('base','s1');
fwrite(s1,....);
which for I need to store the serial com port "s1" within the workspace. Another Problem is to
fclose(s1);
because it will not close the remaining open serial com port, but the last one showed with 'instrfind'.
My question here is: Why does Matlab create multiple serials of the same Name and how can I close the serial com port which is open. I could use
fclose(instrfinde);
but this does not explain, what I am doing wrong. If somebody could point out how to get the serial com port from one function to another, maybe I could ease things up. Thanks in advance!
Answers (1)
Michael schmidt
on 17 Feb 2018
0 votes
I have the exact same problem!
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!