• 串口驱动卸载/加载与 GSM 模块电源控制


    直接上代码:

     1 // 串口驱动卸载/加载 COM13  
     2 BOOL UnloadDeviceDriver(CString csDeviceName)  
     3 {  
     4   BOOL bRet = FALSE;  
     5   HANDLE hFind = INVALID_HANDLE_VALUE;  
     6   if(csDeviceName.IsEmpty())  
     7   {  
     8     return FALSE;  
     9   }  
    10   DevicedeviceType deviceType;  
    11   if(CString(csDeviceName.Right(1)) == _T(":"))  
    12   {  
    13     deviceType = DeviceSearchByLegacyName;  
    14   }  
    15   else  
    16   {  
    17     deviceType = DeviceSearchByDeviceName;  
    18   }  
    19   DEVMGR_DEVICE_INFORMATION devInfo = {0};  
    20   devInfo.dwSize = sizeof(devInfo);  
    21   hFind = FindFirstDevice(deviceType,(LPCVOID)csDeviceName.GetBuffer(),&devInfo);  
    22   if(hFind == INVALID_HANDLE_VALUE)  
    23   {  
    24     return FALSE;  
    25   }  
    26   bRet = DeactivateDevice(devInfo.hDevice);  
    27   FindClose(hFind);  
    28   return bRet;  
    29 }  
    30 BOOL LoadDeviceDriver(CString csDeviceName)  
    31 {  
    32   DWORD dwParam = 89;  
    33   // ActivateDeviceEx(L"\Drivers\BuiltIn\Serial3",NULL,0,&dwParam);  
    34    HANDLE hHd = ActivateDeviceEx(str.GetBuffer(),NULL,0,&dwParam);  
    35   if(NULL == hHd)  
    36   {  
    37     DWORD dwError = GetLastError();  
    38     printf("LoadDeviceDriver Error : %d",dwError);  
    39   }  
    40 }  
    41 // 电源控制  
    42 #define   VIDEOFUNDEVNAME   L"fun1:"   
    43 #define SOFTI2C_IOCTL_TESTPIN 20  
    44 #define GSM_POWER_CONTROL_BY_MCU  0  
    45 BOOL GSM_Power_On(void)  
    46 {  
    47   BOOL bRet;  
    48   BYTE ucPara[3];  
    49   HANDLE hFun1 = INVALID_HANDLE_VALUE;  
    50   ucPara[0] = 1;  
    51   ucPara[1] = 0;  
    52   ucPara[2] = 14;   
    53   hFun1 = CreateFile(VIDEOFUNDEVNAME, GENERIC_WRITE|GENERIC_READ, 0, NULL, 0, 0, NULL);  
    54   if(INVALID_HANDLE_VALUE == hFun1)  
    55   {  
    56     return FALSE;  
    57   }  
    58   bRet = DeviceIoControl(hFun1, SOFTI2C_IOCTL_TESTPIN, ucPara, 3, NULL, 0, NULL, NULL);   
    59   if(!bRet)  
    60   {  
    61     RETAILMSG(1,(L"[Power_On]Device IO control failed: %d
    ",GetLastError()));  
    62   }  
    63   CloseHandle(hFun1);  
    64   hFun1 = INVALID_HANDLE_VALUE;  
    65   RETAILMSG(1,(L"
     open Gprs Power 
    "));  
    66   return bRet;  
    67 }  
    68 BOOL GSM_Power_Off(void)  
    69 {  
    70   BOOL bRet;  
    71   BYTE ucPara[3];  
    72   HANDLE hFun1 = INVALID_HANDLE_VALUE;  
    73   ucPara[0] = 0;  
    74   ucPara[1] = 0;  
    75   ucPara[2] = 14;  
    76   hFun1 = CreateFile(VIDEOFUNDEVNAME, GENERIC_WRITE|GENERIC_READ, 0, NULL, 0, 0, NULL);  
    77   if(INVALID_HANDLE_VALUE == hFun1)  
    78   {  
    79     return FALSE;  
    80   }  
    81   bRet = DeviceIoControl(hFun1, SOFTI2C_IOCTL_TESTPIN, ucPara, 3, NULL, 0, NULL, NULL);   
    82   if(!bRet)  
    83   {  
    84     RETAILMSG(1,(L"[Power_Off]Device IO control failed: %d
    ",GetLastError()));  
    85   }  
    86   CloseHandle(hFun1);  
    87   hFun1 = INVALID_HANDLE_VALUE;  
    88   RETAILMSG(1,(L"
     close Gprs Power 
    "));  
    89   return bRet;  
    90 }  
  • 相关阅读:
    Raft协议备注
    领域建模笔记
    Spark编程模型
    Spark如何删除无效rdd checkpoint
    Parquet 列式存储格式
    SpringBoot中ConditionalOnClass注解的原理
    SpringBoot定制Sevlet容器原理
    分析JDK的动态代理原理
    简述SpringCloud底层原理
    简述SpringCloud框架
  • 原文地址:https://www.cnblogs.com/91program/p/5206038.html
Copyright © 2020-2023  润新知