CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2008
    Posts
    98

    Can I read data simultaneously from same serial port?

    Now one process has already open the serial port COMx to read data, then if I use ::CreateFile to open it, it would fail.
    So I would like to know whether I can read data simultaneously(open serial port) with two process from same serial port or not.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Can I read data simultaneously from same serial port?

    No. Comports can only be used by 1 filehandle at a time, and you can't share filehandles between programs.

  3. #3
    Join Date
    Jan 2008
    Posts
    98

    Re: Can I read data simultaneously from same serial port?

    I heard about may use *virtual port*
    I google "virtual port", then it's all serial port simulator,
    Does anybody knows *virtual port* stuff?
    I just need to read data via two processes!

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Can I read data simultaneously from same serial port?

    Processes or applications ? If you mean 2 processes within 1 application then you CAN share the filehandle, but you will need to add semaphores/mutexes for process synchronization.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Can I read data simultaneously from same serial port?

    Quote Originally Posted by fantasy1215 View Post
    So I would like to know whether I can read data simultaneously(open serial port) with two process from same serial port or not.
    Could you explain why you need it? Perhaps, we could suggest you some workaround?
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2008
    Posts
    98

    Re: Can I read data simultaneously from same serial port?

    Could you explain why you need it? Perhaps, we could suggest you some workaround?
    One process(I have not owned the code) existing in my application open the serial port COMx to read data(I can ensure that the process don't write data to COMx), Now I need to open COMx also to read data.
    So can you suggest some wordaround?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Can I read data simultaneously from same serial port?

    Well, your description is very unclear: what kind of data to be read from COMx, what do you mean by this process YOU "have not owned the code", what do you need the data from COMx for, ...?

    So, without knowing all these thing I can suggest you very simple and straightforward "woraround": don't use this process you "have not owned the code" and rather write your own code to read from COMx. See the code example in Serial Port essay.
    Victor Nijegorodov

  8. #8
    Join Date
    Mar 2004
    Location
    KL, Malaysia
    Posts
    63

    Re: Can I read data simultaneously from same serial port?

    Quote Originally Posted by fantasy1215 View Post
    One process(I have not owned the code) existing in my application open the serial port COMx to read data(I can ensure that the process don't write data to COMx), Now I need to open COMx also to read data.
    So can you suggest some wordaround?
    One com port can only serve one connection at a time. Unless you have ways for the 3rd party process to connect/release the port as you wish, there is no way for your own process to gain the port connection.

    The only way I can think of is to install a new com port (new hardware), then tab pin 2,3,5 of existing com port (with extra wires) over to pin 2,3,5 of new port, and have your own process connect to new com port. That way, your own process will receive the same data simultaneously.

    Regards
    Kevin Choong
    Last edited by ckweius; April 6th, 2009 at 03:27 AM.

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