Cannot create serial port: Error using serial (line 120)?

6 views (last 30 days)
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 Comments
Jasmine
Jasmine on 18 Jul 2014
I've worked out why it wasn't working. My own silly mistake.
I was using a cut-down version of my code as I wanted to debug a simple version before re-adding in the extra features, including a user set port. Only I had a variable called SettingsPressed which went high if the user had set port settings. Otherwise it was low and an if statement said 'if low run GetAvailableComPort '.
However, since my cut-down code didn't set SettingsPressed, GetAvailableComPort didn't get run and the user hadn't set up the port.
I think this fully explains why ans = [] when typing varargin{1} at the command line.
Thank you for suggesting that, I don't think I would have realised what my issue was otherwise.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!