From: moshe on
"Steven_Lord" <slord(a)mathworks.com> wrote in message <i21nr8$f1f$1(a)fred.mathworks.com>...
>
>
> "moshe " <reubinoff(a)hotmail.com> wrote in message
> news:i21k1k$8v2$1(a)fred.mathworks.com...
> >
> >>
> >> Besides us' comment on baud rates, the reallocation on every loop you're
> >> doing will cause it to slow down as t() grows.
> >>
> >> Pre-allocate the t array to some size and fill instead...
> >>
> >> --
> > 1) This kit support only 9600 baud rate
> > 2) I tried to Pre-allocate the cell_array (p is only the index) and this
> > does not work.
>
> Show the group how you tried to preallocate the cell array and what you mean
> by "this did not work". Did you do something like this?
>
> n = 1000;
> C = cell(1, n);
> for k = 1:n
> C{k} = repmat('hello ', 1, n);
> end
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hi,
I tried this:

clc ; clear all;del_port;

ArrLength =1000; %length of the two arrays
arr=1;
arr1=zeros(1, ArrLength );
arr1=cell(size(arr1)) ;p1=1; %init 1st array
arr2=zeros(1, ArrLength );
arr2=cell(size(arr2)) ;p2=1;


Buffer =[];

SerialPort =serial('com3');
set(SerialPort ,'InputBufferSize',100000);
fopen(SerialPort );
temp=fscanf(SerialPort );


while 1

switch arr
case 1
while (SerialPort .BytesAvailable>0) && arr==1
temp=fscanf(SerialPort );
arr1{p1}=(temp(7:11));
p1=p1+1;
if p1==ArrLength +1
p1=1;
arr=2;
disp('switch array');
ar=str2double(arr1);
Buffer =[Buffer ar];
plot(ar);
title('arr1');
end
end

case 2
while (SerialPort .BytesAvailable>0) && arr==2
temp=fscanf(SerialPort );
arr2{p2}=(temp(7:11));
p2=p2+1;
if p2==ArrLength +1
p2=1;
arr=1;
disp('switch array');
ar=str2double(arr2);
Buffer =[Buffer ar];
plot(ar);
title('arr2');
end
end
end
end



fclose(SerialPort );

From: Walter Roberson on
moshe wrote:

> I tried this:

> switch arr
> case 1
> while (SerialPort .BytesAvailable>0) && arr==1
> temp=fscanf(SerialPort );
> arr1{p1}=(temp(7:11));

Your code implies that you are reading a minimum of 12 characters per
line (you use up the the 11th and each line must have at least 1
terminator character.) The maximum sample rate you will be able to get
with that is

9600 baud / (1 bits/baud) / (10 bits / character) / (12 characters /
sample)

which works out as 80 samples per second -- far far too slow for the
1000 samples per second rate you want to process.


As I indicated in an early posting, you cannot read 1000 samples per
second through a 9600 baud serial port unless you can average slightly
less than 1 character per sample, including any terminator characters.
First  |  Prev  | 
Pages: 1 2 3
Prev: gate
Next: For loop iteration number?