btnOpen.Enabled = false;
btnClose.Enabled = true;
try
{
serialPort1.PortName = cboPort.Text;
serialPort1.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
if (serialPort1.IsOpen)
{
str = serialPort1.ReadExisting();
int startIndex = str.IndexOf("[") + 1;
int endIndex = str.IndexOf("]");
string otvet = str.Substring(startIndex, endIndex - startIndex);
textBox1.Text = otvet;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}