USBのセンサから出力されたバイナリデータの変換方法を教えて下さい
2 ビュー (過去 30 日間)
古いコメントを表示
Daisaiku Senoo
2016 年 12 月 21 日
コメント済み: Walter Roberson
2016 年 12 月 22 日
USB出力のジャイロセンサをPCに接続して使用しています。 Matlabのコマンドウィンドウから、以下のようにRAWデータの要求を行いデータが返ってきました。 しかしながら、肝心な測定データがバイナリデータのため文字化けしてしまいました。

また、RAWデータフォーマットは以下のようになっています。

データ型:X(ASCII) U(Unsigned) I(Signed)
バイナリデータから測定値に変換する方法を教えてください。 よろしくお願いします。
1 件のコメント
Walter Roberson
2016 年 12 月 21 日
編集済み: Walter Roberson
2016 年 12 月 21 日
Approximate translation:
USB output gyro sensor is connected to the PC. From the command window of Matlab, we requested RAW data and returned the data as follows. However, since the measurement data which is important is binary data, it got garbled.
The RAW data format is as follows.
採用された回答
Walter Roberson
2016 年 12 月 21 日
You should use fread() rather than fscanf() when you are working with binary. You should also be reading a specific number of bytes, rather than looking for a line terminator, as the line terminator can accidentally occur in the binary. You should configure BytesAvailableFcnMode to 'bytes'.
2 件のコメント
Walter Roberson
2016 年 12 月 22 日
The "Data Size" appears to start counting from the '$' but not to include the CR LF.
It appears that the data is in Big-Endian format, so you probably need to swapbytes() on the data.
angular_x = swapbytes( typecast(out(18:19), 'int8') );
angular_y = swapbytes( typecast(out(20:21), 'int8') );
angular_z = swapbytes( typecast(out(22:23), 'int8') );
acceleration_x = swapbytes( typecast(out(24:25), 'int8') );
acceleration_y = swapbytes( typecast(out(26:27), 'int8') );
acceleration_z = swapbytes( typecast(out(28:29), 'int8') );
and so on.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
