serial port read

This is a discussion on serial port read within the C++ Programming forums, part of the General Programming Boards category; Hi, I have not been able to find an answer, but I am sure it is here some where. I ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    serial port read

    Hi,
    I have not been able to find an answer, but I am sure it is here some where. I have tried http://www.iftools.com/ctb.en.html and http://www.codeproject.com/system/serial.asp plus I have read every thing else that I could find.

    I am running WIN98 using wx-devcpp. I can not even get the above code samples to compile. Found the above links at the wx-devcpp discussion board.

    Problem: I have a pic chip sending data to the pc via serial port, this works as I can recieve with hyper-terminal. How do I set up a C++ program to recieve this data ?? I would like to have the data display into a text box so it can be saved to a database.

    Thank you.

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    check msdn:
    http://msdn.microsoft.com/library/de...nfunctions.asp

    it has all the functions

    Use createFile to get a handle to the serial port and then treat it like a file with read and write.
    Amish

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    4
    Thank you, now it looks like I am getting somewhere. If I can figure out what
    "544 C:\DEV-CPP\include\Winbase.h `DWORD' does not name a type " means.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    I think it comes from windows.h. Try to include that. Not too sure though
    Amish

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    4
    Changed <Winbase.h> to <windows.h> and now this will compile---
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    HANDLE pic;
    main()
    {
    pic = CreateFile( "COM1",     // address of name of the communications device
          GENERIC_READ | GENERIC_WRITE, // access (read-write) mode
          0,                  // share mode
          NULL,               // address of security descriptor
          OPEN_EXISTING,      // how to create
          0,                  // file attributes
          NULL                // handle of file with attributes to copy
       );
    }
    Have not had time to try in full program yet, but now I have a starting point.

    Thank you for your help!!!

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Don't forget that when you call ReadFile on a serial port to always check the number of bytes that were actually read as this can be less then the number requested.

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    4
    I am taking notes.

    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Serial Port Questions
    By valaris in forum Tech Board
    Replies: 2
    Last Post: 05-22-2009, 08:26 AM
  2. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  3. Serial Port Issues (again!)
    By HalNineThousand in forum Linux Programming
    Replies: 6
    Last Post: 04-09-2008, 08:26 PM
  4. HELP with storing serial port data into txt file
    By inmaterichard in forum C Programming
    Replies: 2
    Last Post: 04-02-2008, 02:20 AM
  5. Serial port read..can someone tell me..
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-27-2002, 08:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21