コード例 #1
0
        /// <summary>
        /// Метод изменения значения сигнала
        /// </summary>
        /// <param name="robot">экземпляр подключения к роботу</param>
        /// <param name="ioTypeConstant">константа типа сигнала</param>
        /// <param name="index">индекс сигнала, значение которое нужно изменить</param>
        /// <param name="value">новое значение сигнала</param>
        private async void SetSignalsIO(FRCRobot robot, FREIOTypeConstants ioTypeConstant, long index, bool value)
        {
            try
            {
                if (robot.IsConnected)
                {
                    switch (ioTypeConstant)
                    {
                    case FREIOTypeConstants.frDInType:
                    case FREIOTypeConstants.frDOutType:
                        FRCDigitalIOSignal dioSignal = (FRCDigitalIOSignal)((FRCDigitalIOType)robot.IOTypes[ioTypeConstant]).Signals[index];
                        dioSignal.Value = value;
                        dioSignal.Update();
                        break;

                    case FREIOTypeConstants.frUOPInType:
                    case FREIOTypeConstants.frUOPOutType:
                        FRCUOPIOSignal uop = (FRCUOPIOSignal)((FRCUOPIOType)robot.IOTypes[ioTypeConstant]).Signals[index];
                        uop.Value = value;
                        uop.Update();
                        break;

                    case FREIOTypeConstants.frSOPInType:
                    case FREIOTypeConstants.frSOPOutType:
                        FRCSOPIOSignal sop = (FRCSOPIOSignal)((FRCSOPIOType)robot.IOTypes[ioTypeConstant]).Signals[index];
                        sop.Value = value;
                        sop.Update();
                        break;

                    case FREIOTypeConstants.frFlagType:
                        FRCFlagSignal flagSignal = (FRCFlagSignal)((FRCFlagType)robot.IOTypes[ioTypeConstant]).Signals[index];
                        flagSignal.Value = value;
                        flagSignal.Update();
                        break;

                    case FREIOTypeConstants.frRDInType:
                    case FREIOTypeConstants.frRDOutType:
                        FRCRobotIOSignal rd = (FRCRobotIOSignal)((FRCRobotIOType)robot.IOTypes[ioTypeConstant]).Signals[index];
                        rd.Value = value;
                        rd.Update();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                Signals.Clear();
                await GetSignalsIO(robot, ioTypeConstant);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets the FRCIOSignal of FREIOTypeConstants at ioIndex.
        /// </summary>
        /// <param name="robot">FRCRobot object that is connected to the robot.</param>
        /// <param name="ioTypeConstant">The intended IO type constant from FREIOTypeConstants.</param>
        /// <param name="dioIndex">The index of the digital out signal to get.</param>
        /// <returns></returns>
        public void SetRobotIOSignal(FRCRobot robot, FREIOTypeConstants ioTypeConstant, long ioIndex, FRCIOSignal ioSignal)
        {
            try
            {
                if (robot.IsConnected)
                {
                    // Stacked case statements create the logical OR condition.
                    // http://stackoverflow.com/questions/848472/how-add-or-in-switch-statements
                    switch (ioTypeConstant)
                    {
                    case FREIOTypeConstants.frAInType:
                    case FREIOTypeConstants.frAOutType:
                        FRCAnalogIOSignal aioSignal = (FRCAnalogIOSignal)((FRCAnalogIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        aioSignal.Comment = ((FRCAnalogIOSignal)ioSignal).Comment;
                        aioSignal.Value   = ((FRCAnalogIOSignal)ioSignal).Value;
                        aioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frDInType:
                    case FREIOTypeConstants.frDOutType:
                        FRCDigitalIOSignal dioSignal = (FRCDigitalIOSignal)((FRCDigitalIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        dioSignal.Comment = ((FRCDigitalIOSignal)ioSignal).Comment;
                        dioSignal.Value   = ((FRCDigitalIOSignal)ioSignal).Value;
                        dioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frFlagType:
                        FRCFlagSignal fioSignal = (FRCFlagSignal)((FRCFlagType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        fioSignal.Comment = ((FRCFlagSignal)ioSignal).Comment;
                        fioSignal.Value   = ((FRCFlagSignal)ioSignal).Value;
                        fioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frGPInType:
                    case FREIOTypeConstants.frGPOutType:
                        FRCGroupIOSignal gioSignal = (FRCGroupIOSignal)((FRCGroupIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        gioSignal.Comment = ((FRCGroupIOSignal)ioSignal).Comment;
                        gioSignal.Value   = ((FRCGroupIOSignal)ioSignal).Value;
                        gioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frLAInType:
                    case FREIOTypeConstants.frLAOutType:
                        FRCLaserAnalogIOSignal laioSignal = (FRCLaserAnalogIOSignal)((FRCLaserAnalogIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        laioSignal.Comment = ((FRCLaserAnalogIOSignal)ioSignal).Comment;
                        laioSignal.Value   = ((FRCLaserAnalogIOSignal)ioSignal).Value;
                        laioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frLDInType:
                    case FREIOTypeConstants.frLDOutType:
                        FRCLaserDigitalIOSignal ldioSignal = (FRCLaserDigitalIOSignal)((FRCLaserDigitalIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        ldioSignal.Comment = ((FRCLaserDigitalIOSignal)ioSignal).Comment;
                        ldioSignal.Value   = ((FRCLaserDigitalIOSignal)ioSignal).Value;
                        ldioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frMarkerType:
                        FRCMarkerSignal mrkioSignal = (FRCMarkerSignal)((FRCMarkerType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        mrkioSignal.Comment = ((FRCMarkerSignal)ioSignal).Comment;
                        mrkioSignal.Value   = ((FRCMarkerSignal)ioSignal).Value;
                        mrkioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frMaxIOType:
                        // There is no FRCMaxIOType.
                        return;

                        break;

                    case FREIOTypeConstants.frPLCInType:
                    case FREIOTypeConstants.frPLCOutType:
                        FRCPLCIOSignal plcioSignal = (FRCPLCIOSignal)((FRCPLCIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        plcioSignal.Comment = ((FRCPLCIOSignal)ioSignal).Comment;
                        plcioSignal.Value   = ((FRCPLCIOSignal)ioSignal).Value;
                        plcioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frRDInType:
                    case FREIOTypeConstants.frRDOutType:
                        // There is no FRCRDIOType.
                        return;

                        break;

                    case FREIOTypeConstants.frSOPInType:
                    case FREIOTypeConstants.frSOPOutType:
                        FRCSOPIOSignal sopioSignal = (FRCSOPIOSignal)((FRCSOPIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        sopioSignal.Comment = ((FRCSOPIOSignal)ioSignal).Comment;
                        sopioSignal.Value   = ((FRCSOPIOSignal)ioSignal).Value;
                        sopioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frTPInType:
                    case FREIOTypeConstants.frTPOutType:
                        FRCTPIOSignal tpioSignal = (FRCTPIOSignal)((FRCTPIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        tpioSignal.Comment = ((FRCTPIOSignal)ioSignal).Comment;
                        tpioSignal.Value   = ((FRCTPIOSignal)ioSignal).Value;
                        tpioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frUOPInType:
                    case FREIOTypeConstants.frUOPOutType:
                        FRCUOPIOSignal uopioSignal = (FRCUOPIOSignal)((FRCUOPIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        uopioSignal.Comment = ((FRCUOPIOSignal)ioSignal).Comment;
                        uopioSignal.Value   = ((FRCUOPIOSignal)ioSignal).Value;

                        return;

                        break;

                    case FREIOTypeConstants.frWDInType:
                    case FREIOTypeConstants.frWDOutType:
                        FRCWeldDigitalIOSignal wdioSignal = (FRCWeldDigitalIOSignal)((FRCWeldDigitalIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        wdioSignal.Comment = ((FRCWeldDigitalIOSignal)ioSignal).Comment;
                        wdioSignal.Value   = ((FRCWeldDigitalIOSignal)ioSignal).Value;
                        wdioSignal.Update();
                        return;

                        break;

                    case FREIOTypeConstants.frWSTKInType:
                    case FREIOTypeConstants.frWSTKOutType:
                        FRCWeldStickIOSignal wsioSignal = (FRCWeldStickIOSignal)((FRCWeldStickIOType)robot.IOTypes[ioTypeConstant]).Signals[ioIndex];
                        wsioSignal.Comment = ((FRCWeldStickIOSignal)ioSignal).Comment;
                        wsioSignal.Value   = ((FRCWeldStickIOSignal)ioSignal).Value;
                        wsioSignal.Update();
                        return;

                        break;

                    default:
                        return;

                        break;
                    }
                }
                return;
            }
            catch (Exception e)
            {
                return;
            }
        }