示例#1
0
        public int FindAnalogChansOfType(MccDaq.MccBoard DaqBoard,
            int AnalogType, out int Resolution, out MccDaq.Range DefaultRange,
            out int DefaultChan, out MccDaq.TriggerType DefaultTrig)
        {
            int ChansFound, IOType;
            MccDaq.ErrorInfo ULStat;
            bool CheckPretrig, CheckATrig = false;
            MccDaq.Range TestRange;
            bool RangeFound;

            // check supported features by trial
            // and error with error handling disabled
            ULStat = MccDaq.MccService.ErrHandling
                (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            TestBoard = DaqBoard;
            ATrigRes = 0;
            DefaultChan = 0;
            DefaultTrig = TriggerType.TrigPosEdge;
            DefaultRange = Range.NotUsed;
            Resolution = 0;
            IOType = (AnalogType & 3);
            switch (IOType)
            {
                case ANALOGINPUT:
                    // Get the number of A/D channels
                    ULStat = DaqBoard.BoardConfig.GetNumAdChans(out ChansFound);
                    if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                    {
                        clsErrorDefs.DisplayError(ULStat);
                        return ChansFound;
                    }
                    if (ChansFound > 0)
                    {
                        // Get the resolution of A/D
                        ULStat = DaqBoard.BoardConfig.GetAdResolution(out ADRes);
                        if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                            Resolution = ADRes;
                        // check ranges for a valid default
                        RangeFound = TestInputRanges(out TestRange);
                        if (RangeFound) DefaultRange = TestRange;
                    }
                    break;
                default:
                    // Get the number of D/A channels
                    ULStat = DaqBoard.BoardConfig.GetNumDaChans(out ChansFound);
                    if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                    {
                        clsErrorDefs.DisplayError(ULStat);
                        return ChansFound;
                    }
                    if (ChansFound > 0)
                    {
                        ULStat = TestBoard.GetConfig(2, 0, 292, out DARes);
                        Resolution = DARes;
                        RangeFound = TestOutputRanges(out TestRange);
                        if (RangeFound) DefaultRange = TestRange;
                    }
                    break;
            }

            CheckATrig = ((AnalogType & ATRIGIN) == ATRIGIN);
            if ((ChansFound > 0) & CheckATrig)
            {
                ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigAbove, 0, 0);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                    GetTrigResolution();
                }
                else
                    ChansFound = 0;
            }

            CheckPretrig = ((AnalogType & PRETRIGIN) == PRETRIGIN);
            if ((ChansFound > 0) & CheckPretrig)
            {
                // if DaqSetTrigger supported, trigger type is analog
                ULStat = DaqBoard.DaqSetTrigger(MccDaq.TriggerSource.TrigImmediate,
                    MccDaq.TriggerSensitivity.AboveLevel, 0, MccDaq.ChannelType.Analog,
                    DefaultRange, 0.0F, 0.1F, MccDaq.TriggerEvent.Start);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                else
                {
                    ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigPosEdge, 0, 0);
                    if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                        DefaultTrig = MccDaq.TriggerType.TrigPosEdge;
                    else
                        ChansFound = 0;
                }
            }
            ULStat = MccDaq.MccService.ErrHandling
                (clsErrorDefs.ReportError, clsErrorDefs.HandleError);
            return ChansFound;
        }
示例#2
0
文件: Analog.cs 项目: minosniu/nersa
        private void GetTrigResolution()
        {
            int BoardID, TrigSource;

            MccDaq.ErrorInfo ULStat;

            ULStat = TestBoard.GetConfig(2, 0, 209, out TrigSource);
            ULStat = TestBoard.BoardConfig.GetBoardType(out BoardID);

            switch (BoardID)
            {
            case 95:
            case 96:
            case 97:
            case 98:
            case 102:
            case 165:
            case 166:
            case 167:
            case 168:
            case 177:
            case 178:
            case 179:
            case 180:
            case 203:
            case 204:
            case 205:
            case 213:
            case 214:
            case 215:
            case 216:
            case 217:
            {
                //PCI-DAS6030, 6031, 6032, 6033, 6052
                //USB-1602HS, 1602HS-2AO, 1604HS, 1604HS-2AO
                //PCI-2511, 2513, 2515, 2517, USB-2523, 2527, 2533, 2537
                //USB-1616HS, 1616HS-2, 1616HS-4, 1616HS-BNC
                ATrigRes   = 12;
                ATrigRange = 20;
                if (TrigSource > 0)
                {
                    ATrigRange = -1;
                }
            }
            break;

            case 101:
            case 103:
            case 104:
            {
                //PCI-DAS6040, 6070, 6071
                ATrigRes   = 8;
                ATrigRange = 20;
                if (TrigSource > 0)
                {
                    ATrigRange = -1;
                }
            }
            break;

            default:
            {
                ATrigRes   = 0;
                ATrigRange = -1;
            }
            break;
            }
        }
