Error when trying to read data from serialport
10 views (last 30 days)
Show older comments
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 Comments
Samuel Olufemi Taiwo
on 21 Mar 2021
you have to create whatver you want to plot within the function.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!