private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (!MySerial.IsOpen)
            {
                try
                {
                    MySerial.PortName      = Convert.ToString(comboPorts.Text);
                    MySerial.BaudRate      = Convert.ToInt32(comboBaud.Text);
                    MySerial.DataBits      = Convert.ToInt16(comboBits.Text);
                    MySerial.Parity        = (Parity)Enum.Parse(typeof(Parity), comboParity.Text);
                    MySerial.StopBits      = (StopBits)Enum.Parse(typeof(StopBits), comboStopBit.Text);
                    MySerial.DataReceived += new SerialDataReceivedEventHandler(SerialPort_ReceivedEvent);
                    MySerial.Handshake     = (Handshake)Enum.Parse(typeof(Handshake), comboBoxHandShake.Text);
                    MySerial.Open();

                    buttonConnect.Text        = "Disconnect";
                    comboPorts.Enabled        = false;
                    comboBaud.Enabled         = false;
                    comboBits.Enabled         = false;
                    comboParity.Enabled       = false;
                    comboStopBit.Enabled      = false;
                    comboBoxHandShake.Enabled = false;

                    groupBoxIO.Enabled = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("Connection Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MySerial.Close();
                    buttonConnect.Text        = "Connect";
                    comboPorts.Enabled        = true;
                    comboBaud.Enabled         = true;
                    comboBits.Enabled         = true;
                    comboParity.Enabled       = true;
                    comboStopBit.Enabled      = true;
                    comboBoxHandShake.Enabled = true;

                    groupBoxIO.Enabled = false;
                }
            }
            else
            {
                MySerial.Close();
                buttonConnect.Text        = "Connect";
                comboPorts.Enabled        = true;
                comboBaud.Enabled         = true;
                comboBits.Enabled         = true;
                comboParity.Enabled       = true;
                comboStopBit.Enabled      = true;
                comboBoxHandShake.Enabled = true;

                groupBoxIO.Enabled = false;
            }
        }
Ejemplo n.º 2
0
    public static void Main()
    {
        MySerial sp = new MySerial(115200);

        sp.Open();
        JtagUartIfaceV1  iface = new JtagUartIfaceV1(sp, true);
        JtagDevicePoller jp    = new JtagDevicePoller(iface);

        Console.WriteLine("device number: {0}", jp.CountDevices(true));

        sp.Close();
    }
        private void buttonExit_Click(object sender, EventArgs e)
        {
            DialogResult result;

            result = MessageBox.Show("Are you sure you want to exit ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                if (MySerial.IsOpen)
                {
                    MySerial.Close();
                }

                try
                {
                    Environment.Exit(1);
                }
                catch (Exception)
                {
                }
            }
        }