根据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 ...
随机推荐
- PHP.ini 配置文件解析
[PHP] ;;;;;;;;;;;;;;;;;;;; About php.ini ;;;;;;;;;;;;;;;;;;;;; PHP's initialization file, generall ...
- Downloading the Source
The Android source tree is located in a Git repository hosted by Google. This document describes ho ...
- memset()实现及细节
memset是计算机中C/C++语言函数.将s所指向的某一块内存中的前n个 字节的内容全部设置为ch指定的ASCII值, 块的大小由第三个参数指定,这个函数通常为新申请的内存做初始化工作, 其返回值为 ...
- BITED数学建模七日谈之七:临近比赛时的准备工作
经过前面六天的文章分享,相信大家对数学模型的相关准备.学习都有了更新的认识,希望大家能从中有所收获,以便更高效地准备比赛和学习数学模型,本文是数学建模经验谈的最后一天:临近比赛的准备工作,希望在临近比 ...
- ASP.NET MVC3 系列教程 - 部署你的WEB应用到IIS 6.0
I:ASP.NET MVC3 部署的前期工作 1.确认部署的服务器操作系统环境 首先我们确认服务器的操作系统版本 可以从系统命令行工具里输入: systeminfo 获取相关操作系统信息例如 然后再确 ...
- 一道关于java 类初始化 成员初始化的笔试题的解析
代码如下: java笔试题public class Mapplication { private static int n; private static Mapplication m1 = new ...
- 单源最短路径-Dijkstra算法
1.算法标签 贪心 2.算法描述 具体的算法描述网上有好多,我觉得莫过于直接wiki,只说明一些我之前比较迷惑的. 对于Dijkstra算法,最重要的是维护以下几个数据结构: 顶点集合S : 表示已经 ...
- s3c2440串口裸板驱动(使用fifo)
使用fifo的好处有: 1:串口的数据发送的数据量较大时,使用fifo可以大大降低MCU的开销.(有点类似串入并出的cput处理模型,本质上还是串行收发) 2:在某些特殊场合,例如制定较复杂的协议时, ...
- 消息队列与RabbitMQ
1 什么是消息队列 消息指进程或应用间通信的数据:队列是保存数据的结构:消息队列是指进程或应用间通信时,保存消息的容器.消息队列独特的机制和结构保证了消息发送者和接收者之间良好的异步通信. 2 为什么 ...
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
mvn war:war命令出错: 原因: maven的web项目默认的webroot是在src\main\webapp.如果在此目录下找不到web.xml就抛出以上的异常. 解决方案: 在pom.xm ...