Recent

Author Topic: Very slow response on Windows 7 - comments invited  (Read 4693 times)

Dytlyf

  • Newbie
  • Posts: 6
Very slow response on Windows 7 - comments invited
« on: February 27, 2015, 10:02:17 am »
Hi everyone,

I experienced a strange problem when trying to test a Free Pascal program that I'm developing for a client who uses Windows 7. I'll briefly explain the setup.

I'm developing the program on Ubuntu 14.04 with Lazarus 1.2.0 and FPC 2.6.2. There are two particular functions that can be used to test the program on different platforms: a serial connection using Synaser, and some text that is displayed for a short time using a TTimer component. I'm doing this on a reasonably new 64-bit HP laptop.

The tests I do include a serial port time-out error test which displays the word ERROR in a text box when the serial connection fails, and flashing a word for 100 ms using the timer. This is the code segment for the serial connection:

Code: [Select]
serialConnection := TBlockSerial.Create;
  portStr := PortNameComboBox.Text;
  //serialConnection.Connect('/dev/ttyUSB0'); // for testing on Linux
  serialConnection.Connect(portStr); // for Windows
  Sleep(500);
  serialConnection.Config(115200, 8, 'N', 1, False, False);
  Sleep(100);
  serialConnection.SendString('AT' + Chr($0D));
  Sleep(10);
  replyStr := serialConnection.Recvstring(2000);
 

As you can see, there is a 2 second time-out after which the word ERROR is displayed when a reply from the attached device is not received.

Now, first of all I must say this: the program works perfectly on Linux. And when I recompile in Windows XP, it also works perfectly. When I say 'perfectly' I mean that when I simulate a broken physical serial connection by simply unplugging the USB-to-serial adapter, I consistently get the ERROR message after 2 seconds. And the word that is flashed appears briefly enough to guess that it is up for about 100 ms. The exact time is not too important as long as it is short.

But then I sent the test program to my client on the other side of the world, and it doesn't work. We set up a skype and teamviewer session so that I could guide her through the process. First, we found that the ERROR message sometimes takes several seconds to appear, and at other times it does not appear at all. The test word is similarly affected - it comes up and stays on for a long time, sometimes not disappearing at all.

So, this all makes me suspect that the problem is on the client's laptop. I suggested that she check her computer for unnecessary processes running in the background and to make sure that her anti-virus program is not a cause. I also suspect that the fact that we had both skype and teamviewer running, as well as her browser and email and what have you, slowed her computer down. But she assures me that it is new and clean and doesn't need defragmenting and whatever. So, what am I to do?

Any comments and ideas would be welcome.

Thanks in advance.


engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Very slow response on Windows 7 - comments invited
« Reply #1 on: February 27, 2015, 02:59:54 pm »
There is a wait for 30 seconds in the synaser source code when you call SendString (which calls SendBuffer):
Code: [Select]
  if not WriteFile(FHandle, Buffer^, Length, DWord(Result), @Overlapped) then
    y := GetLastError;
  if y = ERROR_IO_PENDING then
  begin
    x := WaitForSingleObject(FHandle, FDeadlockTimeout);

FDeadlockTimeout is 30 seconds by default. You can reduce it using DeadlockTimeout property. You  might want to write serialConnection.LastErrorDesc after each step to some log file including time stamp and action.

 

TinyPortal © 2005-2018