コード例 #1
0
        // Pulls data from the devices and places it in the table created earlier.
        public static void updateTable(DataGridView dataTable)
        {
            DataTable flippedStatusValues = new DataTable();
            string    period;

            //
            // PULLING DATA FROM MAESTRO
            //
            statusValues.Clear();
            if (NumOfConnectedMaestros > 0)
            {
                usc.getVariables(out maestroVars, out stack, out call_stack, out servos);
                errors = "";
                foreach (var error in Enum.GetValues(typeof(uscError)))
                {
                    if ((maestroVars.errors & (1 << (int)(uscError)error)) != 0)
                    {
                        errors += (error.ToString() + ", ");
                    }
                }
                //
                //
                // Need to add data information for other values, if needed
                //
                //
                statusValues.Rows.Add("Maestro", usc.getSerialNumber(), errors, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
            }
            // Case for when there are no connected Maestros
            else
            {
                statusValues.Rows.Add("Maestro", "No Maestros Found", "", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
            }

            //
            // PULLING DATA FROM JRK 1
            //
            if (Program.NumOfConnectedJrks > 0 && usc.servoCount > 0)
            {
                // Preparing Jrk data input
                jrkVars = Jrk1.getVariables();

                // Reading Jrk current
                // Easier to store in a variable before sending to the table.
                currentCalibrationForward = (Byte)Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD);
                currentCalibrationReverse = (Byte)Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE);
                current = currentToMilliamps(Jrk1, jrkVars.current, jrkVars.dutyCycle);

                // Reading Jrk errors
                // It's easier to store them all in one variable before sending to the table.
                errors = "";
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
                {
                    errors += "Awaiting command, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
                {
                    errors += "No power, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
                {
                    errors += "Motor driver error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
                {
                    errors += "Input invalid, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
                {
                    errors += "Input disconnect";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
                {
                    errors += "Feedback disconnect, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
                {
                    errors += "Max. current exceeded, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
                {
                    errors += "Serial signal error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
                {
                    errors += "Serial overrun, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
                {
                    errors += "Serial RX buffer full, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
                {
                    errors += "Serial CRC error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
                {
                    errors += "Serial protocol error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
                {
                    errors += "Serial timeout error, ";
                }

                period = servos[0].position * 0.25 + " microseconds";

                //Setting up the table with values
                statusValues.Rows.Add("Jrk", Jrk1.getSerialNumber(), errors, servos[0].position, period, jrkVars.target, jrkVars.scaledFeedback, jrkVars.feedback,
                                      jrkVars.errorSum, jrkVars.dutyCycleTarget, jrkVars.dutyCycle, servos[0].speed, servos[0].acceleration, current);
            }
            else
            {
                statusValues.Rows.Add("Jrk", "No Jrks Found");
            }

            //
            // PULLING DATA FROM JRK 2
            //
            if (Program.NumOfConnectedJrks > 1)
            {
                //Preparing Jrk data input
                jrkVars = Jrk2.getVariables();

                //Reading Jrk current
                // Easier to store in a variable before sending to the table.
                currentCalibrationForward = (Byte)Jrk2.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD);
                currentCalibrationReverse = (Byte)Jrk2.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE);
                current = currentToMilliamps(Jrk2, jrkVars.current, jrkVars.dutyCycle);

                //Reading Jrk errors
                // It's easier to store them all in one variable before sending to the table.
                errors = "";
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
                {
                    errors += "Awaiting command, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
                {
                    errors += "No power, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
                {
                    errors += "Motor driver error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
                {
                    errors += "Input invalid, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
                {
                    errors += "Input disconnect";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
                {
                    errors += "Feedback disconnect, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
                {
                    errors += "Max. current exceeded, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
                {
                    errors += "Serial signal error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
                {
                    errors += "Serial overrun, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
                {
                    errors += "Serial RX buffer full, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
                {
                    errors += "Serial CRC error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
                {
                    errors += "Serial protocol error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
                {
                    errors += "Serial timeout error, ";
                }

                period = servos[1].position * 0.25 + " microseconds";

                //Setting up the table with values
                statusValues.Rows.Add("Jrk", Jrk1.getSerialNumber(), errors, servos[1].position, period, jrkVars.target, jrkVars.scaledFeedback, jrkVars.feedback,
                                      jrkVars.errorSum, jrkVars.dutyCycleTarget, jrkVars.dutyCycle, servos[1].speed, servos[1].acceleration, current);
            }

            //Future extension to more devices

            /*
             * if (Program.NumOfConnectedJrks > 2)
             * {
             * }
             * if (Program.NumOfConnectedJrks > 3)
             * {
             * }
             */

            flippedStatusValues.Columns.Add("");
            string deviceTrack = "";

            for (int i = 0; i < statusValues.Rows.Count; i++)
            {
                deviceTrack = "Device " + i;
                flippedStatusValues.Columns.Add(deviceTrack);
            }

            for (int i = 0; i < statusValues.Columns.Count; i++)
            {
                DataRow newRow = flippedStatusValues.NewRow();

                newRow[0] = statusValues.Columns[i].Caption;
                for (int j = 0; j < statusValues.Rows.Count; j++)
                {
                    newRow[j + 1] = statusValues.Rows[j][i];
                }
                flippedStatusValues.Rows.Add(newRow);
            }

            // Configuring the table to show the data
            dataTable.DataSource = flippedStatusValues;
        }