The main form of my program has a button that opens a second form called PortOpener. PortOpener is setup to open serial, GPIB, ethernet, and USB ports to talk to external equipment. You select all the data required to open the port in the PortOpener and click the open port button. This passed all the port information to a new form called serialWindow and then serialWindow opens the port.
Here is where the serialWindow is created and how it passes the data to the new form.
private void OpenPortButton_Click(object sender, EventArgs e)
{
SerialWindow _serialWindow = new SerialWindow();
_serialWindow.Show();
_serialWindow.OpenCom(cboPort.SelectedItem.ToString(), cboParity.SelectedItem.ToString(), cboStop.SelectedItem.ToString(), cboData.SelectedItem.ToString(), cboBaud.SelectedItem.ToString(), NamePortTextBox.Text);
}
Here is the new serialWindow connecting to the port.
public void OpenCom(string port, string parity, string stop, string data, string baud, string PortName)
{
comm.PortName = port;
comm.Parity = parity;
comm.StopBits = stop;
comm.DataBits = data;
comm.BaudRate = baud;
comm.DisplayWindow = rxRichTextBox;
comm.OpenPort();
}
The port opens and I am able to transmit and receive data over the port. I can open multiple instances of the form by selecting different COM ports. I am trying to make it so the mainForm can pass data to the serialWindow to be transmitted.
I know how to pass data from the serialWindow to the mainForm using this method.
How to access a form control for another form?
I am unsure how to differentiate between the different instances of serialWindows. If the mainForm wants to transmit data over COM 3 and 6 COM ports are opened, how would you address each one? Should I try to send it to all of them and then have the serialWindows check if its opened COM port matches the one I want to transmit on?
Thanks for the help