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.
About virtual serial driver sample v2 to support application event handle?
ChiuChiaChang
1
Reputation point
I used the below to create virtual port
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!