i am reading data from a node with four force sensors and Xbee and i have Xbee receiver.i want to get the sensors data continously int to my pc using serial communication.my sensor data lies in 13,15,17,19 bytes of a 20 byte packet sent by Xbee

2 Ansichten (letzte 30 Tage)
%run('clean');
clear all;
close all;
delete(instrfindall);
s = serial('COM5'); %assigns the object s to serial port
s.ReadAsyncMode = 'continuous';
set(s, 'InputBufferSize',20); %number of bytes in inout buffer
set(s, 'BaudRate', 115200);
set(s,'Terminator','LF')
%clc;
x=0;
y=0;
z=0;
w=0;
fopen(s);
%opens the serial port
disp('Running');
while(true)
a =fscanf(s);%reads the data from the serial port and stores it to the matrix a
a1=str2num(a);
s1=a1(13);
x =[x s1];% Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
plot(s1,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
s2=a1(15);
y =[y s2];
plot(s2,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
s3=a1(17);
z =[z s3];
plot(s3,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
s4=a1(19);
w =[w s4];
plot(s4,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
a1=0; %Clear the buffer
fclose(s); %close the serial port
end
i am facing error-----Warning: Unsuccessful read: The input buffer was filled before the Terminator was reached. Attempted to access a1(13); index out of bounds because numel(a1)=0.
  13 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 19 Mär. 2014
If there is never a terminator configure BytesAvailableFcnMode = 'byte' and do not configure Terminator, and use
a = fread(s, 20, '*uint8');
  14 Kommentare
avinash pabbireddy
avinash pabbireddy am 26 Mär. 2014
ReadFile(g_hComPort, gyroBuffer, 7, &dwBytesRead, NULL);
ReadFile(g_hComPort, gyroBuffer, 9, &dwBytesRead, NULL); what are these two lines in C# code?? there is no change in output eventhough the input is changed to sensor

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by