private void saveAndSendAck(object sender, EventArgs e)
        {
            byte[] instruction, sendAckNak, dataWithoutHeader_1, dataWithoutHeader_2, dataWithoutHeader_3;

            if (!UartCom.RxHandshake_16byte(InByte_16, out instruction))
            {
                UartCom.TxHandshake_16byte(out sendAckNak);
                sPort.Write(sendAckNak, 0, 7);
                return;
            }
            UartCom.DataHeader header = UartCom.classifyHeader_16byte(instruction, out dataWithoutHeader_1, out dataWithoutHeader_2, out dataWithoutHeader_3);
            Realtime = UartCom.uARTBytetoFloat(dataWithoutHeader_1); //realtime
            Measure  = UartCom.uARTBytetoFloat(dataWithoutHeader_2); //measure
            PWM      = UartCom.uARTBytetoFloat(dataWithoutHeader_3); //PWM

            UartCom.TxHandshake_16byte(out sendAckNak);
            sPort.Write(sendAckNak, 0, 7);

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

            if (cBoxLog.Checked == true)
            {
                logTable.Rows.Add(Realtime, Setpoint, Measure, PWM);
            }
        }
예제 #2
0
        private void saveAndSendAck(object sender, EventArgs e)
        {
            byte[] instruction, dataWithoutHeader_1, dataWithoutHeader_2, dataWithoutHeader_3;

            if (!UartCom.RxHandshake_16byte(InByte_16, out instruction))
            {
                return;
            }
            UartCom.DataHeader header = UartCom.classifyHeader_16byte(instruction, out dataWithoutHeader_1, out dataWithoutHeader_2, out dataWithoutHeader_3);
            float displayValue1       = UartCom.uARTBytetoFloat(dataWithoutHeader_1); //realtime
            float displayValue2       = UartCom.uARTBytetoFloat(dataWithoutHeader_2); //measure
            float displayValue3       = UartCom.uARTBytetoFloat(dataWithoutHeader_3); //PWM

            Realtime = displayValue1;
            Measure  = displayValue2;
            PWM      = displayValue3;

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

            if (cBoxLog.Checked == true)
            {
                logTable.Rows.Add(Setpoint, Measure);
            }
        }
        //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;
            }
        }
예제 #4
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);
            }
        }