フィルターのクリア

Error when trying to read data from serialport

15 ビュー (過去 30 日間)
Javier Mateo
Javier Mateo 2021 年 1 月 7 日
Hello!
I have a serialport connected, like this:
s =
Serialport with properties:
Port: "COM9"
BaudRate: 115200
NumBytesAvailable: 950
The data I gather from here looks like this:
>> readline(s)
ans =
"*RRN:00000000C76D,00000000C6F1,0,000651,0004,-59"
This device is receiving that kind of data every second or so (it´s not fixed). So "NumBytesAvailable" increases every time (I believe it is 50 Bytes every line). I want to read every of these lines, every time there is a new one. But I don´t know how to use "Callback".
When Callback is on, I have these error (increasing errors every time there is new data in terminator)
>> configureCallback(s,"terminator",@callbackFcn)
Warning: Error occurred while executing the listener callback for event DataWritten defined for class asyncio.InputStream:
Undefined function 'callbackFcn' for input arguments of type 'internal.Serialport'.
Error in internal.Serialport/callbackFunction (line 1353)
obj.BytesAvailableFcn(obj, dataAvailableInfo);
Error in internal.Serialport>@(varargin)obj.callbackFunction(varargin{:}) (line 958)
obj.StringClient.StringReadFcn = @obj.callbackFunction;
Error in matlabshared.transportclients.internal.StringClient.StringClient/DataAvailableCallback
Error in matlabshared.transportclients.internal.StringClient.StringClient>@(varargin)obj.DataAvailableCallback(varargin{:})
Error in matlabshared.seriallib.internal.Serial/onDataReceived
Error in matlabshared.seriallib.internal.Serial>@(varargin)obj.onDataReceived(varargin{:})
Error in asyncio.Channel/onDataReceived (line 487)
notify(obj.InputStream, 'DataWritten', ...
Error in asyncio.Channel>@(source,data)obj.onDataReceived() (line 425)
@(source, data) obj.onDataReceived());
> In asyncio/Channel/onDataReceived (line 487)
In asyncio.Channel>@(source,data)obj.onDataReceived() (line 425)
Warning: Error occurred while executing the listener callback for event DataWritten defined for class asyncio.InputStream:
Undefined function 'callbackFcn' for input arguments of type 'internal.Serialport'.
Error in internal.Serialport/callbackFunction (line 1353)
obj.BytesAvailableFcn(obj, dataAvailableInfo);
Error in internal.Serialport>@(varargin)obj.callbackFunction(varargin{:}) (line 958)
obj.StringClient.StringReadFcn = @obj.callbackFunction;
Error in matlabshared.transportclients.internal.StringClient.StringClient/DataAvailableCallback
Error in matlabshared.transportclients.internal.StringClient.StringClient>@(varargin)obj.DataAvailableCallback(varargin{:})
Error in matlabshared.seriallib.internal.Serial/onDataReceived
Error in matlabshared.seriallib.internal.Serial>@(varargin)obj.onDataReceived(varargin{:})
Error in asyncio.Channel/onDataReceived (line 487)
notify(obj.InputStream, 'DataWritten', ...
Any help please? Thank you in advance
  5 件のコメント
Javier Mateo
Javier Mateo 2021 年 1 月 8 日
Yes, it worked flawlessly, thank you!
I can get the data in the command window. However, my goal is to play with this data and plot it in real time.
Could you please help me with that? I dont see the variable "data" in the workspace. I don´t know how to play with this data then
If I try to write any code below the readSerialData.m code, the callback terminator does not work anymore
Samuel Olufemi Taiwo
Samuel Olufemi Taiwo 2021 年 3 月 21 日
you have to create whatver you want to plot within the function.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSerial and USB Communication についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by