Esempio n. 1
0
        private void chkSetBit_CheckStateChanged(object eventSender, System.EventArgs eventArgs)
        {
            int BitNum = Array.IndexOf(chkSetBit, eventSender);

            MccDaq.DigitalLogicState BitValue = MccDaq.DigitalLogicState.Low;
            if (chkSetBit[BitNum].Checked)
            {
                BitValue = MccDaq.DigitalLogicState.High;
            }

            MccDaq.DigitalPortType PortType = PortNum;
            MccDaq.ErrorInfo       ULStat   = DaqBoard.DBitOut(PortType, BitNum, BitValue);
            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadBitNumber)
            {
                MessageBox.Show("Boards only supports bit numbers less than " + BitNum.ToString("0"), "Bit value too high", 0);
            }
        }
Esempio n. 2
0
        public frmDScan()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            lblDataRead = (new Label[] { _lblDataRead_0, _lblDataRead_1, _lblDataRead_2, _lblDataRead_3, _lblDataRead_4,
                                         _lblDataRead_5, _lblDataRead_6, _lblDataRead_7, _lblDataRead_8, _lblDataRead_9 });

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop

            MccDaq.ErrorInfo ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);


            // Create a new MccBoard object for Board 0
            DaqBoard = new MccDaq.MccBoard(0);

            // set aside memory to hold data
            MemHandle = MccDaq.MccService.WinBufAlloc(NumPoints);


            //  configure FirstPortA for digital input
            //   Parameters:
            //     PortNum    :the input port
            //     Direction  :sets the port for input or output
            PortNum = MccDaq.DigitalPortType.FirstPortA;
            ULStat  = DaqBoard.DConfigPort(PortNum, Direction);


            // configure FirstPortA & FirstPortB for digital input
            //   Parameters:
            //      PortNum    :the input port
            //      Direction  :sets the port for input or output
            PortNum = MccDaq.DigitalPortType.FirstPortB;
            ULStat  = DaqBoard.DConfigPort(PortNum, Direction);


            Force = 0;
        }
Esempio n. 3
0
        public frmDScan()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            lblDataRead = (new Label[]{_lblDataRead_0, _lblDataRead_1, _lblDataRead_2, _lblDataRead_3, _lblDataRead_4,
                                    _lblDataRead_5, _lblDataRead_6, _lblDataRead_7, _lblDataRead_8, _lblDataRead_9});

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop

            MccDaq.ErrorInfo ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);

            // Create a new MccBoard object for Board 0
            DaqBoard = new MccDaq.MccBoard(0);

            // set aside memory to hold data
            MemHandle = MccDaq.MccService.WinBufAlloc(NumPoints);

            //  configure FirstPortA for digital input
            //   Parameters:
            //     PortNum    :the input port
            //     Direction  :sets the port for input or output
            PortNum = MccDaq.DigitalPortType.FirstPortA;
            ULStat = DaqBoard.DConfigPort(PortNum, Direction);

            // configure FirstPortA & FirstPortB for digital input
            //   Parameters:
            //      PortNum    :the input port
            //      Direction  :sets the port for input or output
            PortNum = MccDaq.DigitalPortType.FirstPortB;
            ULStat = DaqBoard.DConfigPort(PortNum, Direction);

            Force = 0;
        }
