LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serialize data coming in multiple messages from the serial port

Solved!
Go to solution

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?

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 11 of 21
(1,589 Views)

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 Smiley Happy.

 

Thanks at least for staying with me,

 

Tim

0 Kudos
Message 12 of 21
(1,582 Views)

Hello Tim,

 

Do you mean instances of classes (objects) instead of subclasses?

 

Is each card exactly the same (but only with different devices connected)?

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 13 of 21
(1,561 Views)

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

0 Kudos
Message 14 of 21
(1,544 Views)

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

 

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 15 of 21
(1,528 Views)

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:

  • Card class
    • Child: card type A
    • Child: card type B
    • ....
    • Child: card type ...
  • Device class
    • Child: device type A
    • Child: device type B
    • ...
    • Child: device type ...

(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:

  • set the power of a device
  • get the analog value the device is outputting
  • get the current the device is using
  • request the readout of diagnostic values of the connected devices
  • software version of the card

Examples of the device specific data (up to 4 devices are connected to a card)

  • the diagnostic values (per device type the interpretation is different but the request is the same)
  • Serial number (same format for all devices)
  • configuration (different per device)

Also: should I place the actual serial handling in the card class or in a pice of normal code

 

Hoping you can help,

 

Tim

0 Kudos
Message 16 of 21
(1,513 Views)

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.

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 17 of 21
(1,488 Views)

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

0 Kudos
Message 18 of 21
(1,458 Views)

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?

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 19 of 21
(1,439 Views)

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

0 Kudos
Message 20 of 21
(1,435 Views)