Sunday 27 January 2013

Access serial port using Matlab code


AccessSerialPort.m


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', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
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
t=1;
disp('Running');
x=0;
while(t<200 p="">   a =fread(s);
   a=max(a);
   x =[x a];
   plot(x);
   axis auto;
   grid on;
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;
   drawnow;
end

fclose(s); %close the serial port

2 comments:

  1. Thanks for providing such wonderful information in this nice article, I really appreciate your hard work behind this nice post. I have bookmarked this article for my future reference. I have a suggestion that now it is easy to solve any problem regarding any Browsers/Computers etc along with Hotmail related problems (If any) with the help of information on customer care services, customer care contact numbers, chat numbers, tech support numbers ( Toll Free Numbers ) information of various USA, UK and CANADA companies provided in the Website http://customercaresupportnumber.com/hotmail-customer-care-service-support-phone-number-microsoft-usa/

    ReplyDelete
  2. The blog posted is very interesting from all aspects and it will surely benefit the readers by all means.

    ReplyDelete