none
SerialPort.GetPortNames returns strange value RRS feed

  • Question

  • Hello

    When I ask for the different ports used with SerialPort.GetPortNames, I received a string with "COM1, COM3" then some space and several asian (I can not tell from which country) characters.

    Previously I got something like "COM1, COM3" and nothing else behind.

    Someone can tell me what is the problem, please?

    Thanks

    Cathy


    • Edited by Cathy L. _ Sunday, December 23, 2018 7:43 PM
    Sunday, December 23, 2018 7:42 PM

All replies

  • There may not be a problem at all.  Did you recently plug in a device that might have added a fake COM port?  Some industrial device that uses a USB-to-Serial translator?  Those devices need to install their own drivers, and the devices are often manufactured in Asia.  Are you able to use your serial ports?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, December 24, 2018 3:01 AM
  • Hi Cathy L. _,

    Thank you for posting here.

    For your question, the code would work well normally. Maybe some special reason cause the error. Please check the link below.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/b195d391-03a0-4221-9b49-ec0133373d58/serialportgetportnames-returns-garbage?forum=vbgeneral

    The strange value is meaningless. The quick way is to use some Regular Expressions to filter out the number portion of the com port name

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 24, 2018 8:19 AM
    Moderator
  • Thanks a lot Wendy

    I have Logitech Unifying USB to connect Keyboard and mouse, and I have a Chinese WEMOS D1 mini Pro (on COM 3).

    Thanks for your answer, I am going to check the links.

    Cathy L.

    Tuesday, December 25, 2018 8:48 AM
  • You may try this code:

    <style type="text/css"><!-- @page { margin: 2cm } p { margin-bottom: 0.25cm; line-height: 120% } --> </style>

    string[] ports = SerialPort.GetPortNames();

    for(int i=0;i<ports.Length;i++)

    {

    string mystr = ports[i];

    if((((mystr[mystr.Length-1]) >= 0*30) & ((mystr[mystr.Length-1]) >= 0*39)

    {

    }

    else

    {

    mystr=mystr.Remove(mystr.Length-1);

    }

    ports[i] = mystr;

    }


    Wednesday, December 26, 2018 8:40 AM
  • Hi Cathy L,

    Is there any update? Do you try the method that Wendy mentioned, if the issue still exists, please feel fee let us know.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 27, 2018 7:17 AM
    Moderator