how can i set properties to serial port from a combobox?
HI!
I made a code for a windows application to communicate via serial port. I want to set the parameters manually by using some combo boxes in my windows form that contain the possible values of baud rate, parity bit etc. I made a bit of a code that gives me in a text box the names of the com ports available and i can select them but i need to set serial port parameters tha开发者_StackOverflow社区t i set in the combo boxes by pressing a button. Can anyone help me?
Thanks!
Do you need to change the serial port parameters before or after you created your serial port object?
I have a project that interacts with an Arduino using the USB interface. Here is my code to create a SerialPort:
string comPort = cboComPorts.SelectedItem.ToString();
SerialPort sp = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
As you can see the comPort is selected from a dropdown. When my program starts up, it lists all the available COM ports in that dropdown. Then, as you can see, I use it as a first parameter when creating my SerialPort object. Then it takes an int for the baud rate and a couple of other parameters. If you want to be able to enter these on a form and use them to instantiate the SerialPort it's not a huge deal you just have to write out some code to capture the information you need just like I have done with the first parameter here.
If you provide some of the code that you already so we can see what you're trying to do exactly, we might be able to give you a better answer.
精彩评论