Error occurred while executing the listener callback for event DataWritten defined for class asyncio.InputStream

30 次查看(过去 30 天)
Hi,
I am reading data over TCP/IP from hardware device using
t1=tcpclient("xxxx",xxxx)
I am configuring callback function, so that when ever 210 data byes avaible to read function1() execute.
while t1.BytesAvailable == 0
%wait for data
end
configureCallback(t1,"byte",210,@varargin()function1())
function function1()
Bytes_DATAF1=t1.NumBytesAvailable
DATA=read(t1,210);
decode=swapbytes(typecast(uint8(DATAF1(1,7:10)'),'uint32'));
Bytes_DATAF2=t1.NumBytesAvailable
end
codes doing fine but in middle giving following warning.
Warning: Error occurred while executing the listener callback for event DataWritten
defined for class asyncio.InputStream:
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
Error in matlabshared.network.internal.TCPClient/onDataReceived
Error in
matlabshared.network.internal.TCPClient>@(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)
--------------------------------------------------------------------------------------------------------
function function1()
Bytes_DATAF1=t1.NumBytesAvailable
DATA=read(t1,210);
decode=swapbytes(typecast(uint8(DATAF1(1,7:10)'),'uint32'));
Bytes_DATAF2=t1.NumBytesAvailable
end
bytes availabe to read
t1.BytesAvailable=Bytes_DATAF1 =12810
mycode reads only 210 bytes
bytes remaining to read
t1.BytesAvailable=Bytes_DATAF2 = 255
12810-255=12555 bytes missing.

采纳的回答

Sugandh Pratap Singh
Error resolved using following command.
configureCallback(t1,"terminator",@(varargin)function1())

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by