示例#3
0
文件: Analog.cs 项目: minosniu/nersa
        public int FindAnalogChansOfType(MccDaq.MccBoard DaqBoard,
                                         int AnalogType, out int Resolution, out MccDaq.Range DefaultRange,
                                         out int DefaultChan, out MccDaq.TriggerType DefaultTrig)
        {
            int ChansFound, IOType;

            MccDaq.ErrorInfo ULStat;
            bool             CheckPretrig, CheckATrig = false;

            MccDaq.Range TestRange;
            bool         RangeFound;

            // check supported features by trial
            // and error with error handling disabled
            ULStat = MccDaq.MccService.ErrHandling
                         (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            TestBoard    = DaqBoard;
            ATrigRes     = 0;
            DefaultChan  = 0;
            DefaultTrig  = TriggerType.TrigPosEdge;
            DefaultRange = Range.NotUsed;
            Resolution   = 0;
            IOType       = (AnalogType & 3);
            switch (IOType)
            {
            case ANALOGINPUT:
                // Get the number of A/D channels
                ULStat = DaqBoard.BoardConfig.GetNumAdChans(out ChansFound);
                if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                {
                    clsErrorDefs.DisplayError(ULStat);
                    return(ChansFound);
                }
                if (ChansFound > 0)
                {
                    // Get the resolution of A/D
                    ULStat = DaqBoard.BoardConfig.GetAdResolution(out ADRes);
                    if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        Resolution = ADRes;
                    }
                    // check ranges for a valid default
                    RangeFound = TestInputRanges(out TestRange);
                    if (RangeFound)
                    {
                        DefaultRange = TestRange;
                    }
                }
                break;

            default:
                // Get the number of D/A channels
                ULStat = DaqBoard.BoardConfig.GetNumDaChans(out ChansFound);
                if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                {
                    clsErrorDefs.DisplayError(ULStat);
                    return(ChansFound);
                }
                if (ChansFound > 0)
                {
                    ULStat     = TestBoard.GetConfig(2, 0, 292, out DARes);
                    Resolution = DARes;
                    RangeFound = TestOutputRanges(out TestRange);
                    if (RangeFound)
                    {
                        DefaultRange = TestRange;
                    }
                }
                break;
            }

            CheckATrig = ((AnalogType & ATRIGIN) == ATRIGIN);
            if ((ChansFound > 0) & CheckATrig)
            {
                ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigAbove, 0, 0);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                    GetTrigResolution();
                }
                else
                {
                    ChansFound = 0;
                }
            }

            CheckPretrig = ((AnalogType & PRETRIGIN) == PRETRIGIN);
            if ((ChansFound > 0) & CheckPretrig)
            {
                // if DaqSetTrigger supported, trigger type is analog
                ULStat = DaqBoard.DaqSetTrigger(MccDaq.TriggerSource.TrigImmediate,
                                                MccDaq.TriggerSensitivity.AboveLevel, 0, MccDaq.ChannelType.Analog,
                                                DefaultRange, 0.0F, 0.1F, MccDaq.TriggerEvent.Start);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                }
                else
                {
                    ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigPosEdge, 0, 0);
                    if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        DefaultTrig = MccDaq.TriggerType.TrigPosEdge;
                    }
                    else
                    {
                        ChansFound = 0;
                    }
                }
            }
            ULStat = MccDaq.MccService.ErrHandling
                         (clsErrorDefs.ReportError, clsErrorDefs.HandleError);
            return(ChansFound);
        }
