Last active
September 28, 2024 03:26
-
-
Save Joooohee/47a520e466e9ae610715393bc1902ce3 to your computer and use it in GitHub Desktop.
장치VID/PID를 사용해서 PC에 연결되어 있는 특정 장치 찾기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string getDeviceComport(string vid, string pid) | |
{ | |
var comport = String.Empty; | |
using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort")) | |
{ | |
var portnames = SerialPort.GetPortNames(); | |
var ports = searcher.Get().Cast<ManagementObjectSearcher>().ToList(); | |
var port = ports.FirstOrDefault(w => w["PNPDeviceID"].ToString().Contains($"{vid}&{pid}")); | |
if(String.IsNullOrEmpty(port)) | |
{ | |
comport = port["DeviceID"].ToString(); | |
} | |
} | |
return comport; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment