Exemplo n.º 1
0
 private void btnI2cReset_Click(object sender, EventArgs e)
 {
     I2c.I2cReset();
     if (I2c.bRdBuffer[0] != 0)
     {
         I2c.GetStatus();
     }
     StatusResult();
 }
Exemplo n.º 2
0
        private void btnSetSpeed_Click(object sender, EventArgs e)
        {
            if (cbxI2cSpeed.Text == "100")
            {
                I2c.I2cSetSpeed((byte)'1');
            }
            else if (cbxI2cSpeed.Text == "400")
            {
                I2c.I2cSetSpeed((byte)'4');
            }
            else
            {
                I2c.bRdBuffer[0] = 0;
            }

            if (I2c.bRdBuffer[0] != 0)
            {
                I2c.GetStatus();
            }
            StatusResult();
        }
Exemplo n.º 3
0
        private void btnSetPullUpR_Click(object sender, EventArgs e)
        {
            if (cbxPullUpR.Text == "4.7")
            {
                I2c.I2cSetPullupR(0x24);
            }
            else if (cbxPullUpR.Text == "4.3")
            {
                I2c.I2cSetPullupR(0x12);
            }
            else if (cbxPullUpR.Text == "2.2")
            {
                I2c.I2cSetPullupR(0x09);
            }
            else if (cbxPullUpR.Text == "1.5")
            {
                I2c.I2cSetPullupR(0x1b);
            }
            else if (cbxPullUpR.Text == "1.1")
            {
                I2c.I2cSetPullupR(0x3f);
            }
            else if (cbxPullUpR.Text == "disabled")
            {
                I2c.I2cSetPullupR(0x00);
            }
            else
            {
                I2c.bRdBuffer[0] = 0;
            }

            if (I2c.bRdBuffer[0] != 0)
            {
                I2c.GetStatus();
            }
            StatusResult();
        }
Exemplo n.º 4
0
 private void btnGetStatus_Click(object sender, EventArgs e)
 {
     I2c.GetStatus();
     StatusResult();
 }
Exemplo n.º 5
0
        private void btnCommOpen_Click(object sender, EventArgs e)
        {
            if (btnCommOpen.Text == "Close")
            {
                ComPort.ComPortClose();
                btnGetStatus.Enabled  = false;
                btnI2cReset.Enabled   = false;
                btnSetPullUpR.Enabled = false;
                btnSetSpeed.Enabled   = false;
                btnI2cTx.Enabled      = false;

                tbxCommParam.Text  = "";
                tbxMstVoltage.Text = "";
                tbxSerialNmb.Text  = "";
                tbxSlvCurrent.Text = "";
                tbxMstTemp.Text    = "";
                cbxI2cSpeed.Text   = "";
                tbxSDALevel.Text   = "";
                tbxSCLLevel.Text   = "";
                cbxPullUpR.Text    = "";

                btnCommOpen.Text = "Open";
            }
            else
            {
                if (cbxCommPort.Text == "")
                {
                    PortNames();
                    return;
                }

                ComPort.ComPortOpen(cbxCommPort.Text);

                I2c.GetStatus();

                if (I2c.bRdBuffer[0] == 0)
                {
                    ComPort.ComPortClose();
                }
                else
                {
                    btnGetStatus.Enabled  = true;
                    btnI2cReset.Enabled   = true;
                    btnSetPullUpR.Enabled = true;
                    btnSetSpeed.Enabled   = true;
                    btnI2cTx.Enabled      = true;
                    btnI2cRx.Enabled      = true;

                    StatusResult();

                    tbxCommParam.Text  = "Baudrate = " + Convert.ToString(I2cDriverDef.BaudRate) + "    ";
                    tbxCommParam.Text += "Databits = " + Convert.ToString(I2cDriverDef.DataBits) + "    ";
                    tbxCommParam.Text += "Stopbits = " + Convert.ToString(I2cDriverDef.StopBits) + " ";
                    tbxCommParam.Text += "Parity = " + Convert.ToString(I2cDriverDef.Parity) + "    ";
                    tbxCommParam.Text += "Handshake = " + Convert.ToString(I2cDriverDef.Handshake) + "                               ";
                    tbxCommParam.Text += "Read Timeout = " + Convert.ToString(I2cDriverDef.ReadTimeOut) + "    ";
                    tbxCommParam.Text += "Write Timeout = " + Convert.ToString(I2cDriverDef.WriteTimeOut);
                }

                btnCommOpen.Text = "Close";
            }
        }