Cannot create serial port: Error using serial (line 120)?
显示 更早的评论
Hi, I have been using MATLAB to connect to a virtual USB serial port for the past few months. However, today I have started to get this error message:
Error using serial (line 120) Cannot create: No constructor with appropriate signature exists in Java class com.mathworks.toolbox.instrument.SerialComm
.
Below is the code I am using:
AComPort = GetAvailableComPort; % Get all available com ports. (borrowed function, can be found online)
y = length(AComPort); % Get how many com ports are available
SPort = AComPort(y); % By default choose last port on list
BRate = 115200; % By default choose 115200 baud rate
myComPort = InitPort(SPort,BRate); % Initialise and open com port
.
This is my own function for initialising ports:
function [ myComPort ] = InitPort( SPort, BRate )
%InitPort - Initialises a com port
obj=instrfind; % Clear all com ports ensuring they are available
if ~isempty(obj);
delete(obj);
end;
myComPort = serial(SPort,'BaudRate',BRate,'DataBits',8,'StopBits',1,'Terminator',0);
% Initialise a port called myComPort
fopen(myComPort); % Open port for read/write
end
.
Neither logging off and logging back in again or re-starting the computer have helped.
This is making it impossible for me to connect to the serial device. Does anyone have any ideas on how to solve this issue?
Thanks,
Jasmine
7 个评论
Geoff Hayes
2014-7-16
What is SPort defined to be? Consider putting a breakpoint at line 118 of serial.m and then re-run the code. When the debugger stops at this line, type varargin{1} in the Command Window and see what appears.
Jasmine
2014-7-16
Geoff Hayes
2014-7-16
Won't that be a problem, if the port is empty/null?
Geoff Hayes
2014-7-17
Are you sure that the serial ports, once opened, are being closed via your ClosePort(myComPort)? If still open, then they won't be "seen" by the GetAvailableComPort call.
It would be interesting to see which ports are being used through the run of your GUI. Is it the same one, every time you invoke myComPort = InitPort(SPort,BRate); or is it a different one? Just add an fprintf('port: %s\n',SPort); statement before or after each InitPort to see what is happening.
Jasmine
2014-7-18
Geoff Hayes
2014-7-18
Good that you figured it out!
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!