Esempio n. 4
0
        const MccDaq.DigitalPortDirection Direction = MccDaq.DigitalPortDirection.DigitalOut;         //  program first digital port for output mode


        public frmSetBitOut()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            chkSetBit = (new CheckBox[] { _chkSetBit_0, _chkSetBit_1, _chkSetBit_2, _chkSetBit_3,
                                          _chkSetBit_4, _chkSetBit_5, _chkSetBit_6, _chkSetBit_7 });

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop

            MccDaq.ErrorInfo ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);



            // Create a new MccBoard object for Board 0
            DaqBoard = new MccDaq.MccBoard(0);


            //Get the first port on the device - some devices (such as the
            //USB-ERB08 and USB-SSR08) don't have FirstPortA, but do have
            //FirstPortCL.

            //Parameters:
            //      DevNum      : 0-based digital device index
            //      FirstPort   : return value for type of device

            int DevNum    = 0;
            int FirstPort = 0;

            ULStat = DaqBoard.DioConfig.GetDevType(0, out FirstPort);

            switch (FirstPort)
            {
            case (int)MccDaq.DigitalPortType.FirstPortA:
                FirstBit = 0;
                break;

            case (int)MccDaq.DigitalPortType.FirstPortB:
                FirstBit = 8;
                break;

            case (int)MccDaq.DigitalPortType.FirstPortCL:
                FirstBit = 16;
                break;

            case (int)MccDaq.DigitalPortType.FirstPortCH:
                FirstBit = 20;
                break;

            default:
                FirstBit = 0;
                break;
            }

            //  configure the first port for digital input
            //   Parameters:
            //     PortNum    :the input port
            //     Direction  :sets the port for input or output

            PortNum = (MccDaq.DigitalPortType)FirstPort;
            ULStat  = DaqBoard.DConfigPort(PortNum, Direction);

            // if the first port is FIRSTPORTCL, configure FIRSTPORTCH, too
            if (PortNum == MccDaq.DigitalPortType.FirstPortCL)
            {
                ULStat = DaqBoard.DConfigPort(PortNum + 1, Direction);
            }
        }
        private void frmStatusDisplay_Load(System.Object eventSender, System.EventArgs eventArgs)
        {
            int NumCntrs, NumPorts, CounterNum;
            int FirstBit;
            int ProgAbility = 0;
            int NumBits     = 0;

            MccDaq.DigitalPortType      PortNum = DigitalPortType.AuxPort;
            MccDaq.DigitalPortDirection Direction;
            MccDaq.ErrorInfo            ULStat;
            MccDaq.TriggerType          DefaultTrig;

            InitUL();

            NumCntrs = 0;
            NumPorts = 0;
            // determine the number of analog, digital, and counter channels and their capabilities
            int ChannelType = clsAnalogIO.ANALOGINPUT;

            NumAIChans = AIOProps.FindAnalogChansOfType(DaqBoard, ChannelType,
                                                        out ADResolution, out Range, out LowChan, out DefaultTrig);
            ChannelType = DigitalIO.clsDigitalIO.PORTIN;
            if (!clsErrorDefs.GeneralError)
            {
                NumPorts = DioProps.FindPortsOfType(DaqBoard, ChannelType, out ProgAbility,
                                                    out PortNum, out NumBits, out FirstBit);
            }
            ChannelType = clsCounters.CTRSCAN;
            if (!clsErrorDefs.GeneralError)
            {
                NumCntrs = CtrProps.FindCountersOfType(DaqBoard, ChannelType, out CounterNum);
            }

            if (NumCntrs == 0)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " has no counter devices.";
                cmdStartBgnd.Enabled = false;
            }
            else if (NumAIChans == 0)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " does not have analog input channels.";
                cmdStartBgnd.Enabled = false;
            }
            else if (NumPorts == 0)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " has no digital devices.";
                cmdStartBgnd.Enabled = false;
            }
            else
            {
                cmdStartBgnd.Enabled = true;
                ADData        = new ushort[NumElements];
                ChanArray     = new short[ChanCount];
                ChanTypeArray = new MccDaq.ChannelType[ChanCount];
                GainArray     = new MccDaq.Range[ChanCount];
                MemHandle     = MccDaq.MccService.WinBufAllocEx(NumElements);
                if (MemHandle == IntPtr.Zero)
                {
                    this.cmdStartBgnd.Enabled = false;
                    NumAIChans = 0;
                }
                //load the arrays with values
                ChanArray[0]     = 0;
                ChanTypeArray[0] = MccDaq.ChannelType.Analog;
                GainArray[0]     = Range;

                ChanArray[1]     = System.Convert.ToInt16(PortNum);
                ChanTypeArray[1] = MccDaq.ChannelType.Digital8;
                if (NumBits == 16)
                {
                    ChanTypeArray[1] = MccDaq.ChannelType.Digital16;
                }
                GainArray[1] = MccDaq.Range.NotUsed;

                ChanArray[2]     = 0;
                ChanTypeArray[2] = MccDaq.ChannelType.Ctr32Low;
                GainArray[2]     = MccDaq.Range.NotUsed;

                ChanArray[3]     = 0;
                ChanTypeArray[3] = MccDaq.ChannelType.Ctr32High;
                GainArray[3]     = MccDaq.Range.NotUsed;

                if (ProgAbility == -1)
                {
                    //configure programmable port for digital input
                    Direction = MccDaq.DigitalPortDirection.DigitalIn;
                    ULStat    = DaqBoard.DConfigPort(PortNum, Direction);
                }

                ULStat = DaqBoard.CConfigScan(0, MccDaq.CounterMode.Bit16,
                                              MccDaq.CounterDebounceTime.DebounceNone,
                                              MccDaq.CounterDebounceMode.TriggerAfterStable,
                                              MccDaq.CounterEdgeDetection.FallingEdge,
                                              MccDaq.CounterTickSize.Tick20833pt3ns, 0);
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " collecting analog, digital, and counter data " +
                                      " using DaqInScan with Range set to " + Range.ToString() + ".";
            }
        }
Esempio n. 6
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)
                    {
                        DFunction = MccDaq.FunctionType.DoFunction;
                    }
                    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);
        }
Esempio n. 7
0
        public frmSetBitOut()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            chkSetBit = (new CheckBox[]{_chkSetBit_0, _chkSetBit_1, _chkSetBit_2, _chkSetBit_3,
                                        _chkSetBit_4, _chkSetBit_5, _chkSetBit_6, _chkSetBit_7});

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop

            MccDaq.ErrorInfo ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);

            // Create a new MccBoard object for Board 0
            DaqBoard = new MccDaq.MccBoard(0);

              //Get the first port on the device - some devices (such as the
              //USB-ERB08 and USB-SSR08) don't have FirstPortA, but do have
              //FirstPortCL.

              //Parameters:
              //      DevNum      : 0-based digital device index
              //      FirstPort   : return value for type of device

              int DevNum = 0;
              int FirstPort = 0;
              ULStat = DaqBoard.DioConfig.GetDevType(0, out FirstPort);

              switch(FirstPort)
              {
            case (int) MccDaq.DigitalPortType.FirstPortA:
              FirstBit = 0;
              break;

            case (int) MccDaq.DigitalPortType.FirstPortB:
              FirstBit = 8;
              break;

            case (int) MccDaq.DigitalPortType.FirstPortCL:
              FirstBit = 16;
              break;

            case (int) MccDaq.DigitalPortType.FirstPortCH:
              FirstBit = 20;
              break;

            default:
              FirstBit = 0;
              break;
              }

              //  configure the first port for digital input
              //   Parameters:
              //     PortNum    :the input port
              //     Direction  :sets the port for input or output

              PortNum = (MccDaq.DigitalPortType) FirstPort;
              ULStat = DaqBoard.DConfigPort(PortNum, Direction);

              // if the first port is FIRSTPORTCL, configure FIRSTPORTCH, too
              if(PortNum == MccDaq.DigitalPortType.FirstPortCL)
            ULStat = DaqBoard.DConfigPort(PortNum + 1, Direction);
        }