charlieb01
asked on
VB.NET SerialPort used for multiple forms
I have a program that needs to use a serial port in VB.NET 2013.
When the program starts I have a splash screen that loads and when the user clicks the "Proceed" button the splash screen is hidden (me.hide) and the user is presented with an "Options" form. The two options are "Run Test" and "System Check". Each of these launches a different form and both forms call the same module that communicate with hardware on the serial port.
In this module I need to refer to the serial port. What I need to know is, can I put the serial port (named "serialport1") on the splash screen and then in the module, when I need to call the serial port, simply say: frmSplash.serialport1 . . .
instead of putting separate serial ports on each form and then modifying the module to call a different serial port depending on which form is being used?
Thanks,
Charlie
When the program starts I have a splash screen that loads and when the user clicks the "Proceed" button the splash screen is hidden (me.hide) and the user is presented with an "Options" form. The two options are "Run Test" and "System Check". Each of these launches a different form and both forms call the same module that communicate with hardware on the serial port.
In this module I need to refer to the serial port. What I need to know is, can I put the serial port (named "serialport1") on the splash screen and then in the module, when I need to call the serial port, simply say: frmSplash.serialport1 . . .
instead of putting separate serial ports on each form and then modifying the module to call a different serial port depending on which form is being used?
Thanks,
Charlie
>>putting separate serial ports on each form
Are you talking about putting the serial port as a control onto the form (like you do for example a button) ?
Are you talking about putting the serial port as a control onto the form (like you do for example a button) ?
ASKER
Andy, Yes, I am talking about putting the serial port on the form. This is the way we always did it in VB6 days and the serial port is a windows form control.
Is there another way to do this?
Is there another way to do this?
>>can I put the serial port (named "serialport1") on the splash screen and then in the module, when I need to call the serial port, simply say: frmSplash.serialport1 . . .
Yes, that should work as you only hide the splash screen. I assume the frmSplash is a reference to the splash screen that is open and hidden.
Yes, that should work as you only hide the splash screen. I assume the frmSplash is a reference to the splash screen that is open and hidden.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just inject the serial port into your module. Thus each of your forms has a separate serial port, put the concrete used one is injected, e.g. by using the constructor, into your module.
The rest depends on your concrete code.