コード例 #1
0
ファイル: Native.cs プロジェクト: ywscr/busdog
        public Native()
        {
            outBuffer = Marshal.AllocHGlobal((int)outBufferSize);
            inBuffer  = Marshal.AllocHGlobal((int)inBufferSize);

            devIO = new DeviceIOCTL(busdogPath, false);

            TraceBufferThread = new Thread(TraceBufRead);
        }
コード例 #2
0
ファイル: Native.cs プロジェクト: ADVALAIN596/busdog
        void TraceBufRead()
        {
            try
            {
                DeviceIOCTL devIO = new DeviceIOCTL(busdogPath, true);

                while (true)
                {
                    uint bytesReturned;
                    // send the get trace buffer command to the driver
                    bool result =
                     devIO.DeviceIoControl(
                         IOCTL_BUSDOG_GET_BUFFER,
                         IntPtr.Zero,
                         0,
                         outBuffer,
                         outBufferSize,
                         out bytesReturned);
                    if (!result)
                    {
                        int err = Marshal.GetLastWin32Error();
                        // check if the I/O request is pending
                        if (err == ERROR_IO_PENDING)
                        {
                            while (true)
                            {
                                // keep checking if the I/O request has been fufilled (abort after 500ms so our thread can be killed)
                                if (devIO.WaitForOverlappedIo(500, out bytesReturned))
                                {
                                    result = true;
                                    break;
                                }
                            }
                        }
                        else
                            System.Diagnostics.Debug.WriteLine(err);
                    }
                    if (result)
                    {
                        // we have a result so now we convert the buffer into a trace list and call the event
                        if (FilterTraceArrived != null)
                            FilterTraceArrived(
                                this,
                                new FilterTraceArrivedEventArgs(GetTraceList(outBuffer, outBufferSize, bytesReturned)));
                        // stall trace stream to allow main thread to have a turn now and then
                        Thread.Sleep(10);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                // We will cancel any pending IO on this thread before exiting
                devIO.CancelIo();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
コード例 #3
0
ファイル: Native.cs プロジェクト: ADVALAIN596/busdog
        public Native()
        {
            outBuffer = Marshal.AllocHGlobal((int)outBufferSize);
            inBuffer = Marshal.AllocHGlobal((int)inBufferSize);

            devIO = new DeviceIOCTL(busdogPath, false);

            TraceBufferThread = new Thread(TraceBufRead);
        }
コード例 #4
0
ファイル: Native.cs プロジェクト: ywscr/busdog
        void TraceBufRead()
        {
            try
            {
                DeviceIOCTL devIO = new DeviceIOCTL(busdogPath, true);

                while (true)
                {
                    uint bytesReturned;
                    // send the get trace buffer command to the driver
                    bool result =
                        devIO.DeviceIoControl(
                            IOCTL_BUSDOG_GET_BUFFER,
                            IntPtr.Zero,
                            0,
                            outBuffer,
                            outBufferSize,
                            out bytesReturned);
                    if (!result)
                    {
                        int err = Marshal.GetLastWin32Error();
                        // check if the I/O request is pending
                        if (err == ERROR_IO_PENDING)
                        {
                            while (true)
                            {
                                // keep checking if the I/O request has been fufilled (abort after 500ms so our thread can be killed)
                                if (devIO.WaitForOverlappedIo(500, out bytesReturned))
                                {
                                    result = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(err);
                        }
                    }
                    if (result)
                    {
                        // we have a result so now we convert the buffer into a trace list and call the event
                        if (FilterTraceArrived != null)
                        {
                            FilterTraceArrived(
                                this,
                                new FilterTraceArrivedEventArgs(GetTraceList(outBuffer, outBufferSize, bytesReturned)));
                        }
                        // stall trace stream to allow main thread to have a turn now and then
                        Thread.Sleep(10);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                // We will cancel any pending IO on this thread before exiting
                devIO.CancelIo();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }