Menu

com0com with OVERLAPPED I/O

Help
2008-11-28
2013-05-20
  • Dominik Tomczak

    Dominik Tomczak - 2008-11-28

    Hello

    I have created port COM5 (CNCA0) with com0com. My application that uses this virtual COM5 uses Overlapped I/O to access the port. When I send only 1B from my app to the com0com, the application that is bound to the paired port (named SRV_COM5 == CNCB0) receives 1024B buffer containig the character that was sent. I use Overlapped I/O on the paired port too. Below is the log from portmon application (from Sysinternals). The log is from COM5 (CNCA0) - I send only 1B to the port, the portmon show many IRP_MJ_WRITE requests to COM5.

    Any ideas why this error occurs? Any solution?

    Thanks

    Dominik

    0.00001097    Trtest.exe    IOCTL_SERIAL_GET_COMMSTATUS    serial2serial14    SUCCESS       
    0.00000955    Trtest.exe    IOCTL_SERIAL_GET_COMMSTATUS    serial2serial14    SUCCESS       
    0.00000286    Trtest.exe    IOCTL_SERIAL_GET_COMMSTATUS    serial2serial14    SUCCESS       
    0.00000919    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000192    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000150    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000167    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000271    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000123    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000184    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000141    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000193    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000126    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000193    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000137    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000124    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000140    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000130    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000140    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000146    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000134    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000152    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000141    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000122    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000137    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000130    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000146    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000138    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000131    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000149    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000124    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000134    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000127    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000163    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000142    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000144    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000127    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000155    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000144    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000123    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000133    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000128    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000138    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000138    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000142    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000132    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000144    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000125    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000203    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000141    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000123    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000136    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000140    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000131    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000146    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000137    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000145    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000126    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000143    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000124    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000133    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000149    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000123    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000139    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000140    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    
    0.00000127    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
    0.00000154    Trtest.exe    IRP_MJ_WRITE    serial2serial14    SUCCESS    Length 1: 31    

     
    • Dominik Tomczak

      Dominik Tomczak - 2008-11-28

      Just additional log from portmon showing how the application initializes COM5 (CNCA0). I suspect the problem could be in lack of implementation of handling RTS,DTR control?

      0.00000463    Trtest.exe    IRP_MJ_CREATE    serial2serial14    SUCCESS    Options: Open    
      0.00000175    Trtest.exe    IOCTL_SERIAL_GET_BAUD_RATE    serial2serial14    SUCCESS       
      0.00000098    Trtest.exe    IOCTL_SERIAL_GET_LINE_CONTROL    serial2serial14    SUCCESS       
      0.00000105    Trtest.exe    IOCTL_SERIAL_GET_CHARS    serial2serial14    SUCCESS       
      0.00000097    Trtest.exe    IOCTL_SERIAL_GET_HANDFLOW    serial2serial14    SUCCESS       
      0.00000101    Trtest.exe    IOCTL_SERIAL_SET_BAUD_RATE    serial2serial14    SUCCESS    Rate: 4800   
      0.00000102    Trtest.exe    IOCTL_SERIAL_SET_RTS    serial2serial14    SUCCESS       
      0.00000104    Trtest.exe    IOCTL_SERIAL_SET_DTR    serial2serial14    SUCCESS       
      0.00000115    Trtest.exe    IOCTL_SERIAL_SET_LINE_CONTROL    serial2serial14    SUCCESS    StopBits: 1 Parity: NONE WordLength: 8   
      0.00000095    Trtest.exe    IOCTL_SERIAL_SET_CHAR    serial2serial14    SUCCESS    EOF:0 ERR:0 BRK:0 EVT:0 XON:0 XOFF:0   
      0.00000126    Trtest.exe    IOCTL_SERIAL_SET_HANDFLOW    serial2serial14    SUCCESS    Shake:1 Replace:80000040 XonLimit:0 XoffLimit:0   
      0.00000114    Trtest.exe    IOCTL_SERIAL_SET_TIMEOUTS    serial2serial14    SUCCESS    RI:100 RM:0 RC:0 WM:3 WC:5000   
      0.00000128    Trtest.exe    IOCTL_SERIAL_PURGE    serial2serial14    SUCCESS    Purge: TXABORT RXABORT TXCLEAR RXCLEAR   
      0.00000278    Trtest.exe    IOCTL_SERIAL_SET_QUEUE_SIZE    serial2serial14    SUCCESS    InSize: 131072 OutSize: 131072   
      0.00000157    Trtest.exe    IOCTL_SERIAL_SET_WAIT_MASK    serial2serial14    SUCCESS    Mask: RXCHAR TXEMPTY CTS DSR ERR    
      0.00000000    Trtest.exe    IRP_MJ_READ    serial2serial14        Length 512   
      13.22348167    Trtest.exe    IOCTL_SERIAL_WAIT_ON_MASK    serial2serial14    SUCCESS       
      0.00000121    Trtest.exe    IOCTL_SERIAL_GET_MODEMSTATUS    serial2serial14    SUCCESS       
      0.00000109    Trtest.exe    IOCTL_SERIAL_GET_MODEMSTATUS    serial2serial14    SUCCESS       
      0.00000125    Trtest.exe    IOCTL_SERIAL_SET_RTS    serial2serial14    SUCCESS       
      0.00000140    Trtest.exe    IOCTL_SERIAL_CLR_DTR    serial2serial14    SUCCESS       
      0.00000130    Trtest.exe    IOCTL_SERIAL_GET_COMMSTATUS    serial2serial14    SUCCESS       

       
    • Vyacheslav Frolov

      The portmon shows many IRP_MJ_WRITE requests to COM5
      if your application does many writings or incorrectly
      uses Overlapped I/O.
      Possible I could be help you if you send me the source
      of application.

       
      • Dominik Tomczak

        Dominik Tomczak - 2008-12-01

        Hello

        Thanks for fast response. Since the application that writes to COM5 is a 3rd party tool, I'll have to organize source code. I'll inform you as soon as I get this. I guess, they implement async I/O incorrectly, but I need to be sure since the tool must work with com0com.

        Another question I'd like to ask is: I need to open the paired port only when the real application opens the provided virtual COM port (paired port is hidden by me and does not appear in enumerator). I implement my own COM to TCP redirector and I need to open the TCP connection only when the application opens the COM port. Could you help me what is the best way to achieve that?

        Thanks
        Dominik

         
    • Vyacheslav Frolov

      > I need to open the TCP connection only when the
      > application opens the COM port

      Wire OPEN and DCD pins and open the TCP connection
      when DCD state is ON.

       
      • Dominik Tomczak

        Dominik Tomczak - 2008-12-02

        Hello

        Does it mean that I have to pool GetCommStatus? Which parameter from DCB structure is mentioned DCD?
        Or can I use for above WaitCommEvent? If so, then which of its parameters (EV_BREAK, EV_CTS, EV_DSR, EV_ERR, EV_RING, EV_RLSD, EV_RXCHAR, EV_RXFLAG, EV_TXEMPTY) should I listen for?

        Generally speaking, pooling for COM port state is not a good solution for me because if an application opens the COM port, my service trying test DCD may detect this fact with a timeout (this depend on the pooling timeout). If the application is fact, it may send data after opening the COM while my pooling timeout is elapsing. In that case, as I understand, data is not buffered an is lost within the driver?

        Please specififyw what is DCD and how to monitor it?

        Thank you very much Vyacheslav.

        Dominik

         
    • Vyacheslav Frolov

      The DCD state can be monitored by

        SetCommMask(EV_RLSD)/WaitCommEvent/GetCommModemStatus

      or by

        DeviceIoControl(IOCTL_SERIAL_LSRMST_INSERT)/ReadFile

      Examples of using both methods can be found in the CVS
      version of hub4com (serial and escparse modules).

       
      • Dominik Tomczak

        Dominik Tomczak - 2008-12-02

        Thanks.

        This is exactly what I was looking for. I'll check this today in th afternoon.

        Thanks again for great work.
        Dominik

         

Log in to post a comment.