[c#] "The semaphore timeout period has expired" error for USB connection

I'm getting this error...

The semaphore timeout period has expired.

On this line...


...but I only get it from time to time. When it happens, it happens over and over again. Then the problem goes away, for hours or days, then it comes back.

The serial port is a USB with a BlueTooth connected.

I think this guy was having a very similar problem, but not in C#

Freeze on SerialPort.Open / DeviceIoControl / GetcommState with usbser.sys

As best I can estimate, I have read his entire problem, and the resulting comments, and the answer, but I really can't figure out which one fixed his problem, or if C# is significantly different from what he was experiencing.

Thanks for any help for the clueless. This is the actual code where it's happening.

public static void Open_ActivePortWeWillUse(String Drone_StringNameFromUser)
    SerialPort TempSerialPort = new SerialPort(Drone_StringNameFromUser, (int) SerialPortSpeed);

    ThePorts.ActivePort1 = TempSerialPort;

    ThePorts.ActivePort1.DataBits = 8;
    ThePorts.ActivePort1.Parity = Parity.None;
    ThePorts.ActivePort1.StopBits = StopBits.One;

    ThePorts.ActivePort1.DataReceived += new SerialDataReceivedEventHandler(OurBackGroundSerialPortReceiver);

    ThePorts.ActivePort1.Open();  // "Sometimes" Error hits here

This question is related to c# serial-port usb semaphore usbserial

The answer is

I had a similar problem which I solved by changing the Port Settings in the port driver (located in Ports in device manager) to fit the device I was using.

For me it was that wrong Bits per second value was set.

This error could also appear if you are having network latency or internet or local network problems. Bridged connections that have a failing counterpart may be the culprit as well.

Okay, I am now connecting without the semaphore timeout problem.

If anyone reading ever encounters the same thing, I hope that this procedure works for you; but no promises; hey, it's windows.

In my case this was Windows 7

I got a little hint from This page on eHow; not sure if that might help anyone or not.

So anyway, this was the simple twenty three step procedure that worked for me

  • Click on start button

  • Choose Control Panel

  • From Control Panel, choose Device Manger

  • From Device Manager, choose Universal Serial Bus Controllers

  • From Universal Serial Bus Controllers, click the little sideways triangle

  • I cannot predict what you'll see on your computer, but on mine I get a long drop-down list

  • Begin the investigation to figure out which one of these members of this list is the culprit...

    • On each member of the drop-down list, right-click on the name

    • A list will open, choose Properties

    • Guesswork time: using the various tabs near the top of the resulting window which opens, make a guess if this is the USB adapter driver which is choking your stuff with semaphore timeouts

  • Once you have made the proper guess, then close the USB Root Hub Properties window (but leave the Device Manager window open).

  • Physically disonnect anything and everything from that USB hub.

  • Unplug it.

  • Return your mouse pointer to that USB Root Hub in the list which you identified earlier.

  • Right click again

  • Choose Uninstall

  • Let Windows do its thing

  • Wait a little while

  • Power Down the whole computer if you have the time; some say this is required. I think I got away without it.

  • Plug the USB hub back into a USB connector on the PC

  • If the list in the device manager blinks and does a few flash-bulbs, it's okay.

  • Plug the BlueTooth connector back into the USB hub

  • Let windows do its thing some more

  • Within two minutes, I had a working COM port again, no semaphore timeouts.

Hope it works for anyone else who may be having a similar problem.

I had this problem as well on two different Windows computers when communicating with a Arduino Leonardo. The reliable solution was:

  • Find the COM port in device manager and open the device properties.
  • Open the "Port Settings" tab, and click the advanced button.
  • There, uncheck the box "Use FIFO buffers (required 16550 compatible UART), and press OK.

Unfortunately, I don't know what this feature does, or how it affects this issue. After several PC restarts and a dozen device connection cycles, this is the only thing that reliably fixed the issue.

Too many big files all in one go. Windows barfs. Essentially the copying took too long because you asked too much of the computer and the file locking was locked too long and set a flag off, the flag is a semaphore error.

The computer stuffed itself and choked on it. I saw the RAM memory here get progressively filled with a Cache in RAM. Then when filled the subsystem ground to a halt with a semaphore error.

I have a workaround; copy or transfer fewer files not one humongous block. Break it down into sets of blocks and send across the files one at a time, maybe a few at a time, but not never the lot.




Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to serial-port

python to arduino serial read & write Reading serial data in realtime in Python Python: Writing to and Reading from serial port IOException: read failed, socket might closed - Bluetooth on Android 4.3 Reading and writing to serial port in C on Linux Python Serial: How to use the read or readline function to read more than 1 character at a time Serial Port (RS -232) Connection in C++ "The semaphore timeout period has expired" error for USB connection What is the correct way to read a serial port using .NET framework? Arduino COM port doesn't work

Examples related to usb

Is there an equivalent of lsusb for OS X USB Debugging option greyed out "The semaphore timeout period has expired" error for USB connection How to change Android usb connect mode to charge only? Is it possible to program Android to act as physical USB keyboard? Why does adb return offline after the device string? Simple way to query connected USB devices info in Python? How do I connect to a terminal to a serial-to-USB device on Ubuntu 10.10 (Maverick Meerkat)? How to load my app from Eclipse to my Android phone instead of AVD Controlling a USB power supply (on/off) with Linux

Examples related to semaphore

semaphore implementation "The semaphore timeout period has expired" error for USB connection Semaphore vs. Monitors - what's the difference? Is there a Mutex in Java? When should we use mutex and when should we use semaphore Lock, mutex, semaphore... what's the difference? Delete all SYSTEM V shared memory and semaphores on UNIX-like systems What is mutex and semaphore in Java ? What is the main difference? Difference between binary semaphore and mutex What is a semaphore?

Examples related to usbserial

"The semaphore timeout period has expired" error for USB connection