現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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
4 ビュー (過去 30 日間)
古いコメントを表示
%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 件のコメント
Walter Roberson
2014 年 3 月 16 日
On the first packet, or after it has been running for a time?
The behaviour of fscanf() is undefined when you do not provide a format specification.
Walter Roberson
2014 年 3 月 16 日
Okay, have you tried adding a format to the fscanf()? Perhaps what you want is fgetl() instead of fscanf() ?
avinash pabbireddy
2014 年 3 月 17 日
Undefined function 'fget1' for input arguments of type 'serial'. i am getting this error and i am facing same error which i have mentioned above even though i am using format specification
Salaheddin Hosseinzadeh
2014 年 3 月 18 日
'fget1' is of course undefined to matlab it's FGETL all lower case. It reads a LINE that's why it ends with L not number one 1
lol
avinash pabbireddy
2014 年 3 月 18 日
same error is repeating even if i use fgetl() 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.
Walter Roberson
2014 年 3 月 18 日
Try increasing your input buffer size -- if the terminator is indeed present then it is not going to matter that your buffer is longer than strictly required.
Double-check that LF alone is the terminator. CR alone or CR+LF are common.
avinash pabbireddy
2014 年 3 月 19 日
126 0 16 131 16 7 40 0 1 30 0 0 176 0 166 0 168 0 169 119 this is one packet sent by xbee where 13,15,17,19 are sensor data and theres is no value equal to terminator
avinash pabbireddy
2014 年 3 月 19 日
i am trying to read the data using fread i am able to get data but it is not correct
Walter Roberson
2014 年 3 月 19 日
Are you saying that packets are determined by length and there is never a terminator?
回答 (1 件)
Walter Roberson
2014 年 3 月 19 日
If there is never a terminator configure BytesAvailableFcnMode = 'byte' and do not configure Terminator, and use
a = fread(s, 20, '*uint8');
14 件のコメント
avinash pabbireddy
2014 年 3 月 19 日
i have configured terminator as empty and i used a = fread(s, 20, '*uint8'); then ia m getting error as
Invalid PRECISION specified. Type 'help serial/fread' for more information.
i tried using it as a = fread(s, 20, 'uint8'); but i coulsnt see the change in data
avinash pabbireddy
2014 年 3 月 19 日
i am able to get the data but some of the data contains values less than 175,166,168,168 values which is equal to 0 force for each sensor.if i read the data normally using fread() by specifying buffer size i am getting accurate data
avinash pabbireddy
2014 年 3 月 20 日
thank walter roberson for your suggestions i tried using 'int8' i wonder i am getting negative values
avinash pabbireddy
2014 年 3 月 20 日
i am applying max force input to one of the sensor =255 but i am reading it as
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178200/image.jpeg)
Walter Roberson
2014 年 3 月 23 日
If you get any value >= 128 in the int8 then something has gone wrong: values 128 and higher should come out negative in int8.
Walter Roberson
2014 年 3 月 23 日
When I look at your graph I get the impression that the values are biased, that a non-load input would be represented by a value other than 0. As if, for example, one should read the data in uint8 form, convert to int16, and then subtract 128 or perhaps 160 to get the actual value.
I'm not going to know without the documentation for the sensor.
Walter Roberson
2014 年 3 月 25 日
Each data channel is a two byte unsigned integer, stored big-endian (most significant value is first, which is not the default for fread()). Take the two bytes and convert to floating point. Subtract 170. Divide the result by 853 to get 0 to 1 pound.
ch1 = fread(s, 1, '*uint16', 'be');
force1 = (double(ch1) - 170) / 853;
avinash pabbireddy
2014 年 3 月 26 日
i have changed byte order to big endian and followed the instruction you have given but i am getting the graph as
avinash pabbireddy
2014 年 3 月 26 日
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
avinash pabbireddy
2014 年 3 月 26 日
wat about left shift followed by and operation to convert in to 0-1 pound??
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)