找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4715|回复: 0
打印 上一主题 下一主题
收起左侧

激光测距模块VL530X API程序源码

[复制链接]
跳转到指定楼层
楼主
激光测距模块VL530X API,内含ContinuousRanging测距模式例程,SingleRanging测距模式例程,SingleRanging_High_Accuracy测距模式例程,SingleRanging_High_Speed测距模式例程,SingleRanging_Long_Range测距模式例程可供参考。


源程序如下:
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include "get_nucleo_serial_comm.h"

  5. DWORD QueryKey(HKEY hKey, TCHAR *pSearchDevice, TCHAR *pPortName)
  6. {
  7.     TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
  8.     DWORD    cbName;                   // size of name string
  9.     TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
  10.     DWORD    cchClassName = MAX_PATH;  // size of class string
  11.     DWORD    cSubKeys=0;               // number of subkeys
  12.     DWORD    cbMaxSubKey;              // longest subkey size
  13.     DWORD    cchMaxClass;              // longest class string
  14.     DWORD    cValues;              // number of values for key
  15.     DWORD    cchMaxValue;          // longest value name
  16.     DWORD    cbMaxValueData;       // longest value data
  17.     DWORD    cbSecurityDescriptor; // size of security descriptor
  18.     FILETIME ftLastWriteTime;      // last write time

  19.     DWORD i, retCode;

  20.     TCHAR  achValue[MAX_VALUE_NAME];
  21.     DWORD cchValue = MAX_VALUE_NAME;
  22.     TCHAR  achDataValue[MAX_VALUE_NAME];
  23.     DWORD cchDataValue = MAX_VALUE_NAME;

  24.     // Get the class name and the value count.
  25.     retCode = RegQueryInfoKey(
  26.         hKey,                    // key handle
  27.         achClass,                // buffer for class name
  28.         &cchClassName,           // size of class string
  29.         NULL,                    // reserved
  30.         &cSubKeys,               // number of subkeys
  31.         &cbMaxSubKey,            // longest subkey size
  32.         &cchMaxClass,            // longest class string
  33.         &cValues,                // number of values for this key
  34.         &cchMaxValue,            // longest value name
  35.         &cbMaxValueData,         // longest value data
  36.         &cbSecurityDescriptor,   // security descriptor
  37.         &ftLastWriteTime);       // last write time

  38.     // Enumerate the subkeys, until RegEnumKeyEx fails.
  39.    
  40.     if (cSubKeys)
  41.     {
  42.         _tprintf(TEXT( "\nNumber of subkeys: %d\n"), (int)cSubKeys);

  43.         for (i=0; i<cSubKeys; i++)
  44.         {
  45.             cbName = MAX_KEY_LENGTH;
  46.             retCode = RegEnumKeyEx(hKey, i,
  47.                      achKey,
  48.                      &cbName,
  49.                      NULL,
  50.                      NULL,
  51.                      NULL,
  52.                      &ftLastWriteTime);
  53.             if (retCode == ERROR_SUCCESS)
  54.             {
  55.                 _tprintf(TEXT("(%d) %s\n"), (int)(i+1), achKey);
  56.             }
  57.         }
  58.     }

  59.     // Enumerate the key values.

  60.     if (cValues)
  61.     {
  62.         printf( "\nNumber of values: %d\n", (int)cValues);

  63.         for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
  64.         {
  65.             cchValue = MAX_VALUE_NAME;
  66.             achValue[0] = '\0';
  67.             cchDataValue = MAX_VALUE_NAME;
  68.             achDataValue[0] = '\0';
  69.             retCode = RegEnumValue(hKey, i,
  70.                 achValue,
  71.                 &cchValue,
  72.                 NULL,
  73.                 NULL,
  74.                 achDataValue,
  75.                 &cchDataValue );
  76.             if (retCode == ERROR_SUCCESS)
  77.             {          
  78.                 _tprintf(TEXT("(%d) %s data %s  cchDataValue=%d\n"), (int)(i+1), achValue, achDataValue, (int)cchDataValue);
  79.                 if (strcmp(pSearchDevice, achValue) == 0) {
  80.                         strcpy(pPortName, achDataValue);
  81.                         _tprintf(TEXT("Found\n"));
  82.                         return 1;
  83.                 }
  84.             } else {
  85.                 _tprintf(TEXT("ERROR (%d) %d \n"), (int)(i+1), (int)retCode);
  86.             }
  87.         }
  88.     }
  89.    
  90.     return 0;
  91. }


  92. DWORD GetNucleoSerialComm(TCHAR *pSerialCommStr)
  93. {

  94.    HKEY hTestKey;
  95.    DWORD state = 0;
  96.     TCHAR  achDataValue[MAX_VALUE_NAME];

  97.    if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  98.         TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
  99.         0,
  100.         KEY_READ,
  101.         &hTestKey) == ERROR_SUCCESS
  102.       )
  103.    {
  104.         state = QueryKey(hTestKey, "\\Device\\USBSER000", achDataValue);
  105.         if (state == 1) {
  106.                 _tprintf(TEXT("found USBSER000 at port com %s\n"), achDataValue);
  107.                 strcpy(pSerialCommStr, achDataValue);               
  108.         } else
  109.                 _tprintf(TEXT("ERROR USBSER000 not found!\n"));

  110.    }
  111.    
  112.    RegCloseKey(hTestKey);

  113.    if (state == 1)
  114.         return 1;               
  115.    else
  116. ……………………

  117. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
en.STSW-IMG005.zip (3.7 MB, 下载次数: 26)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表