CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2005
    Posts
    4

    Virtual serial port driver in C/C++

    Need to write a driver(virtual serial port driver) in C/C++ which will fit in between the applications and the USB driver, and will try to expose virtual serial ports which the application can communicate with, and internally will pass on data to the USB layer, which will communicate with the USB end of the connector.


    For applications, even though the serial devices are connected through a USB interface in between, the USB interface is transparent – i.e. the applications must behave as if they are communicating with serial devices through COM ports, USB is nowhere in the picture.

  2. #2
    Join Date
    Apr 2005
    Posts
    4

    Re: Virtual serial port driver in C/C++

    There has been many code for this attention.
    If you would like to write it yourself, try to implement all the serial port IOCTL message response code.

  3. #3
    Join Date
    May 2005
    Posts
    2

    Re: Virtual serial port driver in C/C++

    I am doing the same and using Serial example in DDK, (SRC/Kernel/Serial) it will save you lot of work.

  4. #4
    Join Date
    May 2005
    Posts
    1

    Re: Virtual serial port driver in C/C++

    I am just starting out developing a Windows driver that provides support for a custom made PIC board with 3 COM ports. The COM ports are non standard and are very specific to the PCI board I am developing.

    Are there any more code exmples or sources of information for virtual type COM ports?

  5. #5
    Join Date
    Mar 2006
    Posts
    1

    Re: Virtual serial port driver in C/C++

    To anyone who has successfully implemented something like the posts above, could you please point me in the direction of any online resources that were helpful?

    Thanks in advance,
    Macca.

  6. #6
    Join Date
    Feb 2019
    Location
    Sofia
    Posts
    1

    Re: Virtual serial port driver in C/C++

    An old post, but the solutions have not been found, if it is useful to someone, then using the Virtual Serial Port Driver you can....
    To use virtual com driver functionality in C and C++, it’s necessary to dynamically load the DLL file, select the required function, and call them.
    Here’s an example of how you can do this in Visual C++:
    Code:
    typedef bool (stdcall *CreatePairFn)(char *Port1, char *Port2);
    typedef bool (stdcall *DeletePairFn)(char *Port);
    typedef bool (stdcall *DeleteAllFn)(void);
    typedef bool (stdcall *SetStrictBaudrateFn) (char *Port, bool StrictBaudrate);
    typedef bool (stdcall *SetBreakFn) (char *Port, bool bBreak);
    typedef bool (stdcall *QueryBusFn) (void* InBuffer, long sizeInBuffer, void* OutBuffer, long sizeOutBuffer);
    typedef bool (stdcall *SetWiringFn) (char *Port, void *Buffer, long sizeBuffer);
    typedef bool (stdcall *SetAccessListFn) (char *Port, void *Buffer, long sizeBuffer);
     
    typedef bool (stdcall *CreatePairExFn)(char *Port1, char *Port2, char * UserSession);
    typedef bool (stdcall *CreatePairWFn)(WCHAR *Port1, WCHAR *Port2);
    typedef bool (stdcall *CreatePairExWFn)(WCHAR *Port1, WCHAR *Port2, WCHAR * UserSession);
    typedef bool (stdcall *DeletePairWFn)(WCHAR *Port);
    typedef bool (stdcall *SetStrictBaudrateWFn) (WCHAR *Port, bool StrictBaudrate);
    typedef bool (stdcall *SetBreakWFn) (WCHAR *Port, bool bBreak);
    typedef bool (stdcall *SetWiringWFn) (WCHAR *Port, void *Buffer, long sizeBuffer);
    typedef bool (stdcall *SetAccessListWFn) (WCHAR *Port, void *Buffer, long sizeBuffer);
    typedef bool (stdcall *DeletePairExFn)(char *Port, char * UserSession);
    typedef bool (stdcall *DeletePairExWFn)(WCHAR *Port, WCHAR * UserSession);
     
    typedef bool (stdcall *GetUserSessionFn)(char *Session, int &iSize);
    typedef bool (stdcall *GetUserSessionWFn)(WCHAR *Session, int &iSize);
     
    typedef bool (stdcall *SetStrictBaudrateExWFn) (WCHAR *Port, WCHAR * UserSession, bool StrictBaudrate);
    typedef bool (stdcall *SetStrictBaudrateExFn) (char *Port, char * UserSession, bool StrictBaudrate);
    typedef bool (stdcall *SetBreakExWFn) (WCHAR *Port, WCHAR * UserSession, bool bBreak);
    typedef bool (stdcall *SetBreakExFn) (char *Port, char * UserSession, bool bBreak);
    typedef bool (stdcall *SetAccessListExWFn) (WCHAR *Port, WCHAR * WCHAR, void *Buffer, long sizeBuffer);
    typedef bool (stdcall *SetAccessListExFn) (char *Port, char * WCHAR, void *Buffer, long sizeBuffer);
    Code:
    bool CreateVSPair(char *Port1, char *Port2) {
    OSVERSIONINFO VersionInfo;
    HINSTANCE libInst;
    libInst = LoadLibrary(VSPDCTL.DLL);
    if (!libInst)
       return false; /* Couldn't load library */
    /* Substitute the typedefs above for functions other than CreatePairFn */
    CreatePairFn CreatePair=(CreatePairFn)GetProcAddress(libInst, CreatePair);
    if (CreatePair==0) return false; /* Couldn`t find function */
    returnvalue=CreatePair(Port1, Port2); /* For example, Port1 = COM5 and Port2 = COM6 */
    FreeLibrary(libInst);
    return returnvalue;
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured