LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

device connection class (general OOP question, but I'm implimenting it in labview) - where/how to impliment connection settings of connection types??

Hello!

 

I want to make a device connection class, and have multiple connection types. (Serial, TCP, UDP, GPIB, etc...). 

I think I have a general idea of how the layout should go, but I'm kinda stuck as to where I should impliment some parts of it.

 

Here is what I am fairly sure of right now, but any suggestions are welcome:

 

Connection (Base class - mostly virtual)

 with override methods: Open, Close, Read, and Write

 and a few parameters: Refnum, isConnected?,  timedOut?, dataReady?

 

Serial (Inherits from Connection)

with Open, Close, Read, and Write Overrides

 

TCP (Inherits from Connection)

with Open, Close, Read, and Write Overrides

 

...and the same layout for UDP/GPIB and others. 

 

Then I'm also planning on having a base class called 'Device' which contains a 'Connection' object.  Then I can have each specific device inherit from 'Device'.

 

The place where I'm getting stuck is trying to sort out the settings of each type of connection.  For example, where and how would I initiate/setup the ip address and port with a TCP connection, or baud rate and flow control of the Serial connection?  I was originally just going to put a 'configure' function in each of the classes (TCP, Serial, etc...) and have those classes store that information, but I when I started thinking implimentation, it just doesn't seem right...I would have to change to a different class, as well as change the configuration setup for each type... So, I'm thinking there has to be a different way.

 

Another idea was to use a configuration object and have that in the base Connection class with all the settings I would ever need, and then pass in a configuration object to the connection type class which would then override a base Method to write the settings in.

 

So I guess the question is: where/how do I impliment the connection settings for each connection type in OOP?

 

Any help is appreciated!

 

Thanks,

Jonathan 

-----
LV 8.2/8.5/8.6 - WinXP
Message 1 of 6
(3,231 Views)

malkier wrote:

Hello!

 

I want to make a device connection class, and have multiple connection types. (Serial, TCP, UDP, GPIB, etc...). 

I think I have a general idea of how the layout should go, but I'm kinda stuck as to where I should impliment some parts of it.

 

Here is what I am fairly sure of right now, but any suggestions are welcome:

 

Connection (Base class - mostly virtual)

 with override methods: Open, Close, Read, and Write

 and a few parameters: Refnum, isConnected?,  timedOut?, dataReady?

 

Serial (Inherits from Connection)

with Open, Close, Read, and Write Overrides

 

TCP (Inherits from Connection)

with Open, Close, Read, and Write Overrides

 

...and the same layout for UDP/GPIB and others. 

 

Then I'm also planning on having a base class called 'Device' which contains a 'Connection' object.  Then I can have each specific device inherit from 'Device'.

 

The place where I'm getting stuck is trying to sort out the settings of each type of connection.  For example, where and how would I initiate/setup the ip address and port with a TCP connection, or baud rate and flow control of the Serial connection?  I was originally just going to put a 'configure' function in each of the classes (TCP, Serial, etc...) and have those classes store that information, but I when I started thinking implimentation, it just doesn't seem right...I would have to change to a different class, as well as change the configuration setup for each type... So, I'm thinking there has to be a different way.

 

Another idea was to use a configuration object and have that in the base Connection class with all the settings I would ever need, and then pass in a configuration object to the connection type class which would then override a base Method to write the settings in.

 

So I guess the question is: where/how do I impliment the connection settings for each connection type in OOP?

 

Any help is appreciated!

 

Thanks,

Jonathan 


Hi Jonathan,

 

I am far from an expert at OOP so the best I can do is act as a sounding board.

 

What is wrong with adding a "Configure" method to the class "Connection" which over-riden by each of its children?

 

I would think that would allow you to add new children in the future without having to make modes to the parent as would be the case if you went with the  "all the settings I would ever need," approach.

 

I believe you can see an example of this in LV's objects. If you edit the properties of a FP control, there are common attributes that are available for all VL objects, like "Name", "Visable, etc. For Numerics you will see representation and formatting that are avaliable on different pages of the properties dialog screen.

 

Not sure if any of that helped. Please explain what issue I am missing.

 

Have fun!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 6
(3,225 Views)

Ah, ok...I didn't quite explain that part correctly.

 

If I add a configure method in the base class, then I have to match the input parameters in all the sub-classes.  I thought this might be an issue since they are different in each type of connection. Then I thought maybe I could use an object for each set of settings, maybe a varient would work just as well...

Though in the object case, I could create a base class called connection_settings, then have the settings for each device inherit from that...but now this seems overkill (or is it?) because I have objects for both connection type and connection settings type....

 

Hrm, I'll take a look at the control properties now to see if I can deduce anything....I'm still new to implimenting this OOP stuff so maybe something will click if I keep looking at examples...

-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 3 of 6
(3,216 Views)
Hrm, Ok, I think I'm going to have the same problem if I make the connection settings an object too....I still need some way of using different data types to read/write the settings...which brings me back to thinking I should just have a static configuration method in each connection type object and call the method when the object is instantiated, or use a varient in the base class.  I've been leaning away from varients since I don't use them very often, but it seems like this might be the best way to go, still exploring options though.
-----
LV 8.2/8.5/8.6 - WinXP
0 Kudos
Message 4 of 6
(3,203 Views)

malkier wrote:

Hello!

 

The place where I'm getting stuck is trying to sort out the settings of each type of connection.  For example, where and how would I initiate/setup the ip address and port with a TCP connection, or baud rate and flow control of the Serial connection?  I was originally just going to put a 'configure' function in each of the classes (TCP, Serial, etc...) and have those classes store that information, but I when I started thinking implimentation, it just doesn't seem right...I would have to change to a different class, as well as change the configuration setup for each type... So, I'm thinking there has to be a different way.

 

So I guess the question is: where/how do I impliment the connection settings for each connection type in OOP?

 

Any help is appreciated!

 

Thanks,

Jonathan 


I'm NO expert on OOP either but here goes... Setup your base class with all the controls group together using clusters for different types of connections. These controls are private to be used only by child class. Again, in your base class, one cluster for IP/tcp, another for serial.... the child class only needs to set/get and change the cluster thats its needs to use for the specific connection functionality...

 

And I haven't used the OOP yet...Smiley Wink

 

Message Edited by richjoh on 10-31-2008 09:03 AM
0 Kudos
Message 5 of 6
(3,201 Views)

malkier wrote:
which brings me back to thinking I should just have a static configuration method in each connection type object and call the method when the object is instantiated...

My thought exactly. What you basically want is a constructor, which doesn't exist in LVOOP, so what you want to do is instruct the class user to only create objects using that VI, which will include your config for each class. All the other methods pretty much go against encapsulation (except the config class, but that seems to just be duplicating the class hierarchy for no reason, since most or all classes will not share config options).

 

Disclaimer - I know LVOOP, but have no real practical experience with it, nor am I that much into OOP. But that's just what I think.


___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(3,171 Views)