question

GetacCorin-3623 avatar image
0 Votes"
GetacCorin-3623 asked DoronHolan answered

About virtual serial driver sample v2 to support application event handle?

I used the below to create virtual port

https://docs.microsoft.com/en-us/samples/microsoft/windows-driver-samples/virtual-serial-driver-sample-v2/

And I could use application to polling data from this virtual port,

However, because Application also can be use interrupt mode to get virtual port data, but this simple code looks can not support this.

I have see below "PostEvent" and "wdfdevicepostevent", it looks can be solve problem. but I don't know how to use them, does anyone know how to add below to support application interrupt mode, eg, C# serial port component use event handle to get virtual port notify from Virtual serial driver, thanks!

https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wudfddi/nf-wudfddi-iwdfdevice-postevent

https://docs.microsoft.com/zh-tw/windows-hardware/drivers/ddi/wdfdevice/nf-wdfdevice-wdfdevicepostevent

windows-hardware
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you clarify what you mean by interrupt mode? If you want to move to async io, you don't need to change the driver. Rather, you need open the file hanle to the serial port with FILE_FLAG_OVERLAPPED and then pass in a valid OVERLAPPED for each IO API call. WdfDevicePostEvent (and its UMDF equivalent) are not for I/O, but for one off custom event notifications. Make sure that you are using UMDF2 as the basis for your vitual serial port, not UMDF1. Start with https://github.com/microsoft/Windows-driver-samples/tree/master/serial/VirtualSerial2

0 Votes 0 ·

Thank you so much your reply -

About interrupt mode, I mean I use C# and use Serial Component and create an event handle as below, I could not any thing from UMDF2 Virtual Serial, only way is using ReadLine to get string from Virtual Serial Port. So I just want to know how I can support this kind of application use event handle behavior.


![120686-image.png][1]


0 Votes 0 ·
image.png (62.8 KiB)

I can use readline in C# to get string from UMDF2 Virtual Serial, but could not use EventHandler to get data.


120735-image.png


0 Votes 0 ·
image.png (53.6 KiB)

1 Answer

DoronHolan avatar image
0 Votes"
DoronHolan answered

I looked into the SerialPort class and how it invokes the read callback. It relies on the win32 API WaitCommMask(EV_RXCHAR | EV_RXFLAG), which in turn calls into the serial driver with IOCTL_SERIAL_WAIT_ON_MASK. If you look at the implementation of IOCTL_SERIAL_WAIT_ON_MASK in the virtual serial port driver sample, it only queues the request, but never completes the request (other than if another one is sent) until the handle is closed. If you have underlying hardware that can indicate receive chars are present (see the serial.sys WDK sample that supports a 16550 UART for an example of how to process the request)) and sucessfully complete the WAIT_ON_MASK IOCTL when indicated, the C# callback should be invoked.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.