private void bCreateSP_Click(object sender, EventArgs e) { if (!serialPort.IsOpen) { serialPort.PortName = cbPort.Text; serialPort.BaudRate = Convert.ToInt32(cbBaudRate.Text); serialPort.NewLine = "\r"; serialPort.Open(); //Serialport öffnen lbRecievedDelegate = new InvokeLB(InvokeLBRecieved); serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); //DataRecieved Event abonnieren this.bCreateSP.Text = "Close"; this.lbl_connected.Text = "Connected"; this.progressBarConnected.Value = 100; groupBoxSimulation.Show(); goto ende_create; } if (serialPort.IsOpen) { GotoClose = true; serialPort.Close(); serialPort.Dispose(); this.lbl_connected.Text = "Closed"; this.bCreateSP.Text = "Open"; this.progressBarConnected.Value = 0; groupBoxSimulation.Hide(); } ende_create: cbPort.Show(); }
private void bCreateSP_Click(object sender, EventArgs e) { if (!serialPort.IsOpen) { serialPort.PortName = cbPort.Text; serialPort.BaudRate = Convert.ToInt32(cbBaudRate.Text); serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), cbParity.Text); serialPort.DataBits = Convert.ToInt16(cbDataBits.Text); serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cbStopbits.Text); serialPort.Handshake = (Handshake)Enum.Parse(typeof(Handshake), cbHandshake.Text); serialPort.RtsEnable = Boolean.Parse(cbRtsEnable.Text); serialPort.DtrEnable = Boolean.Parse(cbDtrEnable.Text); serialPort.NewLine = "\r"; serialPort.Open(); //Serialport öffnen lbRecievedDelegate = new InvokeLB(InvokeLBRecieved); serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); //DataRecieved Event abonnieren SetButtonsState(true); this.bCreateSP.Text = "Close"; this.lable_connected.Text = "Connected"; this.progressBarConnected.Value = 100; //this.progressBarConnected. goto ende_create; } if (serialPort.IsOpen) { GotoClose = true; serialPort.Close(); serialPort.Dispose(); this.lable_connected.Text = "Closed"; this.bCreateSP.Text = "Open"; this.progressBarConnected.Value = 0; SetButtonsState(false); } ende_create: cbPort.Show(); }