根据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 ...
随机推荐
- IT技术人士 不能一辈子靠技术生存
我现在是自己做,但我此前有多年在从事软件开发工作,当回过头来想一想自己,觉得特别想对那些初学JAVA/DOT.NET技术的朋友说点心里话,希望你们能从我们的体会中,多少受点启发(也许我说的不好,你不赞 ...
- AJAX overrideMimeType作用
我们经常在AJAX代码中发现如下代码: if (http_request.overrideMimeType) { http_request.overrideMimeType("te ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
- LruCache--远程图片获取与本地缓存
Class Overview A cache that holds strong references to a limited number of values. Each time a value ...
- 我常用的VBS方法(QTP)
这些是4年前在HP用QTP做自动化测试时候总结的一些,现在贴出来,说不准以后会不会用到 当初花了2天时间写的一个自动生成的Excel Report Public Function Report (st ...
- winform form
WinForm:Windows Form,.Net中用来开发Windows窗口程序的技术,无论是之前学的控制台程序,还是后面要学的asp.net都是调用.net框架,因此所有知识点都是一样的.新建一个 ...
- linux 条件变量
互斥量就是一把锁,在访问数据时能保证同一时间内只有一个线程访问数据,在访问完以后再释放互斥量上的锁. 条件变量是利用线程间共享的全局变量进行同步的一种机制,主要包括两个动作:一个线程等待"条 ...
- Eclipse中用Link方式安装Maven插件(转载)
标签: it 分类: 开发软件 1.工具下载: Eclipse4.2 jee版本(注意是Jee,不是标准版的eclipse) 下载地址:http://www.eclipse.org/downloads ...
- 9段高效率开发PHP程序的代码
php是世界上最好的语言 在php网站开发中,大家都希望能够快速的进行程序开发,如果有能直接使用的代码片段,提高开发效率,那将是起飞的感觉.今天由杭州php工程师送出福利来了,以下9段高效率开发PHP ...
- Git 常用操作。
1.本地文件被修改后,却想要撤销所有的修改. SVN中可以简单地将被修改的文件直接删除,重新Update一下. Git中本以为可以将文件直接删除然后pull一下,然而却是不行的. 可以使用Revert ...