Author Topic: Comms timeouts  (Read 22332 times)

towlerg

  • Member
  • ***
  • Posts: 24
Comms timeouts
« on: November 05, 2016, 07:31:33 am »
Hi

for reasons that I won't bore you with, I'm trying to use a PC serial port to a PIC, running a super simple data-ack protocol. I'm using the native functions of my compiler and I'm seeing a 20msec. ish delay/latency/timeout between the PIC sending and the PC responding. After wallowing about on several boards I've been guided toward using ReadFile/WriteFile and the comms timeout settings. Having read  the MSDN page on comms timeouts (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363190(v=vs.85).aspx) more times than I care to admit, I still don't understand them. I'm going to try using non-overlapped, just to see what the minimum latency is. What timeout settings will prevent timeouts from having any influence?

George

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Comms timeouts
« Reply #1 on: November 05, 2016, 10:12:52 am »
If you don't want any timeouts, use zero.

towlerg

  • Member
  • ***
  • Posts: 24
Re: Comms timeouts
« Reply #2 on: November 05, 2016, 02:31:46 pm »
Thanks.

Does that apply to ReadIntervalTimeOut, word on the street was that he should be set to %MAXDWORD (ie -1)?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Comms timeouts
« Reply #3 on: November 05, 2016, 08:35:05 pm »
The documentation says:

A value of zero indicates that interval time-outs are not used.

A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, specifies that the read operation is to return immediately with the bytes that have already been received, even if no bytes have been received.

So if you want to wait until data arrives, use zero. If you want to return immediately with whatever data has been received, use MAXDWORD.

towlerg

  • Member
  • ***
  • Posts: 24
Re: Comms timeouts
« Reply #4 on: November 06, 2016, 01:09:49 am »
Thanks for clearing that up. One less variable.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Comms timeouts
« Reply #5 on: November 06, 2016, 12:13:22 pm »
Happy to help.