private void SendCommand(char command) { char[] commandoutput = new char[3]; commandoutput[0] = '#'; commandoutput[1] = command; commandoutput[2] = '$'; String sendcommand = new String(commandoutput); if (ComPortSelector.SelectedIndex != -1 && ComPortSelector.SelectedIndex != 0) { logMessage(Color.Blue, new Font("Verdana", 8, FontStyle.Bold), sendcommand, textBox1, 'S'); try { serialPort1.Write((String)sendcommand); } catch (Exception exception) { OpenComPort(ComPortSelector.GetItemText(ComPortSelector.SelectedItem)); String S = ("Failed to send command:" + sendcommand + "\n"); logMessage(Color.Red, new Font("Verdana", 8, FontStyle.Bold), S, textBox1, 'S'); logMessage(Color.Red, new Font("Verdana", 8, FontStyle.Bold), S, richTextBox1, 'S'); S = (exception.Message + "\n\n" + exception.Data); logMessage(Color.Red, new Font("Verdana", 8, FontStyle.Bold), S, textBox1, 'W'); RefreshComPorts(); } } }
private void CheckComPorts() { int count = 0; //ComPortSelector. string[] ports = System.IO.Ports.SerialPort.GetPortNames(); foreach (String s in ports) { ComPortSelector.Items.Add(s); count++; } if (count == 0) { ComPortSelector.Items.Add("no port avaible"); logMessage(Color.Red, new Font("Verdana", 8, FontStyle.Bold), "NO AVAILABLE COMPORTS FOUND", textBox1, 'E'); } if (count > 5) { count = 5; } int size = 17 * (count + 1); ComPortSelector.SetBounds(511, 127, 111, size); }
private void ComPortSelector_SelectedIndexChanged_1(object sender, EventArgs e) { textBox1.AppendText(ComPortSelector.GetItemText(ComPortSelector.SelectedItem) + " selected\n"); OpenComPort(ComPortSelector.GetItemText(ComPortSelector.SelectedItem)); }