c# - Finding the serial device COM port -


i have windows c# application . application connects rfid card reader on serial port . though have given com port 3 default . land situations user's port not available , port being used different windows os.

my application give user ability change com port , find com port being used operating system , user needs go device manager , check , novice person might not comfortable .

is there function or way find port rfid card connected in windows , can display :

application port set : com .... device connection port on os : com ....

also target framework 3.5

edit 1:

tried using serialport.getportnames() returns empty string : system.string[]..

my rfid device listed under device manager ===> ports(com & lpt) silicon labs cp210x usb uart bridge (com3)

hi @user3828453 how following , can, use correct port number returned if still have empty port have ask user go device manager , update port via interface.

private static string getrfidcomport() {   string portname = "";    ( int = 1; <= 20; i++ )   {     try     {       using ( serialport port = new serialport( string.format( "com{0}", ) ) )       {         // try open port         port.open();          // ensure you're communicating correct device (some logic test it's device)          // close port         port.close();       }      }     catch ( exception ex )     {       console.writeline( ex.message );     }   }    return portname; } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -