请教版主及各位大虾----如何用CVI编程实现关断U盘
<P>是这样的,我想编程实现如下功能:</P><P>1、程序可以检测到U盘的插入。</P>
<P>2、可以将U盘关闭。(在WINDOWS状态栏上不会再出现U盘的符号)</P>
<P>我想,使用VISA应该可以实现,但是我整了很久都没有什么突破,现请教各位有这方面经验的大虾指点。</P> <P>唉!没人回贴.</P><P>看样子又要靠自己去摸索了!</P> 虽然我也不会,但好主意要鼓励 <P>兄弟我支持你</P><P>但我是真的不会哦</P><P>呵呵</P> 没有作过。我想应该去查查Windows下关于该设备的管理,然后用CVI通过SDK来解决。祝你成功! <P>历经艰辛万苦.今天终于搞定了.呵呵......</P> 还有点小问题就是,“Undefined symbol '_GUID_CLASS_USB_DEVICE' reference in TestUSB.c”这个错误还是存在,如果这个参数变为NULL,的话没有错误提示,但执行目的达不到,其他的几个错误只需要把setupapi.lib加到工程立即刻,但对于这个错误怎么解决啊?谢谢,盼复!!! 请版主上传程序,让俺们也学学 <P>int CVICALLBACK EnjoinUSB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
switch (event)
{
case EVENT_COMMIT:</P><P> //--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// 查询信息失败
printf("ERROR - SetupDiGetClassDevs()");
return 0;
}
//--------------------------------------------------------------------------</P><P> // 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname;
ULONG ulStatus;
ULONG ulProblemNumber;</P><P> cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr )
{
printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
}
else
{
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
if ((DN_DISABLEABLE & ulStatus ) != 0 )
printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
else
continue;
if ((DN_REMOVABLE & ulStatus ) != 0 )
printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
else
continue;
</P><P> len = MAX_PATH;
// pnpvietotype = PNP_VetoDevice;
cr = CM_Request_Device_Eject(
DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0
);
if ( CR_SUCCESS == cr )
{
printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
SetupDiDestroyDeviceInfoList(hDevInfo);
return 1;
}
else
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
}
</P><P> }
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 0;
}
//Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
break;
}
return 0;
}
</P> <P>增加以下宏定义语句.</P><P>#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE</P> <P>我增加了如下的定义(用guidgen.exe生成的):</P><P>// {9A8BED8C-2AC0-41d2-AFBB-A21ABE6CC6D3}
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,0x9a8bed8c, 0x2ac0, 0x41d2, 0xaf, 0xbb, 0xa2, 0x1a, 0xbe, 0x6c, 0xc6, 0xd3);</P><P>#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE</P><P>但还是提示</P><P>Undefined symbol '_GUID_DEVINTERFACE_USB_DEVICE' Referenced in "TestUsb.c"</P><P>是不是需要增加什么Lib文件啊?我已经增加了cfgmgr32.lib 和setupapi.lib.</P><P>谢谢!</P> 不好意思,已经解决了,不过还是谢谢!
页:
[1]