Thread: Serial Communication in C++

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    56

    Serial Communication in C++

    I am having trouble reading data through serial communication in C++. Some of the data read in is being cutoff. It reads all the data fine in hyperterminal but not in C++. Can anyone help?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    what compiler and operating system? you probably need to implement some type of interrupt driven read function. How to do that depends on os and sometimes compiler.

    Your program is losing data because it probably is not reading the UARTs fast enough and the UART's buffer gets overwritten with new incoming data.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    Everything is written in visual C++. I am communicating it to a PIC device. I am using a Visual C++ compiler and windows xp. I know the data is there because the PIC is able to display all the information on the hyperterminal but it's not displaying all the information on my C++ GUI display.
    Last edited by NewGuy100; 03-12-2006 at 02:20 PM.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Add breakpoints especially within the calls to IO API.

    Kuphryn

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    Whats the best method for serial communication in MFC and Visual C++?

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    To my knowledge MFC doesn't directly support serial communications functions -- probably a lot easier to use win32 api functions. You can set up a callback function which win32 will call when something arrives at the UART, that way you don't miss data. And I put that in a different thread.

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    Can you direct me to where I can find examples of this? I am very new to visual C++!

    Thank You,

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    I have attach the following files. I am having trouble reading my serial port in main from the commdlg.

    I also used the MSCOMM with the GetInput(), but it keeps cutting off some of the data I am reading in through the serial port!
    Last edited by NewGuy100; 04-13-2006 at 10:17 AM.

  9. #9
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    Whats the difference between using MSCOMM or HANDLE for serial communication? I am kind of confused on this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Duplex communication thro serial port
    By Priyachu in forum Linux Programming
    Replies: 1
    Last Post: 05-30-2009, 04:03 AM
  2. Serial port Communication
    By vin_pll in forum C++ Programming
    Replies: 23
    Last Post: 01-07-2009, 09:32 AM
  3. Serial pot communication through c program
    By vin_pll in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2009, 12:52 PM
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  5. Serial communication packets
    By Roaring_Tiger in forum C Programming
    Replies: 3
    Last Post: 04-26-2003, 08:33 AM