Pipistrello: Identify virtual com port (e.g. COM4) by the device serial number

Recommended Posts


I did a quick demo that Pipistrello boards can be uniquely identified when several are connected to the same host.
The same works probably with Papilio and others, but I didn't test it.
The serial number can be read e.g. with FTDI's FT_PROG utility.Alternatively, Windoze device manager, "View/devices by connection", "USB serial converter A", "Details", "Device instance path".

Adapted from stackexchange.


using System;
using System.Management;
using System.Linq;
using System.Text.RegularExpressions;

... your class here

    private static string[] matchRegexReturnString(Regex r,string s) {
        Match m = r.Match(s);
        int n = m.Groups.Count - 1; // captures start at index 1
        if(n > 0) {
            string[] result = new string[n];
            for(int ix = 0;ix < n;++ix) {
                result[ix] = m.Groups[ix + 1].Value;
            return result;
        else {
            return null;

    private static string getComPortName(string serialNr) {
        ManagementObjectSearcher searcher2 = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_PnPEntity");

        Regex re1 = new Regex(@"FTDIBUS..VID_0403.PID_6010.(\d+)\D");
        Regex re2 = new Regex(@"(COM\d+)");

        foreach(ManagementObject queryObj in searcher2.Get()) {
            string p = queryObj.Path.Path.ToString();
            // search for expected FTDI device
            string[] m = matchRegexReturnString(re1,p);
            if(m != null) {
                // search for supported serial number
                if(m[0] == serialNr) {
                    string uu = queryObj["Caption"].ToString();
                    m = matchRegexReturnString(re2,uu);
                    if(m != null) {
                        return m[0];
        return null;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now