How User Defined Serial Port StopBits

My application reads custom settings from INI. Everything works, except that after the data from INI is displayed in all the text fields of the form, the sreialPort1 connection parameters will prevent me from using some of the variables.

For some, I just needed to convert to Int, so for example the following is just fine:

serialPort1.BaudRate = Convert.ToInt32(txtboxbaud.Text);

      

However, the following will not:

serialPort1.StopBits = Convert.ToInt32(txtboxstopbits.Text);

      

I get the error "An explicit conversion exists (are you missing the listing?)"

I'm not sure what I need to do to fix this.

+3


source to share


1 answer


The StopBits property is an enumeration, not an Int32. Have a look at https://msdn.microsoft.com/en-us/library/system.io.ports.stopbits(v=vs.110).aspx

You can store its values ​​as a string and use:



serialPort1.StopBits = (StopBits) Enum.Parse(typeof(StopBits), mystring);

      

+3


source







All Articles