08-16-2013 03:21 AM
Hello Tim,
An OOP approach might be interesting.
I was thinking about something using the Actor Framework.
Have you (in the following of the presentation) played with it yet?
08-16-2013 07:33 AM
Hello Thierry C,
I opened the actor framework template.
However I still need a lot of training before I am able to read/understand the code in the template.
I did have a look at the factory pattern?? (queued message handler where you transmit classes and dynamic dispatch handles the conversion) but if you have a better suggestion it's always welcome.
Another option where I might make some improvement with OOP (for now) in my code is in the storage/retrieval of the data contained in my devices.
The setup I have is the following:
Serial bus
|
|--Card 0 --device 0
| --device 1
| --device 2
| --device 3
|--Card 1 --device 0
| --device 1
| --device 2
| --device 3
....
....
|--Card 6 --device 0
| --device 1
| --device 2
| --device 3
The trick is that each card communicates with the connected devices and stores this data internally. My Labview program has to poll the cards and grab (and store) the data. A 2nd trick is that the cards can change and/or are missing. (The program of the cards is done by me so changes are an option.)
Now I'm thinking of it what I could do is to create a "card" class and create subclasses for each card.
So can I create an array of classes where I dynamically can connect them to their respective classes?
I hope this clarifies some questions cou might have and create a lot more
.
Thanks at least for staying with me,
Tim
08-19-2013 03:47 AM
Hello Tim,
Do you mean instances of classes (objects) instead of subclasses?
Is each card exactly the same (but only with different devices connected)?
08-20-2013 04:43 AM - edited 08-20-2013 04:44 AM
Hello Thierry C,
As for the cards, there are multiple types of cards (can be identified by sending a command to the card) but every card get's only 1 type of device.
So if I'm correct I have subclasses for every board/device type and instances per card/device.
So to refrase the original question:
So can I create an array of classes instances where I dynamically can connect them the cards to their respective classes? Also each card needs a separate array for every device.
Thanks,
Tim
08-21-2013 06:42 AM - edited 08-21-2013 06:42 AM
Hello Tim,
You could have for example an
- Array of card instances (one instance for each active card for example).
Each card instance could then for example internally store it's actual reference to that card (this could be a device name, device handle or any way you can identify the right card to send to, etc...).
To store this information in an instance of a certain class you just have to provide a place to store that information in your common parent class.
Afterwards you can use dynamic dispatching so that you use the appropriate method/VI for the appropriate instance
- Inside each card instance you could also have an array of device instances.
It could be that I'm talking now an unknown language to you, so to be sure I just want to check if you are at this moment familiar with following terms like:
- Parents/Children
- Inheritance
- Dynamic Dispatching
If not, then please first have a look at this session:
http://zone.ni.com/wv/app/doc/p/id/wv-3353
08-23-2013 04:00 AM
Hello Thierry C,
So I just watched the session you recommended.
So now I am more familiar with the terms you used in your post. (I kinda messed-up subclasses and children)
Now the question becomes: what (private) data should I store in my classes and what accessors am I gona use for this.
At the moment I am thinking of the following:
(I might need to put in aditional leveling in the cards and devices since some data is on certain cards/devices and not on others)
However I am somewhat puzzled about the methods I could be using.
Examples all cards can do:
Examples of the device specific data (up to 4 devices are connected to a card)
Also: should I place the actual serial handling in the card class or in a pice of normal code
Hoping you can help,
Tim
08-26-2013 06:20 AM - edited 08-26-2013 06:23 AM
Hello Tim,
It's very difficult for me to tell you at which level some things should be implemented and how it should be implemented without knowing the differences between Card Type A, Card Type B, ... and how you're at this moment (succesfully) implementing it.
Also there is no one perfect way to implement abstraction in general.
Each way has its positive points and drawbacks.
To know what "private data" you should store internally you will have to make an abstraction of all of the tasks your cards should accomplish.
UML Diagrams can be very useful and should be used in your first design stage.
I think a first step should be to define and (on a high-level) "implement" a first approach/test yourself. (This could be done through some dummy code)
In this case take a very limited amount of Card Types (for example 2) and a limited set of devices.
You can make a simple hierarchy and a simple demo to illustrate how you're going to implement some inheritancy and functionality.
Making a prototype like this can already give you valuable insights into the limitations of a certain approach.
Once you've made a simple test I'm always willing to provide you with feedback about it.
09-13-2013 04:59 AM
Hello Thierry C,
Sorry that the reply took so long,
Based on our discussion here on the forum I decided that it would better for my program to do a full re-write (it now includes a hal).
For the challenge I have with my current version I'll create a new thread if required so others can join as well.
Thanks for the help so far.
Tim
09-25-2013 06:22 AM - edited 09-25-2013 06:22 AM
Hello Tim,
I just saw your post today.
I was on holiday the last couple of weeks.
Is there still something you would want me to take a look at?
09-25-2013 06:30 AM
Hi Thierry C,
Well I finished this thread since 1st of all it was going totally off-topic (not that I cared but still...), 2nd I started a re-design of my program to make use of a HAL and GOOP.
For the problem I have now I started a new thread that can be found here: http://forums.ni.com/t5/LabVIEW/best-design-pattern-to-convert-a-static-flat-VI-to-a/m-p/2556629
So altough the state machine/queued message handler/model view controller are options in the thread I'm hoping that there is a better solution for my challenge.
Thanks,
Tim