//private void readBuffer(ref byte[] outBuffer)
        //{
        //    for (int ii = 0; ii <= 4; ii++)
        //    {
        //        outBuffer[ii] = Convert.ToByte(sPort.ReadByte());
        //    }
        //}

        private void saveData(object sender, EventArgs e)
        {
            byte[] instruction, dataWithoutHeader;

            if (!UartCom.RxHandshake(InByte, out instruction))
            {
                return;
            }
            UartCom.DataHeader header = UartCom.classifyHeader(instruction, 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;
                lbRun.Text           = "RUN";
                lbRun.ForeColor      = Color.Green;
                break;

            case UartCom.DataHeader.Stop:
                tBoxDisplayGet.Text += UartCom.motorMessage[1];
                tBoxDisplayGet.Text += Environment.NewLine;
                lbRun.Text           = "STOP";
                lbRun.ForeColor      = Color.Red;
                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.Data:
            //    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;

            default:
                break;
            }
        }
Example #2
0
        //private void readBuffer(ref byte[] outBuffer)
        //{
        //    for (int ii = 0; ii <= 4; ii++)
        //    {
        //        outBuffer[ii] = Convert.ToByte(sPort.ReadByte());
        //    }
        //}

        private void saveData(object sender, EventArgs e)
        {
            byte[] instruction, dataWithoutHeader;

            if (!UartCom.RxHandshake(InByte, out instruction))
            {
                return;
            }
            UartCom.DataHeader header = UartCom.classifyHeader(instruction, 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.Data:
                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;

            default:
                break;
            }

            if (status == GraphStatus.GraphRun)
            {
                graphUpdate();
            }

            if (cBoxLog.Checked == true)
            {
                logTable.Rows.Add(Setpoint, Measure);
            }
        }