The serial port is locked out everytime when the matlab code reads it. For executing the code again, I need to remove and reconnect the Uno microcontroller back to my computer. My OS is Ubunbtu 14.04.
6 views (last 30 days)
Show older comments
I have written a simple MATLAB code to read the serial port. An arduino UNO microcontroller is continuously sending some data to the USB port. For example /dev/ttyUSB6. When I run the MATLAB code, the code runs once witout any issues. But when I execute the code again I am getting a error message as follows..
Error using serial/fopen (line 72)
Open failed: Port: /dev/ttyUSB6 is not available. Available ports: /dev/ttyUSB1.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error in Serial_dec23 (line 18)
fopen(s);
At the same time in MATLAB terminal, I can see another error message as follows
RXTX fhs_lock() Error: opening lock file: /var/lock/LCK..ttyUSB6: File exists
RXTX fhs_lock() Error: opening lock file: /var/lock/LCK..ttyUSB6: File exists
RXTX fhs_lock() Error: opening lock file: /var/lock/LCK..ttyUSB6: File exists
If I need to run the code again, I need to remove the microcontroller board and re-connect it back and then update the USB port number in my MATLAB code to /dev/ttyUSB7. Then, again it will succesfully run once and agian will be locked out.
How can I solve this lock out issue? I tried deleting the lock file available inside /var/lock folder. But it didn't helped me to resove the issue.
The basic code to read the serial port that I used is as follows
clc;
clear all;
close all;
instrfind()
bR=115200;
s=serial('/dev/ttyUSB6','BaudRate',bR);
fopen(s);
for i = 1:2
an = fscanf(s,'%c');
end
C = strsplit(an,';');
t1 = cell2mat(C(1));
fclose(s);
delete(s);
clear s;
Could you please help me to resolve this. I just need to read the USB port contineously without removing and reconnecting the microcontroller board everytime
5 Comments
Kavya Vuriti
on 1 Apr 2020
Is your issue resolved? Here are the functions to transition you code from serial to serialport interface.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!