Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
 private void ComPortSelector_SelectedIndexChanged_1(object sender, EventArgs e)
 {
     textBox1.AppendText(ComPortSelector.GetItemText(ComPortSelector.SelectedItem) + " selected\n");
     OpenComPort(ComPortSelector.GetItemText(ComPortSelector.SelectedItem));
 }