コード例 #1
0
 private void tBoxK3_KeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         if (e.KeyCode == Keys.Enter)
         {
             byte[] setPointBuffer = UARTCom.headerEncapsulation(UARTCom.controlHeader.Parak3, tBoxK3.Text);
             sPort.Write(setPointBuffer, 0, 5);
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         //throw;
     }
 }
コード例 #2
0
 private void btnRequest_Click(object sender, EventArgs e)
 {
     try
     {
         //byte[] temp = new byte[1];
         //temp[0] = (byte)UARTCom.controlHeader.Stop;
         //sPort.Write(temp, 0, 1);
         byte[] setPointBuffer = UARTCom.headerEncapsulation(UARTCom.controlHeader.Request, "0");
         sPort.Write(setPointBuffer, 0, 5);
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         //throw;
     }
 }
コード例 #3
0
        /*Radio Button methods*/
        private void rBtnVP_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                clearGraph();
                if (rBtnVelocity.Checked)
                {
                    lbVelocity.Text = "Velocity";
                    tbCalib.Text    = "4.8";

                    GraphPane myPane = zGrphPlotData.GraphPane;
                    myPane.YAxis.Scale.Min = 0;                      //Tương tự cho trục y
                    myPane.YAxis.Scale.Max = 2500;
                    myPane.AxisChange();

                    //byte[] temp = new byte[1];
                    //temp[0] = (byte)UARTCom.controlHeader.Velocity;
                    //sPort.Write(temp, 0, 1);
                    byte[] setPointBuffer = UARTCom.headerEncapsulation(UARTCom.controlHeader.Velocity, "0");
                    sPort.Write(setPointBuffer, 0, 5);
                }
                else
                {
                    lbVelocity.Text = "Position";
                    tbCalib.Text    = "40";

                    GraphPane myPane = zGrphPlotData.GraphPane;
                    myPane.YAxis.Scale.Min = 0;                      //Tương tự cho trục y
                    myPane.YAxis.Scale.Max = 600;
                    myPane.AxisChange();

                    //byte[] temp = new byte[1];
                    //temp[0] = (byte)UARTCom.controlHeader.Position;
                    //sPort.Write(temp, 0, 1);
                    byte[] setPointBuffer = UARTCom.headerEncapsulation(UARTCom.controlHeader.Position, "0");
                    sPort.Write(setPointBuffer, 0, 5);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //throw;
            }
        }
コード例 #4
0
        private void btnMotorRun_Click(object sender, EventArgs e)
        {
            try
            {
                clearGraph();

                byte[] setPointBuffer = UARTCom.headerEncapsulation(UARTCom.controlHeader.Run, "0");
                sPort.Write(setPointBuffer, 0, 5);

                //btnMotorRun.Enabled = false;
                //btnMotorStop.Enabled = true;

                //gBoxWhatToMeasure.Enabled = false;
                //gBoxPID.Enabled = false;
                //tBoxSetPoint.Enabled = false;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //throw;
            }
        }
コード例 #5
0
        private void showAndSaveData(object sender, EventArgs e)
        {
            int[] dataWithoutHeader;
            UARTCom.dataHeader header = UARTCom.classifyData(inBuffer, out dataWithoutHeader);
            float displayValue        = UARTCom.uARTtoFloat(dataWithoutHeader);

            if (header != UARTCom.dataHeader.Message)
            {
                switch (header)
                {
                case UARTCom.dataHeader.Realtime:
                    realtime = displayValue;
                    break;

                case UARTCom.dataHeader.Setpoint:
                    setpoint = displayValue;
                    break;

                case UARTCom.dataHeader.Measure:
                    measure = displayValue;
                    break;

                default:
                    break;
                }

                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                tBoxTime.Text        = realtime.ToString();
                tBoxMeasure.Text     = measure.ToString();
            }
            else
            {
                tBoxDisplayGet.Text += dataWithoutHeader.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
            }

            realtime += 0.25;
        }
コード例 #6
0
        private void showAndSaveData(object sender, EventArgs e)
        {
            /*int[]*/ byte[] dataWithoutHeader;
            //UARTCom.dataHeader header = UARTCom.classifyData(inBuffer, out dataWithoutHeader);
            //float displayValue = UARTCom.uARTtoFloat(dataWithoutHeader);

            UARTCom.dataHeader header = UARTCom.classifyByte(inByte, out dataWithoutHeader);
            float displayValue        = UARTCom.uARTBytetoFloat(dataWithoutHeader);

            switch (header)
            {
            case UARTCom.dataHeader.Realtime:
                //realtimestep = displayValue;
                break;

            case UARTCom.dataHeader.Setpoint:
                setpoint             = displayValue;
                tBoxDisplayGet.Text += UARTCom.motorMessage[4];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Measure:
                measure   = displayValue;
                realtime += realtimestep;
                break;

            case UARTCom.dataHeader.Run:
                tBoxDisplayGet.Text += UARTCom.motorMessage[0];
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Stop:
                tBoxDisplayGet.Text += UARTCom.motorMessage[1];
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Velocity:
                tBoxDisplayGet.Text += UARTCom.motorMessage[2];
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Position:
                tBoxDisplayGet.Text += UARTCom.motorMessage[3];
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Kp:
                tBoxDisplayGet.Text += UARTCom.motorMessage[5];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Ki:
                tBoxDisplayGet.Text += UARTCom.motorMessage[6];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Kd:
                tBoxDisplayGet.Text += UARTCom.motorMessage[7];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Message:
                char transChar = (char)displayValue;
                tBoxDisplayGet.Text += Convert.ToString(transChar);
                break;

            case UARTCom.dataHeader.Floattype:
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Calib:
                tBoxDisplayGet.Text += UARTCom.motorMessage[8];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Parak0:
                tBoxDisplayGet.Text += UARTCom.motorMessage[9];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Parak1:
                tBoxDisplayGet.Text += UARTCom.motorMessage[10];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Parak2:
                tBoxDisplayGet.Text += UARTCom.motorMessage[11];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.Parak3:
                tBoxDisplayGet.Text += UARTCom.motorMessage[12];
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                break;

            case UARTCom.dataHeader.ParaThetaa1:
                Thetaa1 = displayValue;
                break;

            case UARTCom.dataHeader.ParaThetaa2:
                Thetaa2 = displayValue;
                break;

            case UARTCom.dataHeader.ParaThetab1:
                Thetab1 = displayValue;
                break;

            case UARTCom.dataHeader.ParaThetab2:
                Thetab2 = displayValue;
                break;

            case UARTCom.dataHeader.Null:
                sPort.ReadExisting();
                break;

            default:
                break;
            }

            textupdate--;
            if (textupdate == 0)
            {
                tBoxTime.Text        = realtime.ToString();
                tBoxMeasure.Text     = measure.ToString();
                tBoxDisplayGet.Text += displayValue.ToString();
                tBoxDisplayGet.Text += Environment.NewLine;
                textupdate           = 50;
            }

            if (status == graphStatus.GraphRun)
            {
                Draw();
            }


            if (cBoxLog.Checked == true)
            {
                logTable.Rows.Add(setpoint, measure);
            }
        }