"The Semaphore Timeout Period Has Expired" Error for Usb Connection

C# to and from Arduino DUE Serial Semaphore Time out

After a few days I have figured out what happened!

The Arduino Due was crashing do to an overflow of data coming from C#!

When it crashed C# would throw the Semaphore Timeout Exception and would never recover from it even when a try and catch was in place, and I gave it time to clear the traffic of all the data sent!

Initially the message sent from C# was the following:

serialPort.Write("#30" + pinNumber + power + "\n");

  • '#' -> order
  • 3 -> Analog Output
  • '0'+pinNumber -> pin number (0 is added when the pin number has only 1 digit ex. 02 por pin 2)
  • power -> value from 0-255
  • '\n' -> end command

When using a slider it would send this message with a different power value many times and in a short time. Crashing the Arduino and requiring a reset.

After days of testing I tried the following message as an experiment:

serialPort.Write(power + "\n");

I temporarily changed the arduino code to only change pin 2, that way only a value to change to was required.

After this change , no matter how fast I dragged the slider from on side to the other, the Arduino would comply and the problem was solved.

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

This is a working part of my c++ class for handling Serial Port communication changed a bit to accommodate C and your needs. If it doesn't work then its probably your driver for virtual port that's faulty

 DCB SerialPortSettings;
HANDLE SerialPort;

int OpenPort(WCHAR* PortName,int BaudRate)
{

SerialPort = CreateFileW(PortName,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);

if(SerialPort==INVALID_HANDLE_VALUE)
return -2;

RtlZeroMemory(&SerialPortSettings,sizeof(DCB));
SerialPortSettings.DCBlength = sizeof(DCB);
if(!GetCommState(SerialPort,&SerialPortSettings))
{
CloseHandle(SerialPort);
return -3;
}

//8n1 RS485
SerialPortSettings.BaudRate = BaudRate;
SerialPortSettings.ByteSize = 8;
SerialPortSettings.Parity = NOPARITY;
SerialPortSettings.StopBits = ONESTOPBIT;
SerialPortSettings.fRtsControl = RTS_CONTROL_TOGGLE;

if(!SetCommState(SerialPort,&SerialPortSettings))
{
CloseHandle(SerialPort);
return -4;
}

return 0;

}

Edit: Try downloading a driver from http://www.ftdichip.com/Drivers/VCP.htm, as the problem you are describing is most likely a driver or a device issue. Worked for Etan :)

Semaphore Timeout Period

After troubleshooting this for hours and sitting on the phone with my hosting group they discovered that there was a problem with their networking configuration. The solution was made clearer when during my testing one of the VM's suddenly couldn't find the domain, and a simple 'ping' to the IP of each box from the other would occasionally time out. This ruled out DNS entirely. After the hosting group applied the proper configuration on their end the app has been stable and FAST!

Thanks for everyone's help!



Related Topics



Leave a reply



Submit