Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am making an attempt to design a Windows application in c# that communicates through a serial port. The project will have a connection select screen, a main form with a menu bar and multiple dialogs connected to each menu item. The flow of the application would look like this:

The connection select dialog will be shown on the MainForm_Load event and capture the serial port name.

When a menu items is selected, the associated command will be sent through the serial port and the dialog will show the response data.

I am having trouble with the basic c# concepts coming from c++.

How can I create just one serial class that can share data between all the dialogs?
How can I access the serial read response from my dialog and display that data in a text field or a more meaningful way?

When I draw this up, it appears simple, but I do not know how to access data from the serial port to display in each dialog.
Posted
Comments
[no name] 15-Aug-12 16:54pm    
I think that what you are groping for here (from your comments) is create a class to handle your serial communication and then create some delegate functions that your dialogs can subscribe to, to get information and notifications.
dsandru1 15-Aug-12 16:56pm    
Do you have more information on this I can look into? It sounds like what I am after.
[no name] 15-Aug-12 17:02pm    
Go through this http://www.codeproject.com/search.aspx?q=delegates&sbo=kw and start reading. Start simple and work your way up.
Kenneth Haugland 15-Aug-12 17:06pm    
Yes, that is precisely what I meant :) Thank you Wes. It seems to be an easier way of doing this without delagates though...

1 solution

 
Share this answer
 
v3
Comments
dsandru1 15-Aug-12 16:36pm    
I have read through this, but it doesn't help me with my application because it is for the console not a Windows Form. I am trying to create a class that the other Forms can access, and then pull data from that class to post on the calling Form.
Kenneth Haugland 15-Aug-12 16:42pm    
It dosent matter if its a consol or Windows application, the same code for the serial port should still work. You should perhaps choose a setting dialog as the startup window, and call the main form when the settings are ok.

What is the trouble in creating a serialport class anyway?
dsandru1 15-Aug-12 16:46pm    
I guess the trouble isn't creating the serial class, it is finding a way to access the data in the class through multiple forms. For instance in one dialog I might have serialPort.Send(0x10), but I would have had created a new instance of serialPort without the settings selected during start-up. Also when I go to retrive the data, it is always null. *In my dialog code* textbox1.Text = serialPort.message;
Kenneth Haugland 15-Aug-12 16:48pm    
Think you'll have to add handlers in the Serial class if thats going to work
dsandru1 15-Aug-12 16:50pm    
This is where I start getting confused. I am used to being able to pass pointers to objects around, but I don't know where to begin with handlers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900