Error when trying to read data from serialport

19 Ansichten (letzte 30 Tage)
Javier Mateo
Javier Mateo am 7 Jan. 2021
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 Kommentare
Javier Mateo
Javier Mateo am 8 Jan. 2021
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 am 21 Mär. 2021
you have to create whatver you want to plot within the function.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by