Chinaunix首页 | 论坛 | 博客
  • 博客访问: 316826
  • 博文数量: 90
  • 博客积分: 4010
  • 博客等级: 上校
  • 技术积分: 694
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-22 10:51
文章分类

全部博文(90)

文章存档

2011年(3)

2010年(35)

2009年(52)

我的朋友

分类: 嵌入式

2010-12-21 15:44:11

DM9000冷启动,不需要重新编译内核,以下C#程序在WINCE6.0系统下运行:
 
        const Byte IO_CTL_DM9000_RESET = 0x14;
        private const int IOCTL_NDIS_REBIND_ADAPTER = 1507374;
        private const int IOCTL_NDIS_GET_ADAPTER_NAMES = 1507386;
        private const string EtherCardFileName = "NDS0:";
        private const int FILE_ATTRIBUTE_NORMAL = 0x80;
        private static string EtherCardName = "DM9CE1\0";
 
        [DllImport("Coredll.dll", EntryPoint = "CreateFile")]
        private static extern int CreateFile(
                string lpFileName,
                int dwDesiredAccess,
                int dwShareMode,
                int lpSecurityAttributes,
                int dwCreationDisposition,
                int dwFlagsAndAttributes,
                int hTemplateFile
            );
        [DllImport("Coredll.dll", EntryPoint = "DeviceIoControl")]
        private static extern int DeviceIoControl(
                int hDevice,
                int dwIoControlCode,
                string lpInBuffer,
                int nInBufferSize,
                string lpOutBuffer,
                int nOutBufferSize,
                int lpBytesReturned,
                int lpOverlapped
            );
        [DllImport("Coredll.dll", EntryPoint = "CloseHandle")]
        private static extern int CloseHandle(int hObject);
       
        public static bool resetDM9000()
        {
            int hNdis = CreateFile(EtherCardFileName, 0, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,INVALID_HANDLE_VALUE);
            if (hNdis == INVALID_HANDLE_VALUE)
            {
                return false;
            }
            // Send the device command.
            if (DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, EtherCardName, EtherCardName.Length * 2 + 2, null, 0, 0, 0) == 0)
            {
                return false;
            }
            CloseHandle(hNdis);
            return true;
        }
 
阅读(884) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~