Does anybody know why this code would produce a "Write Timed Out" error

I am trying to simply write one byte to a Logic Controls cash drawer via a Virtual COM Port.

Code Snippet

Friend Sub OpenCashDrawer1Go()

Dim SerialPort As New SerialPort

Dim oCmd() As Byte = {&H7}

SerialPort.BaudRate = 9600

SerialPort.DataBits = 8

SerialPort.Parity = Parity.None

SerialPort.PortName = "COM3"

SerialPort.StopBits = StopBits.One



SerialPort.Write(oCmd, 0, oCmd.Length)


Catch ex As Exception


End Try


End Sub

Re: Windows Forms General SerialPort "Write Timed Out" Error


Forgot to mention, this is VB.NET 2005 on Windows Vista.



Re: Windows Forms General SerialPort "Write Timed Out" Error

Yu Guo ¨C MSFT

Hi, sstriano,

Based on my standing, you get a "Timout Error" when try to write data to com port, don't you

I tried your code, and it works perfectly in my computer.

Please try to increase the SerialPort.WriteTimeout property, and check if it helps.

Besides, this problem may caused by the hardware driver, please contact your hardware vendor to check if they have met with such issues before.

Hope this helps,


Re: Windows Forms General SerialPort "Write Timed Out" Error


Strange problem, especially considering that the default value for WriteTimeout is "InfiniteTimeout". One thing you shouldn't do is opening and closing the port like this. The MSDN library topic for SerialPort.Close() warns about this:

"The best practice for any application is to wait for some amount of time after calling the Close method before attempting to call the Open method, as the port may not be closed instantly".

Pretty useless comment of course when it doesn't tell you how long to wait. What needs to happen is that enough time should expire for a background thread started by Open() to exit. How long that takes is not predictable and depends on system load. The real best practice is to open the port when your app starts and close it when it exits. Not calling Close() at all is okay, Windows ensures the port is closed when your app terminates.

Re: Windows Forms General SerialPort "Write Timed Out" Error

Yu Guo ¨C MSFT

We are changing the issue type to ¡°Comment¡± because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to ¡°Question¡± by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Thank you!