根据PID和VID得到USB转串口的串口号
/*******************************************************************************
*
* FindAppUART.cpp - PC command line utility for enumerating MSP430 EVM's
* Application UARTs.
*
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/ //------------------------------------------------------------------------------
// Desc: PC command line utility for enumerating MSP430 EVM's Application UARTs.
// The application returns the COM port number of the first UART that is
// found. If this is successful the error code is set to '0'. In case of
// the UART string could not be determined '1' is returned.
//
// The code was developed with the Express Edition of Visual C++ 2008
// http://www.microsoft.com/express/
//
// Ver.: 0.1 (February 2011)
// - Alpha version
//
// Auth: Andreas Dannenberg
// MSP430 Applications
// Texas Instruments, Inc.
//------------------------------------------------------------------------------ // Windows Header Files
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff
// from Windows headers
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <setupapi.h> // "setupapi.lib" must be linked
// to the project
// C Runtime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h> //------------------------------------------------------------------------------
// DWORD WINAPI EnumComPorts(DWORD dwIndex, LPTSTR lptszName,
// DWORD dwNumOfElements)
//
// User-mode code fragment to identify attached VCP COMnn port[s] with a
// specific device instance ID based on USB VID and PID and returns the COMnn
// port that the OS embeds into the device instance ID. When called with
// dwIndex = 0, the function will enumerate all COMPORT class devices and
// return the name of the first one that was found. Subsequent calls using an
// incremented dwIndex parameter can be performed until ERROR_NO_MORE_ITEMS
// is returned.
//
// IN: dwIndex COMPORT class device # 0, 1, 2, ... to check
// dwNumOfElements The size of the lptszName buffer
// OUT: lptszName COMnn name of given device #
// return() ERROR_SUCCESS - lpszName is valid
// ERROR_NO_MORE_ITEMS - End of device list reached
//------------------------------------------------------------------------------
DWORD WINAPI EnumComPorts(DWORD dwIndex, LPTSTR lptszName, DWORD dwNumOfElements)
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
TCHAR *pcParse; // Create a HDEVINFO with all present devices
hDevInfo = SetupDiGetClassDevs(
NULL,
, // Enumerator
,
DIGCF_PRESENT | DIGCF_ALLCLASSES); if (INVALID_HANDLE_VALUE == hDevInfo)
{
return GetLastError();
} // Enumerate through all devices in set
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i = ; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
LPTSTR buffer = NULL;
DWORD buffersize = ; // Get the device instance ID that is associated with the device information element
while (!SetupDiGetDeviceInstanceId(
hDevInfo,
&DeviceInfoData,
buffer,
buffersize,
&buffersize))
{
if (buffer)
{
LocalFree(buffer);
} if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
// Change the buffer size. Double the size to avoid problems on
// W2K MBCS systems per KB 888609.
buffer = (LPTSTR)LocalAlloc(LPTR, buffersize * );
}
else
{
// Error: could not get device instance ID
// Cleanup and return error code
SetupDiDestroyDeviceInfoList(hDevInfo);
return GetLastError();
}
} if (buffer)
{
// Look for the "Application UART" of common MSP430 EVMs. The application UART
// has an USB VID of 0x0451 (Texas Instruments) and an PID of 0xF432.
const TCHAR testval[] = _T("USB\\VID_0451&PID_F432&MI_00"); if (NULL != _tcsstr(buffer, testval))
{
TCHAR szFriendlyName[MAX_PATH]; if (SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_FRIENDLYNAME,
NULL,
(PBYTE)szFriendlyName,
sizeof(szFriendlyName) - ,
NULL))
{
// Check if we have reached the dwIndex-th element, if not keep looking
if (dwIndex == )
{
// Find pointer to "COM" substring (secure)
szFriendlyName[sizeof(szFriendlyName) - ] = 0x00;
pcParse = _tcsstr(szFriendlyName, _T("COM")); if (pcParse != NULL)
{
// Zero-terminate COM port string after last digit
if (!isdigit(pcParse[])) {
pcParse[] = ;
}
else if (!isdigit(pcParse[])) {
pcParse[] = ;
}
else {
pcParse[] = ;
} // Pass string to the return parameter
_tcscpy_s(lptszName, dwNumOfElements, pcParse); // Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo); return ERROR_SUCCESS;
}
}
else
{
dwIndex--;
}
}
}
}
} // Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo); return ERROR_NO_MORE_ITEMS;
} //------------------------------------------------------------------------------
// Main application entry point. Simply return the first Application UART
// COM port that was found to STDOUT.
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szDeviceName[MAX_PATH];
DWORD dwReturnValue; dwReturnValue = EnumComPorts(, szDeviceName, _countof(szDeviceName)); if (dwReturnValue == ERROR_SUCCESS) {
_ftprintf_s(stdout, _T("%s\r\n"), szDeviceName);
return ;
} return ;
}
根据PID和VID得到USB转串口的串口号的更多相关文章
- RK3288 USB触摸屏无法使用,需要添加PID和VID
RK3288 Android5.1 现象:USB 接口触摸屏插到板子上,触摸屏无法使用,有可能出现更奇葩的,同一套代码,有的板子可以用,有的板子不能用. 1.打开串口调试,插上触摸屏,读取触摸屏的 ...
- 通过串口设备vid,pid自动获得该设备所对应的串口号
用C#做串口通讯很方便,因为dotfx2.0已经集成了Serial Port控件,此控件使用上比MSComm控件更简单,当然它也有一个小bug (RecievedBytesThreshold设置有时候 ...
- ubuntu下minicom和USB转串口(转)
ubuntu下minicom和USB转串口(转) minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有“超级终端”那么易用,但是使用习惯之后读者将会体会到它的高效与便利 ...
- [驱动]内核添加USB转串口驱动支持
转自:http://blog.csdn.net/gatieme/article/details/49491325 目录 1. 问题 2. 驱动源码 3. 内核配置 4. 编译内核和模块驱动 5. 加载 ...
- 【小技巧】9针USB转串口简易连通性测试,附25针转9针
Part 1 前言 最近用SecureCRT连接串口,因为是笔记本用的USB转串口,好多次出现安装驱动OK,连接上了,但是没有串口打印.无法进行控制的问题:所以不清楚是USB串口的驱动问题,还是转接用 ...
- Ubuntu系统下USB转串口的使用
PC系统是Ubuntu12.04,与路由器开发板之间用USB转串口线连接. 一.硬件连接 确认Ubuntu对USB转串口设备的支持. 1.# lsmod | grep usbserial如果有usbs ...
- 单片机usb转串口的时灵时不灵的解答
写这篇博客,首先检讨一下自己,因为以前串口的程序,也和步进电机一样,时灵时不灵,我现在终于知道这是为什么了,因为51上有三个串口,一个公口,一个母口,一个usb转串口,这样的话,串口有3个了,我手头上 ...
- 在MAC OS X下安装usb转串口驱动(PL2303主控芯片)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 因为最近手里有一块STM32Discovery开发板,所以想搞一下STM32的开发,我前面的 ...
- mac usb转串口 连接树莓PI
USB 转串口是淘宝买的 http://item.taobao.com/item.htm?spm=a1z09.2.9.50.YOJBwG&id=38963495468&_u=4m1dr ...
随机推荐
- netbeans中wicket插件对应的jQuery-ui版本
在netbean里使用wicket,我们经常习惯使用netbeans自带的wicket插件直接安装wicket,但是因为netbean上的 wicket插件版本比较老,使得我们很多新的第三方wicke ...
- JavaScript 建立简单的图片库
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 使用Python拼接多张图片
写机器学习相关博文,经常会碰到很多公式,而Latex正式编辑公式的利器.目前国内常用的博客系统,好像只有博客园支持,所以当初选择落户博客园.我现在基本都是用Latex写博文,然后要发表到博客园上与大家 ...
- Inverse是hibernate双向关系中的基本概念。inverse的真正作用就是指定由哪一方来维护之间的关联关系。当一方中指定了“inverse=false”(默认),那么那一方就有责任负责之间的关联关系,说白了就是hibernate如何生成Sql来维护关联的记录
<set name ='students' table="students_table" inverse='false'(默认不用写) > <key column ...
- Winsock IO模型之select模型
之所以称其为select模型是因为它主要是使用select函数来管理I/O的.这个模型的设计源于UNIX系统,目的是允许那些想要避免在套接字调用上阻塞的应用程序有能力管理多个套接字. int sele ...
- AudioManager --- generateAudioSessionId
AudioManager中的generateAudioSessionId方法介绍: 1.方法声明 pubilc void generateAudioSessionId(); 2.API描述 返回一个不 ...
- python实现不可修改的常量
因为种种原因,Python并未提供如C/C++/Java一样的const修饰符,换言之,python中没有常量,至少截止2015年年末,还没有这个打算.Python程序一般通过约定俗成的变量名全大写的 ...
- 转】Mahout分步式程序开发 聚类Kmeans
原博文出自于: http://blog.fens.me/hadoop-mahout-kmeans/ 感谢! Mahout分步式程序开发 聚类Kmeans Hadoop家族系列文章,主要介绍Hadoop ...
- 【MySql】性能优化之分析命令
一 当发现程序运行比较慢的时候,首先排除物力资源问题之后,就将注意力转向mysq数据库: 1.首先确定运行慢的sql语句: mysql> show full processlist; 2.确认低 ...
- JavaIO(06)文件复制
文件复制一般是采用两种方式进行操作: 1:将源文件中的内容全部读取到内存中,并一次性的写入到目标文件中:(不常用这种方式) 2:不将源文件中的内容全部读取进来,而是采用边读边写的方式: 实例01: ...