ultraviolet_ray
Newbie level 6
I am trying to send an infinite sequence of charachters from AVR to PC, by using COM 1 and 2400 baudrate.
The hyperterminal sucessively shows the received charachters , but if I try to plot or visualise the result using MATLAb using COM1, an error appears saying:
??? Error using ==> serial.fopen
Port: COM1 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
I am using the following code:
I even closed the hyperterminal(incase the error is being generated because of the connection at hyperterminal), but I still get the same error.
The hyperterminal sucessively shows the received charachters , but if I try to plot or visualise the result using MATLAb using COM1, an error appears saying:
??? Error using ==> serial.fopen
Port: COM1 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
I am using the following code:
Code:
%run('clean');
clear all;
close all;
s = serial('COM1'); %assigns the object s to serial port
set(s, 'InputBufferSize', 256); %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 2400);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
%clc;
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]);
fopen(s); %opens the serial port
int t =1;
disp('Running');
x=0;
for t = 1:200
a =fread(s); %reads the data from the serial port and stores it to the matrix a
a=max(a); % in this particular example, I'm plotting the maximum value of the 256B input buffer
x =[x a]; % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
%Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
%data at the end!
plot(x);
axis auto;
grid on;
disp([num2str(t),'th iteration max= ',num2str(a)]);
hold on;
t=t+1;
a=0; %Clear the buffer
drawnow;
end
fclose(s); %close the serial port
I even closed the hyperterminal(incase the error is being generated because of the connection at hyperterminal), but I still get the same error.
Last edited: