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

User.1 picture User.1 · Dec 22, 2012 · Viewed 107.1k times · Source

I'm getting this error...

The semaphore timeout period has expired.

On this line...

ThePorts.ActivePort1.Open();

...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
}

Answer

Rudy Hinojosa picture Rudy Hinojosa · Nov 11, 2016

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.