1

I'm getting the following error when I try and connect to a serial port device. The weird thing is, it connects successfully on some laptops but not others.

System.IO.IOException: The semaphore timeout period has expired.

Please see my code below:

serialcom.RtsEnable = true;
serialcom.PortName = comport;
serialcom.BaudRate = Convert.ToInt32(mainformtarget.connectionsettingsformref.baudratecombobox.Text);
serialcom.Parity = (Parity)Enum.Parse(typeof(Parity), mainformtarget.connectionsettingsformref.paritycombobox.Text);
serialcom.StopBits = (StopBits)Enum.Parse(typeof(StopBits), mainformtarget.connectionsettingsformref.stopbitscombobox.Text);
serialcom.DataBits = 8;
serialcom.Handshake = (Handshake)Enum.Parse(typeof(Handshake), mainformtarget.connectionsettingsformref.handshakecombobox.Text);
serialcom.ReadTimeout = 5000;
serialcom.WriteTimeout = 5000;
serialcom.Open();

Any ideas on what could be causing this?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
wuwu123
  • 19
  • 3
  • What is `comport` ? Does it have to be the same for all computers? Maybe it is used by another process.. – L.B Sep 02 '16 at 22:16
  • 1
    It seems to be a problem with bad drivers. See http://stackoverflow.com/questions/13999439/the-semaphore-timeout-period-has-expired – Cecilio Pardo Sep 02 '16 at 22:17
  • Check in device manager that the com port is shown and working. After some changes, sometime one has to reboot the computer (like updating port name). – Phil1970 Sep 02 '16 at 22:25
  • Thanks for the link @Cecilio Pardo. Problem is I can't ask a user to follow all those steps, I need to try and find a fix in my code. – wuwu123 Sep 04 '16 at 16:47
  • @L.B The code is in a loop which connects to all COM ports in turn until it finds the right one. 'comport' is the current name of the COM port in the loop. – wuwu123 Sep 04 '16 at 16:47
  • I'm afraid you can't fix a buggy driver from your code. – Cecilio Pardo Sep 05 '16 at 17:54
  • As a work around I ask the user to manually select a com port. This will have to do for now. – wuwu123 Sep 09 '16 at 15:28

0 Answers0