//*********************************************************
// Labwindows/cvi8.5 自动识别串口号
// 注册表枚举某子项的所有键名及键值
// szlihongtao
// 2010-09-06
//*********************************************************
#include "windows.h"
#include <formatio.h>
#include <utility.h>
#include "winreg.h"
#include "toolbox.h"
#include <cvirte.h>
#include <userint.h>
#include "com_dect.h"
//*********************************************************
static int panelHandle;
unsigned int realstringsize;
unsigned int buffersize = 300;
unsigned char stringbuffer[300];
int cnt_test;
int Port_Number;
//*********************************************************
int get_Port_Number(char Device_Name[])
{
int Port_Num,i;
i=Device_Name[3];
Port_Num=i-0x30;
i=Device_Name[4];
if (i!=0x00)
{
Port_Num*=10;
Port_Num+=i-0x30;
i=Device_Name[5];
if (i!=0x00)
{
Port_Num*=10;
Port_Num+=i-0x30;
}
}
return Port_Num;
}
//*********************************************************
void init(void)
{
int com;
int i,size1,size2;
int type;
unsigned int values; // 子键个数
char valueName[MAX_PATH];
const char *arr_Subkey_Name="HARDWARE\\DEVICEMAP\\SERIALCOMM";
com=0;
#if 0
RegReadString (REGKEY_HKLM, arr_Subkey_Name, "\\Device\\ProlificSerial2", stringbuffer, buffersize, &realstringsize);
if (realstringsize>0)
InsertListItem (panelHandle, PANEL_RING_COM, -1, stringbuffer,++com);
#endif
// 获取子键个数
RegQueryInfoOnKey (REGKEY_HKLM, arr_Subkey_Name,NULL, &values, NULL, NULL, NULL);
for(i=0;i<values;i++)
{
size1 = MAX_PATH;
size2 = 512;
RegEnumerateValue (REGKEY_HKLM, arr_Subkey_Name,i, valueName, &size1, stringbuffer, &size2,&type);
if((type==_REG_SZ)
&&(size2>0))
{
InsertListItem (panelHandle, PANEL_RING_COM, -1, stringbuffer,++com);
Port_Number=get_Port_Number(stringbuffer);
size1=FindPattern (valueName, 0, -1, "ProlificSerial", 0, 0);
if (size1==-1) // 没有找到
;
else
{
// 子键名称中含有"ProlificSerial"
++cnt_test;
}
}
}
SetCtrlIndex (panelHandle, PANEL_RING_COM, 0);
//读取LabWindows/CVI的存储路径
//RegReadString (REGKEY_HKLM, "SOFTWARE\\National Instruments\\CVI\\8.5\\User Info", "Directory", stringbuffer, buffersize, &realstringsize);
}
//*********************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "com_dect.uir", PANEL)) < 0)
return -1;
init();
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//*********************************************************
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
//*********************************************************
//*********************************************************
//*********************************************************
用户1317815 2014-6-8 20:58
用户746021 2012-9-2 05:06
用户175940 2012-4-9 19:48
非常不错啊!!!!!!!
用户403995 2011-11-24 10:42