Virtual Serial port with UMDF / Timeout using .net ports write() function

Hi,

After connecting to the virtual port using .net ports, when I use its write() function, the data is received fine in the driver, however the function throws timeout exception.

I tried to change the timeout but that did not help.

when using win API WriteFile in C++ , there is no such problem.

the same happens with the serial port example comes with WDF 7000.0.

Thanks…

You can get the source for the BCL for free from microsoft. Get it and see why it times out

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@gmail.com
Sent: Wednesday, May 06, 2009 4:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Virtual Serial port with UMDF / Timeout using .net ports write() function

Hi,

After connecting to the virtual port using .net ports, when I use its write() function, the data is received fine in the driver, however the function throws timeout exception.

I tried to change the timeout but that did not help.

when using win API WriteFile in C++ , there is no such problem.

the same happens with the serial port example comes with WDF 7000.0.

Thanks…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Igal N wrote:

the same happens with the serial port example comes with
WDF 7000.0.

Interesting that it also happens with the supplied WDF serial driver. Maybe the author of mscomm32.ocx wrote this BCL code too :slight_smile:

Thanks Doron, I found why the it throws the timeout:

.net’s write() function is using CreateFile and WriteFile Async like this :

CreateFile(“\\.\” + portName,
NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
IntPtr.Zero, // no security attributes
UnsafeNativeMethods.OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED,
IntPtr.Zero // hTemplate must be NULL for comm devices
);

WriteFile(_handle, p + offset, count, IntPtr.Zero, overlapped);

when I used those I had NULL instead of the FILE_FLAG_OVERLAPPED.

OK now i know why that happens, the question is how to fix it ? it looks like the driver is working fine with the async WriteFile, but the function returns an error for some reason.