serial communication problem with open port
Show older comments
Hello,
I work with a PIC microchip connected to the serial COM port of my computer to send and receive data to and from the microchip PIC.
This device works well with the hyperterminal under Windows XP.
When I work with the command windows of Matlab these commands are working well:
s= serial('COM3','BaudRate',9600,'DataBits',8,'terminator',17);
fopen(s);
fprintf(s,'F')
out = fscanf(s);
disp(out)
fclose(s);
delete(s);
clear s;
and it is possible to launch again this program without any error. But when I write these lines inside of a m file and run it the error pops up as following:
??? Error using ==> serial.fopen
Port: COM3 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error in ==> PIC_I2C_Translator at 2
fopen(s);
-----------------------
Running INSTRFING it comes:
>> INSTRFIND
Instrument Object Array
Index: Type: Status: Name:
1 serial open Serial-COM3
2 serial closed Serial-COM3
3 serial closed Serial-COM3
4 serial closed Serial-COM3
5 serial closed Serial-COM3
----------------------
What is the wrong thing that makes the program not able to close the COM port when working with the m file instead of working directly through the command windows with exactly the same code ?
Is there anybody out there who met such a problem ... and solve it ?
Answers (0)
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!