Exemplo n.º 1
0
        private void Connect(object sender, EventArgs e)
        {
            butConnect.Enabled = false;

            try
            {
                //Connect to Bus Pirate
                sp          = new SerialPort();
                sp.PortName = comboSerial.SelectedItem.ToString();
                bp          = new BusPirate(sp);
                bp.Open();
                i2c = new I2C(bp);
                i2c.EnterMode();
                Thread.Sleep(200);

                //Setup 48 GPIOS!
                GPIOSetup();

                //Setup MCP23017s
                PortExpanders[0] = new MCP23017((byte)Convert.ToInt32(comboU8Addr.SelectedItem));
                PortExpanders[1] = new MCP23017((byte)Convert.ToInt32(comboU9Addr.SelectedItem));
                PortExpanders[2] = new MCP23017((byte)Convert.ToInt32(comboU12Addr.SelectedItem));
                foreach (GPIO g in GPIOs)
                {
                    PortExpanders[(int)g.PortExpander].Pins[g.Pin] = g.ToMCP23017Pin();
                }
                for (int i = 0; i < 3; i++)
                {
                    PortExpanders[i].Setup(i2c);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Disconnect(sender, e);
                return;
            }

            Connected           = true;
            lblStatus.Text      = "CONNECTED";
            lblStatus.ForeColor = Color.Green;
        }
Exemplo n.º 2
0
        private void Connect(object sender, EventArgs e)
        {
            butConnect.Enabled = false;

            try
            {
                //Connect to Bus Pirate
                sp = new SerialPort();
                sp.PortName = comboSerial.SelectedItem.ToString();
                bp = new BusPirate(sp);
                bp.Open();
                i2c = new I2C(bp);
                i2c.EnterMode();
                Thread.Sleep(200);

                //Setup 48 GPIOS!
                GPIOSetup();

                //Setup MCP23017s
                PortExpanders[0] = new MCP23017((byte)Convert.ToInt32(comboU8Addr.SelectedItem));
                PortExpanders[1] = new MCP23017((byte)Convert.ToInt32(comboU9Addr.SelectedItem));
                PortExpanders[2] = new MCP23017((byte)Convert.ToInt32(comboU12Addr.SelectedItem));
                foreach (GPIO g in GPIOs)
                    PortExpanders[(int)g.PortExpander].Pins[g.Pin] = g.ToMCP23017Pin();
                for (int i = 0; i < 3; i++)
                    PortExpanders[i].Setup(i2c);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Disconnect(sender, e);
                return;
            }

            Connected = true;
            lblStatus.Text = "CONNECTED";
            lblStatus.ForeColor = Color.Green;
        }