Results 1 to 5 of 5

Thread: Share serial port between two programs on Windows

  1. #1
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Share serial port between two programs on Windows

    I'm using QExtSerialPort in my application. On Linux, when I open two instances of my program, configured with the same serial port, both instances are able to open the port without problems.

    However, on Windows, the second instance fails to open the port, as the first instance has exclusive access. Is there any way to workaround this limitation (without a virtual serial port if possible), or is it impossible on Windows? Does QSerialDevice behave differently?

    Thanks in advance,
    Ismael

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Share serial port between two programs on Windows

    In Windows, you can not open a single port simultaneously by multiple applications.
    It is impossible, it is a "feature" Windows.

    For these purposes, you can use this solution:
    1. There are some single application(manager/server), which opens / closes the necessary ports by requests from other applications, and returns for this applications a open ports descriptors.
    (ie provides an interface for queries like:
    bool openPort (portName)
    bool closePort (portName or descriptor)
    HANDLE getDescriptor (portName)
    and etc)

    2. There are some applications(clients) that make requests to the server-application with a command to open/close port descriptor and perform I / O through these received descriptors.
    (ie provides an interface for I/O like:
    write(descriptor, ...)
    read(descriptor, ...)
    and etc)

    3. Exchange of data between applications (client-server) or by a QLocalSocket or etc.
    4. Must somehow take into account all the nuances associated with simultaneous access to I / O from clients, or to repeated requests for opening / closing.
    In general, you have to think everything through very well.

    To get a descriptor using libraries QextSerialPort or QSerialDevice need to patch/modify and add a new method of type getDescriptor().

    Library QSerialDevice provide only exclusive access to a port to all platforms. This is done on purpose for typization/unification.

  3. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Share serial port between two programs on Windows

    That is impossible afaik on windows. QSerialDevice cannot open the same port twice either.

    Regards,
    Marc

  4. #4
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Share serial port between two programs on Windows

    Thanks a lot for the quick reply guys,

    Some time ago to solve this I tried to use virtual COM ports, in particular with com0com and hub4com), but sometimes on concurrent accesses the whole thing hanged, the serial port seemed to become sort of stalled, and I had to reboot Windows.

    Do you know of any reliable alternative? Once I implemented the solution kuzulis proposed, for a particular problem, but this time I need the solution to be more transparent to the regular serial port access, so either I use virtual ports (which are no more than kuzulis' solution but with virtual devices involved), or I try to only open the port when I use it and close it right away afterwards (dirty, but implemented it once and worked more or less nicely).

  5. #5

    Default Re: Share serial port between two programs on Windows

    Well, you can use something like Serial Splitter https://www.eltima.com/products/serialsplitter/, which creates virtual serial ports connected with the real one. Then you can open each virtual serial port in your applications.

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 03:38
  2. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 16:51
  3. What is the best way to share data between 2 programs?
    By ModeZt in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2008, 22:23
  4. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 03:05
  5. Serial Port access in Qt
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 18th October 2006, 22:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.