I am working on a MATLAB class which stores an interface object created with tcpip
and includes a callback function for the interface object to use, as per the following example:
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
%STATIC METHODS
methods (Static)
%TCP Callback
%This function will be called if one Byte is available at the TCPIP
%buffer.
function TCP_Callback(tcpsocket,event,obj)
fprintf('Loading 1 Byte Data From Buffer.\n')
end
end
end
When I clear my class the variable will be cleaned from the workspace, but the delete
destructor function is not called. Why not?
I realized, that my Instruments are still active in the Instrument Control app. If I delete my Instruments from there, my delete
destructor is be called.
I think it is some strange behaviour of the tcpip-class.