示例#4
0
        public int FindPortsOfType(MccDaq.MccBoard DaqBoard, int PortType,
                                   out int ProgAbility, out MccDaq.DigitalPortType DefaultPort,
                                   out int DefaultNumBits, out int FirstBit)

        {
            int   ThisType, NumPorts, NumBits;
            int   DefaultDev, InMask, OutMask;
            int   PortsFound, curCount, curIndex;
            short status;
            bool  PortIsCompatible;
            bool  CheckBitProg = false;

            MccDaq.DigitalPortType CurPort;
            MccDaq.FunctionType    DFunction;
            MccDaq.ErrorInfo       ULStat;
            string ConnectionConflict;

            ULStat = MccDaq.MccService.ErrHandling
                         (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            ConnectionConflict = "This network device is in use by another process or user." +
                                 System.Environment.NewLine + System.Environment.NewLine +
                                 "Check for other users on the network and close any applications " +
                                 System.Environment.NewLine +
                                 "(such as Instacal) that may be accessing the network device.";

            DefaultPort    = (MccDaq.DigitalPortType)(-1);
            CurPort        = DefaultPort;
            PortsFound     = 0;
            FirstBit       = 0;
            ProgAbility    = -1;
            DefaultNumBits = 0;
            ULStat         = DaqBoard.BoardConfig.GetDiNumDevs(out NumPorts);
            if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
            {
                clsErrorDefs.DisplayError(ULStat);
                return(PortsFound);
            }

            if ((PortType == BITOUT) || (PortType == BITIN))
            {
                CheckBitProg = true;
            }
            if ((PortType == PORTOUTSCAN) || (PortType == PORTINSCAN))
            {
                if (NumPorts > 0)
                {
                    DFunction = MccDaq.FunctionType.DiFunction;
                    if (PortType == PORTOUTSCAN)
                    {
                        ULStat        = DaqBoard.GetConfig(2, 0, 378, out configVal);
                        DigTypeExists = false;
                        if (configVal == 0)
                        {
                            NumPorts = 0;
                        }
                        else
                        {
                            for (i = 0; i < configVal; i++)
                            {
                                ULStat = DaqBoard.GetConfig(2, i, 379, out TypeNum);
                                if (TypeNum == 1)
                                {
                                    DigTypeExists = true;
                                }
                                if (TypeNum == 2)
                                {
                                    DigTypeExists = true;
                                }
                                if (TypeNum == 16)
                                {
                                    DigTypeExists = true;
                                }
                            }
                            if (!DigTypeExists)
                            {
                                NumPorts = 0;
                            }
                        }
                        ULStat = DaqBoard.GetStatus(out status, out curCount, out curIndex, DFunction);
                        if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                        {
                            NumPorts = 0;
                        }
                    }
                }
                PortType = PortType & (PORTOUT | PORTIN);
            }

            for (int DioDev = 0; DioDev < NumPorts; ++DioDev)
            {
                ProgAbility = -1;
                ULStat      = DaqBoard.DioConfig.GetDInMask(DioDev, out InMask);
                ULStat      = DaqBoard.DioConfig.GetDOutMask(DioDev, out OutMask);
                if ((InMask & OutMask) > 0)
                {
                    ProgAbility = FIXEDPORT;
                }
                ULStat = DaqBoard.DioConfig.GetDevType(DioDev, out ThisType);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    CurPort = (DigitalPortType)Enum.Parse(typeof(DigitalPortType),
                                                          ThisType.ToString());
                }
                if ((DioDev == 0) && (CurPort == MccDaq.DigitalPortType.FirstPortCL))
                {
                    //a few devices (USB-SSR08 for example)
                    //start at FIRSTPORTCL and number the bits
                    //as if FIRSTPORTA and FIRSTPORTB exist for
                    //compatibiliry with older digital peripherals
                    FirstBit = 16;
                }

                //check if port is set for requested direction
                //or can be programmed for requested direction
                PortIsCompatible = false;
                switch (PortType)
                {
                case (PORTOUT):
                    if (OutMask > 0)
                    {
                        PortIsCompatible = true;
                    }
                    break;

                case (PORTIN):
                    if (InMask > 0)
                    {
                        PortIsCompatible = true;
                    }
                    break;

                default:
                    PortIsCompatible = false;
                    break;
                }
                PortType = (PortType & (PORTOUT | PORTIN));
                if (!PortIsCompatible)
                {
                    if (ProgAbility != FIXEDPORT)
                    {
                        MccDaq.DigitalPortDirection ConfigDirection;
                        ConfigDirection = DigitalPortDirection.DigitalOut;
                        if (PortType == PORTIN)
                        {
                            ConfigDirection = DigitalPortDirection.DigitalIn;
                        }
                        if ((CurPort == MccDaq.DigitalPortType.AuxPort) && CheckBitProg)
                        {
                            //if it's an AuxPort, check bit programmability
                            ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                         FirstBit, ConfigDirection);
                            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                            {
                                //return port to input mode
                                ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                             FirstBit, DigitalPortDirection.DigitalIn);
                                ProgAbility = PROGBIT;
                            }
                            else
                            {
                                if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) ||
                                    (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse))
                                {
                                    System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use");
                                    break;
                                }
                            }
                        }
                        if (ProgAbility == -1)
                        {
                            //check port programmability
                            ULStat = DaqBoard.DConfigPort(CurPort, ConfigDirection);
                            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                            {
                                //return port to input mode
                                ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                             FirstBit, DigitalPortDirection.DigitalIn);
                                ProgAbility = PROGPORT;
                            }
                            else
                            {
                                if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) ||
                                    (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse))
                                {
                                    System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use");
                                    break;
                                }
                            }
                        }
                    }
                    PortIsCompatible = !(ProgAbility == -1);
                }

                if (PortIsCompatible)
                {
                    PortsFound = PortsFound + 1;
                }
                int BitVals, BitWeight;
                int TotalVal, CurBit;
                if (DefaultPort == (MccDaq.DigitalPortType)(-1))
                {
                    ULStat = DaqBoard.DioConfig.GetNumBits(DioDev, out NumBits);
                    if (ProgAbility == FIXEDPORT)
                    {
                        //could have different number of input and output bits
                        CurBit   = 0;
                        TotalVal = 0;
                        BitVals  = OutMask;
                        if (PortType == PORTIN)
                        {
                            BitVals = InMask;
                        }
                        do
                        {
                            BitWeight = (int)Math.Pow(2, CurBit);
                            TotalVal  = BitWeight + TotalVal;
                            CurBit    = CurBit + 1;
                        } while (TotalVal < BitVals);
                        NumBits = CurBit;
                    }
                    DefaultNumBits = NumBits;
                    DefaultDev     = DioDev;
                    DefaultPort    = CurPort;
                }
                if (ProgAbility == PROGBIT)
                {
                    break;
                }
            }
            ULStat = MccDaq.MccService.ErrHandling
                         (clsErrorDefs.ReportError, clsErrorDefs.HandleError);
            return(PortsFound);
        }