locked
Check on Serial Ports is "breaking" USB modem RRS feed

  • Question

  • Hello!

    I am using the following code to enumerate through com ports to determine if the attached modems are in use.  When I get to my usb modem, it returns the correct "PostIsAvailable" status, but then it kind of locks up the modem and I get the following error when I try to manually query the modem I get: "The modem failed to respond. Make sure it is properly connected and turned on. If it is an internal modem, or is connected, verify that the interupt for the port is properly set."  I either have to manually requery the modem or unplug/plug it again.  This code works fine on my external serial modem, but not the USB modem.  Any thoughts???  Thanks!!!

        Public Function PortIsAvailable(ByVal port As String) As Boolean
          Dim TempPort As New SerialPort
          TempPort.PortName = port 
    
          Try
            TempPort.Open()
            Threading.Thread.Sleep(100)
    
            If TempPort.DsrHolding Then
              If TempPort.IsOpen Then
                TempPort.Close()
                TempPort.Dispose()
                Threading.Thread.Sleep(2000)
              End If
              
              Return True
             End If
    
          Catch
            Return False
          Finally
    
          End Try
        End Function
    

    Tuesday, May 31, 2011 4:59 PM

Answers

  • This, almost certainly, is a driver issue, and one that cannot be solved except by updating the driver from the modem manufacturer. 

    If you download my EnhancedSerialPort dll, you will find the GetPortDescriptions() method, which returns a list of installed devices.  This contains both a list of port number and descriptive information returned by the driver, and will allow you to locate the USB modem.  However, your problem seems to be after the modem port has been opened -- this cannot be solved at the application level.

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    • Proposed as answer by Mike Feng Thursday, June 2, 2011 5:50 AM
    • Marked as answer by Mike Feng Tuesday, June 21, 2011 9:23 AM
    Wednesday, June 1, 2011 9:59 PM
  • BTW, you can try the "work around" of calling SerialPort.Open() then delaying a short time, perhaps 500 mS before attempting to do anything with the port.  Perhaps a simple delay here will allow it to work -- though this would be crude, I've seen this approach work with other driver problems.

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    • Proposed as answer by Mike Feng Thursday, June 2, 2011 5:50 AM
    • Marked as answer by Mike Feng Tuesday, June 21, 2011 9:23 AM
    Wednesday, June 1, 2011 10:06 PM

All replies

  • Hi,

    Dunno.  USB devices use virtual serial port drivers, and these drivers may not work exactly the same way as physical serial port devices.

    However, checking the status of DSR is not a reliable way to determine if a modem is present.  DSR will (often, though not universally) be asserted by non-modem serial devices.

    The "best" way to determine if a modem is present is to send a command and await a response.  Here is what I use:

    SerialPort.Write("ATE1V1Q0" & vbCr)

    Then, I wait for a couple of hundred mS for the "OK" & vbCrLf response form a connected modem -- btw, you must make sure that RTSEnable = True before you send the command.

    Also, you do not need to call Dispose after you close the port.

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    Wednesday, June 1, 2011 4:44 PM
  • Dick -

     

    Thanks for the info... I have updated my code per your suggestions and although that routine appears to be working, I am still having the original issue where "quering" the modem to determine if it is available locks it up and I get the following error when I try to manually query the modem I get: "The modem failed to respond. Make sure it is properly connected and turned on. If it is an internal modem, or is connected, verify that the interupt for the port is properly set." I either have to manually requery the modem or unplug/plug it again.  Anybody else have suggestions???

     

    Thank you!!

    Wednesday, June 1, 2011 8:08 PM
  • I either have to manually requery the modem or unplug/plug it again.  Anybody else have suggestions???

     Thank you!!


    Hello,

    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/c1165f03-2338-4f04-ae76-4284ab40c53f

    Take a look here. My answer is at the bottom of this thread. A little mistake.

    best regards Ellen

    backup: get all avaiable COM Ports with this code:

     Dim Portnames As String() = SerialPort.GetPortNames
    
        If Portnames IsNot Nothing Then
          

    Ich benutze/ I'm using VB2008 & VB2010
    • Edited by Ellen Ramcke Wednesday, June 1, 2011 9:16 PM backup
    Wednesday, June 1, 2011 8:53 PM
  • This, almost certainly, is a driver issue, and one that cannot be solved except by updating the driver from the modem manufacturer. 

    If you download my EnhancedSerialPort dll, you will find the GetPortDescriptions() method, which returns a list of installed devices.  This contains both a list of port number and descriptive information returned by the driver, and will allow you to locate the USB modem.  However, your problem seems to be after the modem port has been opened -- this cannot be solved at the application level.

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    • Proposed as answer by Mike Feng Thursday, June 2, 2011 5:50 AM
    • Marked as answer by Mike Feng Tuesday, June 21, 2011 9:23 AM
    Wednesday, June 1, 2011 9:59 PM
  • BTW, you can try the "work around" of calling SerialPort.Open() then delaying a short time, perhaps 500 mS before attempting to do anything with the port.  Perhaps a simple delay here will allow it to work -- though this would be crude, I've seen this approach work with other driver problems.

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    • Proposed as answer by Mike Feng Thursday, June 2, 2011 5:50 AM
    • Marked as answer by Mike Feng Tuesday, June 21, 2011 9:23 AM
    Wednesday, June 1, 2011 10:06 PM