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

ChiuChiaChang 1 Reputation point
2021-08-03T03:42:24.29+00:00

I used the below to create virtual port

https://learn.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://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wudfddi/nf-wudfddi-iwdfdevice-postevent

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

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,553 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Doron Holan 1,801 Reputation points
    2021-08-09T21:34:51.467+00:00

    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.

    0 comments No comments