General design question to do with OO programming and serial ports

8 vues (au cours des 30 derniers jours)
Simon
Simon le 10 Avr 2011
I have an object oriented design at the moment, and I need to integrate input data from a device on a com port.
Within my current design there's a Session class, and an object of this class is to read from the com port. The issue is that I need to have multiple Session objects reading from the same com port.
I've tried to do this by creating a ComPort class and then a single ComPort object that represents and connects to the port, and returns the data. This ComPort object is then passed to multiple Session objects.
However this doesn't work, with odd errors. I also ruled out creating multiple ComPort objects as I don't think Matlab allows you to open the same port twice.
Is there a better design strategy? Is it even possible for multiple Matlab objects of the same class to read simultaneously from the same com port?
Thanks for your help!
  1 commentaire
per isakson
per isakson le 19 Avr 2011
You need to be more specific.
Did you try to create **one** com_port_object with the function, serial, and pass that to your Session objects? BTW: what do you imply with the name "Session"?
- per

Connectez-vous pour commenter.

Réponses (1)

Chirag Gupta
Chirag Gupta le 19 Avr 2011
Hi Simon,
What is the exact error that you get when you pass the serial object around?
In reality, this is more of a design question in my opinion. I could suggest something like a Singleton pattern where you could have a separate class for your COM port. This class would be a singleton and the first caller to this class would instantiate the object and open the connection.
The remaining classes would just request the information from the same object.
Again, its a pattern that easy to hate and I would be interested in the errors you are getting when you pass the objects around.

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by