资源简介
Matlab自动识别插入电脑的串口设备及其串口号。函数运行之后返回N×2的单元矩阵,N代表所有活动串口数目。每行的第一列是接入电脑的设备名称(例如'USB-SERIAL CH340'),第二列是其对应的串口号。
代码片段和文件信息
function devices = IdentifySerialComs()
% function:identifies Serial COM devices on Windows systems by friendly name and service.
% output:a cell array where the first column holds the name of the device
% and the second column holds the COM number. Devices returns empty if nothing is found.
% author:Modified by “yuhansgg(Shi Gaige)“ based on code of “Lorgio Teodovich“
% date: 2017.12.29
devices = [];
Skey = ‘HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM‘;
[~ list] = dos([‘REG QUERY ‘ Skey]);
if ischar(list) && strcmp(‘ERROR‘list(1:5)) %%strcmp 两个字符串相同返回1
disp(‘Error: EnumSerialComs - No SERIALCOMM registry entry‘)
return;
end
list = strread(list‘%s‘‘delimiter‘‘ ‘); %#ok requires strread()
coms = 0;
for i = 1:numel(list) %%numel 返回元素个数
if strcmp(list{i}(1:3)‘COM‘)
if ~iscell(coms)
coms = list(i);
else
coms{end+1} = list{i}; %#ok Loop size is always small
end
end
end
out = 0;
outK = 0;
for j=1:2
switch j
case 1
key = ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\‘;
case 2
key = ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\FTDIBUS\‘;
end
[~ vals] = dos([‘REG QUERY ‘ key ‘ /s /f “FriendlyName“ /t “REG_SZ“‘]);
if ischar(vals) && strcmp(‘ERROR‘vals(1:5))
disp(‘Error: EnumSerialComs - No Enumerated USB registry entry‘)
return;
end
vals = textscan(vals‘%s‘‘delimiter‘‘\t‘);
vals = cat(1vals{:});
for i = 1:numel(vals)
if strcmp(vals{i}(1:min(12end))‘FriendlyName‘)
if ~iscell(out)
out = vals(i);
else
out{end+1} = vals{i}; %#ok Loop size is always small
end
if ~iscell(outK)
outK = vals(i-1);
else
outK{end+1} = vals{i-1}; %#ok Loop size is always small
end
end
end
end
i_dev=1;Sservices=[];
for i = 1:numel(coms)
match = strfind(out[coms{i}‘)‘]);
ind = 0;
for j = 1:numel(match)
if ~isempty(match{j})
ind = j;
[~ sers] = dos([‘REG QUERY “‘ outK{ind} ‘“ /f “Service“ /t “REG_SZ“‘]);
sers = textscan(sers‘%s‘‘delimiter‘‘\t‘);
sers = cat(1sers{:});
if (numel(sers)>1)
sers=strread(sers{2}‘%s‘‘delimiter‘‘ ‘);
Sservices{i_dev} = sers{3};
i_dev=i_dev+1;
end
end
end
end
Sservices=unique(Sservices);
i_dev=1;
for ss=1:numel(Sservices)
key = [‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\‘ Sservices{ss} ‘\Enum‘];
[~ vals] = dos([‘REG QUERY ‘ key ‘ /f “Count“‘]);
if ischar(vals) && strcmp(‘ERROR‘vals(1:5))
% disp(‘Error: EnumSerialComs - No Enumerated services USB registry entry‘)
% return
end
vals 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5119 2017-12-29 10:37 IdentifySerialComs.m
- 上一篇:右臂表面肌电信号数据
- 下一篇:Matlab小波包分解函数
相关资源
- 串行级联cpm系统MATLAB仿真
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
川公网安备 51152502000135号
评论
共有 条评论