General design question to do with OO programming and serial ports

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

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

댓글을 달려면 로그인하십시오.

답변 (1개)

Chirag Gupta
Chirag Gupta 2011년 4월 19일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

질문:

2011년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by