Reputation: 1008
I wanted to create a TCPIP object inside a class. I have some problems to figure out how to done this.
First I will show a working code snippet:
>> %Creating the TCPIP object
>> TCPIP = tcpip('localhost',1000)
TCPIP Object : TCPIP-localhost
Communication Settings
RemotePort: 1000
RemoteHost: localhost
Terminator: 'LF'
NetworkRole: client
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
>> %Changing Buffersize as example
>> TCPIP.OutputBufferSize = 30000
TCPIP Object : TCPIP-localhost
Communication Settings
RemotePort: 1000
RemoteHost: localhost
Terminator: 'LF'
NetworkRole: client
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
As you can see the command line output of the Buffersize change is not shown. I can't visualize this correctly but I try to explain: After creating the TCPIP object Matlab creates the variable TCPIP
with the value 1x1 tcpip
. If I double click this value I can see all properties of the object, including outputBuffersize
.
Now I will show my first try of implemantation in class. I tryied to create the tcpip object inside a methode that saves the variable TCPIP
(like explained before) inside my class properties.
classdef tcp_test < handle
properties
TCPIP
end
methods
%CONSTRUCTOR
function Obj = tcp_test(~)
ipobject(Obj);
end
%DECONSTRUCTER
function delete(~)
end
%Create TCPIP Object
function ipobject(Obj)
Obj.TCPIP = tcpip('localhost',1000);
Obj.TCPIP.OutputBufferSize = 30000;
end
end
end
This class example is working with any error output, but I recognized something that seems not working as I expected. After creating the class object ´myTCP = tcp_test´ I tryed to investigate the the Object ´myTCP.TCPIP´ and realized that it looks like empty. Actually all necessary properties are set and I can change them, they are just not shown.
This leads to the original Question: I thought I have to inherit the tcpip class to use the class methods.
I still have the feeling that I still doing something wrong, because of the missing visualisatiuon.
Upvotes: 2
Views: 142
Reputation: 30047
I think this is just a lack of understanding what is displayed in the command window - it's not all of the properties of the object, sometimes just a subset. If you type get( TCPIP )
in the command window, you will see all properties including the OutputBufferSize
. Similarly, t = tcp_test; get( t.TCPIP )
will show the same properties.
You can see, from typing edit tcpip
in the command window, that the tcpip
class has the following properties:
properties(Hidden, SetAccess = 'public', GetAccess = 'public')
icinterface
end
It inherits from the instrument
class which is not editable, and will have other properties we can't see the definitions for.
The important thing here is the Hidden
attribute. From the docs:
MATLAB does not display in the command window the names and values of properties having protected or private GetAccess or properties whose Hidden attribute is true.
This is why you can't see the property in the workspace. However, you can freely edit the properties, and view them using the general get( TCPIP )
, or a specific get
command:
outBuffer = get( TCPIP, 'OutputBuffer' );
More simply done with dot indexing
outBuffer = TCPIP.OutputBuffer;
Upvotes: 1