根据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 ...
随机推荐
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.2安装操作系统CentOS5.4
2.2. 安装操作系统CentOS5.4 两个虚拟机都安装,此步骤在创建虚拟机节点时: 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境所有链接: 1.资源 ...
- Phonegap中用ajax读取PHP服务器的数据
直接上代码: HTML: var URL="网站地址&callback=?"; $.ajax({ type : 'GET', url : URL, dataType : ' ...
- base64 encoding
//https://en.wikipedia.org/wiki/Base64 std::string base64Encode(const std::vector<char>& b ...
- C#对Excel打印时,PageSetup 对象详解
PageSetup 对象包含所有页面设置的属性(左边距.底部边距.纸张大小等).下面按“页面”.“页边距”.“页眉/页脚”.“工作表”和“无对应选项卡”五个类别,逐一介绍. 一.页面 与“页面”选项卡 ...
- 8、NFC技术:让Android自动打开网页
创建封装Uri的NdefRecord public NdefRecord createUri(String uriString); public NdefRecord cre ...
- 如何配置仿真器DM8127+SEED-XDS560v2PLUS和连接不上的问题的解决
1 根据配置焊接JTAG电路转接板.我用的是14pin的. 2 安装仿真器驱动.安装完如下图 我安装的时候没有自动装上,第一次显示问号,后来手动的. 3 设置ccs工程 4 最后调试是这个样子 5 查 ...
- TV端产品设计法则和分析
对TV端产品设计的分析太特么少了.翻遍网络,大多也是针对UI设计的分析,这篇从产品设计的角度,梳理下现有的TV端产品设计法则,顺道做点分析.(前方多图,高能预警) 目录: 1. TV端产品使用场景 2 ...
- [转] 編程風格要素-The Elements of Programming Style 中文英文中英對照
转自: http://www.loliman3000.com/tech/2fe33ce32906f0302412881.php 下面的程序風格規則提煉自Brian Kernighan和P. J. Pl ...
- Ubuntu 下一个可用的音乐播放器
参考:http://www.pairsdoll.com/install-audacious-music-palyer-in-ubuntu.html/ 方法:打开terminal,sudo apt-ge ...
- JAVA逻辑字符串判断真假
package com.chinahrt.zyn.iteye; import javax.script.Bindings; import javax.script.Compilable; import ...