Thread: VC++/NT serial port access

  1. #1
    Registered User
    Join Date
    Nov 2002

    Unhappy VC++/NT serial port access

    I'm trying to create a little app using MFC to allow strings to be sent and recieved via the serial port. I've got something basic working and am able to test using another PC running hyperterminal.
    What I've got so far uses createfile() to give a handle, setupcomm() to fill a DCB struct and then i use writefile() and readfile() to send and recieve strings; for reading I have a button on my dialog which causes readfile to execute, and I update an edit box with the contents of the buffer. OK.
    Now, what I really want is for incoming characters to trigger an event which automatically causes the edit box to update with the new character (like hyperterminal does.)
    I've got an event mask that looks for EV_RXCHAR and all but can't get this to work.
    Also, I think I need to get a file handle with CreateFile() using the FILE_FLAG_OVERLAPPED option to allow this event driven code to work (asynchronous i/o). This type of file handle worked under WIN ME, but I just get an invalid file handle error from Writefile() according to GetLastError() when I execute under WIN NT. Any one know why this is? On both platforms VC++ compiles without errors or warnings. I presume this is to do with differences in underlying implementations of file handling between WIN ME and NT. Thing is, I need my program to work on both platforms.

    Any help would be greatly appreciated. Feel free to have a look at my website if you would like to know more about the bigger picture of what I'm trying to do.

    Dan Harland

  2. #2
    Registered User
    Join Date
    Nov 2001
    Here is one solution from MSDN.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. Replies: 1
    Last Post: 02-10-2009, 11:02 AM
  3. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM