Jump to content

Switching out communication actors


Recommended Posts

I have a question relating to inheritance in one of my programs. When at a customer's site we have Ethernet IP available, which will ultimately be what is used for communication between a PLC and our application upon delivery. However, because I don't have ethernet IP available elsewhere, I was hoping to use TCP/IP when in the office and write a simulator to substitue for E-IP when I don't have it available . The issue is, it doesn't really make sense to have TCP/IP and ethernetIP classes both inherit from a same base class (say, communication class) because the ethernet IP drivers don't really have similar functionality to TCP/IP exposed. With ethernet IP, although it uses TCP/IP underneath it, the API is just a polymorphic VI with an input for the address and tag name. You don't need to open anything, or hold a reference to the session etc. I am wondering if there is some way to set up the class structure so I can easily switch out ethernetIP with TCP/IP and vice versa, even if it does not make sense for them to both inherit from the same base class.

post-15770-0-82554500-1334790629.png

Edited by for(imstuck)
Link to comment

Well,as so often happens when learning something new i either:

1) think I get it but actually don't get it

2) when it comes to implementing it I get overwhelmed.

I believe this is a case of both. The reason for part of my confusion is Wikipedia seems to show delegation as being a class which has a member object that may be set and this object is a parent of multiple different children. This can then be set to a child object and the programmer has the ability to always call delegate.method which will call childthatwasset.method. because each childthatwasset method overrides parent.method the class can delegate based on the object. This results in only changing the member class set in the delegator but then the function calls exposed to the programmer don't change. A wrapper of sorts (which just sounds to me like inheritance with a wrapper layer so maybe I'm reading the c++ code example wrong) Then, the NI example seems to show calling the same code from within different classes. Maybe I am misreading Eli's description. So, any clarification is appreciated.

Now, the second issue I have is this. When setting this up I'm not exactly sure how to handle everything. I basically have 3 different classes that all do the same thing, manage some handshaking. One will use daqmx to read DI, one Ethernet IP, one TCP/IP. I suppose each could still have an open, read, close method which are delegated. A simple example would be much appreciated as I seem to be making minimal progress!

Sorry for any typos or confusing descriptions. Wrote this from my phone.

Edit: Wikipedia I referenced http://en.m.wikipedia.org/wiki/Delegation_pattern#section_1

Edited by for(imstuck)
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.