Esempio n. 1
0
        public ListenerBoard(int boardNo)
        {
            BoardNo = boardNo;
            var fValue = new float[3];

            ushort wTotalBoard = 0;

            var result = UniDAQ.Ixud_DriverInit(ref wTotalBoard);

            if (result != 0)
            {
                throw new ApplicationException("Error initializing driver");
            }

            result = UniDAQ.Ixud_GetAIBuffer(0, 3, fValue);
            if (result != 0)
            {
                throw new ApplicationException("Buffer error");
            }

            result = UniDAQ.Ixud_StartAI(0, 0, UniDAQ.IXUD_BI_20V, 10, 3);   //10 Hz, 3 samples per call
            if (result != 0)
            {
                throw new ApplicationException("Error of data acquisition");
            }
        }
        /// <summary>
        /// I/O 제어 보드를 오픈한다.
        /// </summary>
        /// <returns></returns>
        public bool OpenIO()
        {
#if PROGRAM_RUNNING
            try
            {
                try
                {
                    //ushort wIrqNo;
                    //ushort wSubVendor;
                    //ushort wSubDevice;
                    //ushort wSubAux;
                    //ushort wSlotDevice;
                    //ushort WSoltBus;
                    //ushort Result;                    
                    //string s;
                    byte[] szModeName = new byte[20];


                    //Driver Initial
                    wInitialCode = UniDAQ.Ixud_DriverInit(ref wTotalBoard);
                    if (wInitialCode != UniDAQ.Ixud_NoErr)
                    {
                        MessageBox.Show("Driver Initial Error!!Error Code:" + wInitialCode.ToString());
                        return false;
                    }

                    P32C32.InTotalBoardCount = 0;
                    P32C32.OutTotalBoardCount = 0;
                    C64.OutTotalBoardCount = 0;
                    AD813.ADTotalBoardCount = 0;

                    for (ushort wBoardIndex = 0; wBoardIndex < wTotalBoard; wBoardIndex++)
                    {
                        //Get Card Information
                        wInitialCode = UniDAQ.Ixud_GetCardInfo(wBoardIndex, ref sDeviceInfo[wBoardIndex], ref sCardInfo[wBoardIndex], szModeName);

                        string chars = Encoding.Default.GetString(szModeName).Trim();

                        if (chars.Contains("PISO-P32C32") == true)
                        {
                            if (0 < sCardInfo[wBoardIndex].wDIPorts)
                            {
                                P32C32.In[P32C32.InTotalBoardCount] = wBoardIndex;
                                P32C32.InPort[P32C32.InTotalBoardCount] = sCardInfo[wBoardIndex].wDIPorts;
                                P32C32.InTotalBoardCount++;
                            }
                            if (0 < sCardInfo[wBoardIndex].wDOPorts)
                            {
                                P32C32.Out[P32C32.OutTotalBoardCount] = wBoardIndex;
                                P32C32.OutPort[P32C32.OutTotalBoardCount] = sCardInfo[wBoardIndex].wDOPorts;
                                P32C32.OutTotalBoardCount++;
                            }
                        }
                        else if (chars.Contains("PISO-C64") == true)
                        {
                            if (0 < sCardInfo[wBoardIndex].wDOPorts)
                            {
                                C64.Out[C64.OutTotalBoardCount] = wBoardIndex;
                                C64.OutPort[C64.OutTotalBoardCount] = sCardInfo[wBoardIndex].wDOPorts;
                                C64.OutTotalBoardCount++;
                            }
                        }
                        else if (chars.Contains("PISO-813") == true)
                        {
                            if (0 < sCardInfo[wBoardIndex].wAIChannels)
                            {
                                AD813.ADBoard[AD813.ADTotalBoardCount] = wBoardIndex;
                                AD813.ADPort[AD813.ADTotalBoardCount] = sCardInfo[wBoardIndex].wAIChannels;
                                AD813.ADTotalBoardCount++;
                            }
                        }
                    }
                    if (0 < P32C32.OutTotalBoardCount)
                    {
                        for (ushort i = 0; i < P32C32.OutTotalBoardCount; i++)
                        {
                            for (ushort j = 0; j < P32C32.OutPort[i]; j++) wInitialCode = UniDAQ.Ixud_SetDIOModes32(P32C32.Out[i], (uint)(1 << j));
                        }
                    }
                    if (0 < C64.OutTotalBoardCount)
                    {
                        for (ushort i = 0; i < C64.OutTotalBoardCount; i++)
                        {
                            for (ushort j = 0; j < C64.OutPort[i]; j++) wInitialCode = UniDAQ.Ixud_SetDIOModes32(C64.Out[i], (uint)(1 << j));
                        }
                    }
                    if (0 < AD813.ADTotalBoardCount)
                    {
                        ushort wRtn = UniDAQ.Ixud_ConfigAI(AD813.ADBoard[0], 2, 2048, (ushort)ADCardType.HIGH_FAST_JPX_10V_GAIN, 0);
                        if (0 < wRtn)
                        {
                            MessageBox.Show("AI Config Error!!Error Code:" + wRtn.ToString());
                            return false;
                        }

                    }
                    Open = true;
                    if (0 < P32C32.InTotalBoardCount)
                    {
                        for (int i = 0; i < P32C32.InTotalBoardCount; i++) IOInit(i);
                    }

                    if (0 < C64.OutTotalBoardCount)
                    {
                        for (int i = 0; i < C64.OutTotalBoardCount; i++) IOInitC64(i);
                    }
                }
                catch (Exception Msg)
                {
                    MessageBox.Show(Msg.Message + "\n" + Msg.StackTrace);
                }
            }
            finally
            {
            }
#endif
            return true;
        }