Esempio n. 1
0
        /// <summary>
        /// 打开设备
        /// </summary>
        /// <returns></returns>
        public bool Open()
        {
            if (dev.hDev == IntPtr.Zero)
            {
                card.dwItems = 2;

                // BAR0
                card.Item0.item         = (uint)ITEM_TYPE.ITEM_IO;
                card.Item0.fNotSharable = 0;
                card.Item0.I.IO.dwAddr  = ioStart;
                card.Item0.I.IO.dwBytes = ioRange;
                card.Item0.I.IO.dwBar   = 0;

                // Int
                card.Item1.item              = (uint)ITEM_TYPE.ITEM_INTERRUPT;
                card.Item1.fNotSharable      = 0;
                card.Item1.I.Int.dwInterrupt = intNum;
                card.Item1.I.Int.dwOptions   = 0;

                ptrCard = Marshal.AllocHGlobal(Marshal.SizeOf(card));
                Marshal.StructureToPtr(card, ptrCard, false);


                uint status = wdc_lib_decl.WDC_IsaDeviceOpen(ref dev.hDev, ptrCard, IntPtr.Zero, IntPtr.Zero, null, IntPtr.Zero);


                if (status == (uint)WD_ERROR_CODES.WD_STATUS_SUCCESS)
                {
                    intHandler = new INT_HANDLER(ProcessInterrupt);

                    wdc_lib_decl.WDC_IntEnable((WDC_DEVICE)(dev), null, 0, 0, intHandler, IntPtr.Zero, false);
                    wdc_lib_decl.WDC_IntIsEnabled(dev.hDev);
                    //停止读写
                    sw.Start();

                    Thread threadRcv = new Thread(new ThreadStart(ProcRcv));
                    threadRcv.IsBackground = true;
                    threadRcv.Start();
                    return(true);
                }
                else
                {
                    dev.hDev = IntPtr.Zero;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 打开设备
        /// </summary>
        /// <returns></returns>
        public bool OpenDevice()
        {
            if (dev.hDev == IntPtr.Zero)
            {
                CANCard card = new CANCard();
                card.dwItems            = 2;
                card.Item1.item         = (uint)ITEM_TYPE.ITEM_BUS;
                card.Item1.item         = (uint)ITEM_TYPE.ITEM_IO;
                card.Item1.fNotSharable = 0;
                card.Item1.I.IO.dwAddr  = ioStart;
                card.Item1.I.IO.dwBytes = ioRange;
                card.Item1.I.IO.dwBar   = 0;


                //Int - Int: Interrupt Number a, Edge Triggered
                card.Item0.item              = (uint)ITEM_TYPE.ITEM_INTERRUPT;
                card.Item0.fNotSharable      = 0;
                card.Item0.I.Int.dwInterrupt = irqNum;
                card.Item0.I.Int.dwOptions   = 0;
                IntPtr ptrCard = Marshal.AllocHGlobal(Marshal.SizeOf(card));
                Marshal.StructureToPtr(card, ptrCard, true);



                uint status = wdc_lib_decl.WDC_IsaDeviceOpen(ref dev.hDev, ptrCard, IntPtr.Zero, IntPtr.Zero, null, IntPtr.Zero);


                if (status == (uint)WD_ERROR_CODES.WD_STATUS_SUCCESS)
                {
                    //bool state = wdc_lib_decl.WDC_IntIsEnabled(dev.hDev);

                    IRQCallback = new INT_HANDLER(ProcessIRQ);

                    wdc_lib_decl.WDC_IntEnable((WDC_DEVICE)(dev), null, 0, 0, IRQCallback, IntPtr.Zero, false);
                    wdc_lib_decl.WDC_IntIsEnabled(dev.hDev);
                    return(true);
                }
                else
                {
                    dev.hDev = IntPtr.Zero;
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 打开设备
        /// </summary>
        /// <returns></returns>
        public bool Open()
        {
            if (dev.hDev == IntPtr.Zero)
            {

                card.dwItems = 2;

                // BAR0 
                card.Item0.item = (uint)ITEM_TYPE.ITEM_IO;
                card.Item0.fNotSharable = 0;
                card.Item0.I.IO.dwAddr = ioStart;
                card.Item0.I.IO.dwBytes = ioRange;
                card.Item0.I.IO.dwBar = 0;

                // Int
                card.Item1.item = (uint)ITEM_TYPE.ITEM_INTERRUPT;
                card.Item1.fNotSharable = 0;
                card.Item1.I.Int.dwInterrupt = intNum;
                card.Item1.I.Int.dwOptions = 0;

                ptrCard = Marshal.AllocHGlobal(Marshal.SizeOf(card));
                Marshal.StructureToPtr(card, ptrCard, false);


                uint status = wdc_lib_decl.WDC_IsaDeviceOpen(ref dev.hDev, ptrCard, IntPtr.Zero, IntPtr.Zero, null, IntPtr.Zero);


                if (status == (uint)WD_ERROR_CODES.WD_STATUS_SUCCESS)
                {

                    intHandler = new INT_HANDLER(ProcessInterrupt);

                    wdc_lib_decl.WDC_IntEnable((WDC_DEVICE)(dev), null, 0, 0, intHandler, IntPtr.Zero, false);
                    wdc_lib_decl.WDC_IntIsEnabled(dev.hDev);
                    //停止读写
                    return true;
                }
                else
                {
                    dev.hDev = IntPtr.Zero;
                    return false;
                }

            }
            return true;
        }
Esempio n. 4
0
        public DWORD EnableInterrupts(USER_INTERRUPT_CALLBACK userIntCb, IntPtr pData)
        {
            DWORD dwStatus;

            WD_TRANSFER[] pIntTransCmds = null;
            DWORD         dwNumCmds;

            if (userIntCb == null)
            {
                Log.TraceLog("PCI_0228_Device.EnableInterrupts: "
                             + "user callback is invalid");
                return((DWORD)wdc_err.WD_INVALID_PARAMETER);
            }

            if (!IsItemExists(m_wdcDevice, (DWORD)item_types.ITEM_INTERRUPT))
            {
                Log.TraceLog("PCI_0228_Device.EnableInterrupts: "
                             + "Device doesn't have any interrupts");
                return((DWORD)wdc_err.WD_OPERATION_FAILED);
            }

            m_userIntHandler = userIntCb;

            m_intHandler = new INT_HANDLER(PCI_0228_IntHandler);
            if (m_intHandler == null)
            {
                Log.ErrLog("PCI_0228_Device.EnableInterrupts: interrupt handler is " +
                           "null (" + this.ToString(false) + ")");
                return((DWORD)wdc_err.WD_INVALID_PARAMETER);
            }

            if (wdc_lib_decl.WDC_IntIsEnabled(Handle))
            {
                Log.ErrLog("PCI_0228_Device.EnableInterrupts: "
                           + "interrupts are already enabled (" +
                           this.ToString(false) + ")");
                return((DWORD)wdc_err.WD_OPERATION_ALREADY_DONE);
            }

            dwStatus = CreateIntTransCmds(out pIntTransCmds, out dwNumCmds);
            if (dwStatus != (DWORD)wdc_err.WD_STATUS_SUCCESS)
            {
                return(dwStatus);
            }
            dwStatus = wdc_lib_decl.WDC_IntEnable(wdcDevice, pIntTransCmds,
                                                  dwNumCmds, 0, m_intHandler, pData, wdc_defs_macros.WDC_IS_KP(wdcDevice));

            if ((DWORD)wdc_err.WD_STATUS_SUCCESS != dwStatus)
            {
                Log.ErrLog("PCI_0228_Device.EnableInterrupts: Failed "
                           + "enabling interrupts. Error " + dwStatus.ToString("X") + ": "
                           + utils.Stat2Str(dwStatus) + "(" + this.ToString(false) + ")");
                m_intHandler = null;
                return(dwStatus);
            }

            /* TODO: You can add code here to write to the device in order
             *   to physically enable the hardware interrupts */

            Log.TraceLog("PCI_0228_Device: enabled interrupts (" + this.ToString(false) + ")");
            return(dwStatus);
        }