Use TCPIP with callback inside a class

조회 수: 2 (최근 30일)
Matti Kaupenjohann
Matti Kaupenjohann 2020년 1월 27일
I have a problem with a the tcpipsocket in use with a class as property. The class inherits handle to work with constructor and destructor. All works fine until I activate the BytesAvailableFunction. After the Activation the destructor will no longer be called by deleting my workspace. It seems that my class is referenced somewhere in the instrument control, because calling instrreset after deleting my workspace, calls my destructor function.
Here is a minimal example that reproduce the error:
classdef wsg50_mini2 < handle
properties
TCPIP
end
%PUBLIC METHODS
methods
%CONSTRUCTOR
function obj = wsg50_mini2(varargin)
fprintf('################# I am created #################\n')
obj.TCPIP = tcpip('localhost',1000);
obj.TCPIP.OutputBufferSize = 3000;
obj.TCPIP.InputBufferSize = 3000;
obj.TCPIP.ByteOrder = 'littleEndian';
obj.TCPIP.Timeout = 1;
%Setting up Callbackfunction
obj.TCPIP.BytesAvailableFcnMode = 'byte';
obj.TCPIP.BytesAvailableFcnCount = 1;
obj.TCPIP.BytesAvailableFcn = {@obj.TCP_Callback, obj};
end
end
%PRIVATE METHODS
methods (Access = private)
%DESTRUCTOR
function delete(obj)
fprintf('################# Hey I am called! #################\n')
instrreset
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by