Serial port programming

This is a discussion on Serial port programming within the C Programming forums, part of the General Programming Boards category; I want to learn how to send and receive data using the serial (com) port on my computer, but i ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    8

    Question Serial port programming

    I want to learn how to send and receive data using the serial (com) port on my computer, but i don't know of any tutorials or anything, so if any of you know where to find tutorials or anything about that, can you please tell me?

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Below is a list of the most commonly used functions in doing COM programming (AFAIK), which you can look up on MSDN and/or Google:

    HANDLE
    CreateFile(...)
    WriteFile(...)
    ReadFile(...)

    Now, to actually do the programming is up to you, and it also depends on if you want to do multithreading in it, or not. Read up on those, and you should be set (HANDLE is a variable type (like int, char, float, etc...), but it's still on MSDN).

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're assuming they're doing Windows programming... Though I would also echo the Google suggestion.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Apr 2004
    Posts
    8
    MSDN Says that i can NOT use any reserved device names as a filename, e.g. COM3 (then one I will be programming on)...
    I don't know if i understand this completely.

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Quote Originally Posted by kristoffer
    MSDN Says that i can NOT use any reserved device names as a filename, e.g. COM3 (then one I will be programming on)...
    I don't know if i understand this completely.
    The filename for both WriteFile and ReadFile would be "COM#" (in quotes), where # is the com port you want to connect to.

  6. #6
    Registered User
    Join Date
    Apr 2004
    Posts
    8
    So this means I can use it then...

    Anyway, thanks for the help

  7. #7
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by kristoffer
    So this means I can use it then...
    In this context (serial comms) yes, you actually must use it.
    Emmanuel Delahaye

    "C is a sharp tool"

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    1

    Smile

    There is a really good book by Paul Bergsman called "Controlling the World With Your PC" that deals with PC serial communication. Lots of C, Pascal, and Basic coding examples.

    Good Luck!

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    and incase you want to avoid windows.h you can always use this: http://www.seetron.com/c_tip2.htm
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    I want to learn how to send and receive data using the serial (com) port on my computer, but i don't know of any tutorials or anything, so if any of you know where to find tutorials or anything about that, can you please tell me?
    Mark Nelson (a Cisco programmer) came out with a really great book on serial communications (with a focus on the Window environment). Lots of great code examples and plenty of solid theory, too. Highly recommended.



    ITSA
    Socket Library!

  11. #11
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I were unable to find this book on amazon. Tell me, does it also explains about usb ports programming?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  12. #12
    Registered User
    Join Date
    Jun 2004
    Posts
    6
    In windows, there are two ways of doing so.
    1. use bioscom built-in function in <bios.h> provided by all standard compilers
    2. there are 10 registers available for the purpose. u will have to control them. that is u will have to understand how the data transfer takes place and accordingly u will have to set/reset appropriate bits (DTR,DSR,etc) in those registers. theres a book "IBM PC CLONES" available in market, it can help u out.

    I had handled project on PC-PC communication earlier using second method. I can provide u with code in case u need it.

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    bios.h is only usable in dos based compilers. Modern compilers do not have it and modern operating systems will not work with it as you can not take direct control of ports like that anymore.

  14. #14
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Sebastiani
    Mark Nelson (a Cisco programmer) came out with a really great book on serial communications (with a focus on the Window environment). Lots of great code examples and plenty of solid theory, too. Highly recommended.
    Quote Originally Posted by Devil Panther
    I were unable to find this book on amazon. Tell me, does it also explains about usb ports programming?
    http://www.amazon.com/exec/obidos/tg...glance&s=books?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  15. #15
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    ...tell me, does it also explains about usb ports programming?
    No, just serial ports.



    ITSA
    Socket Library!

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. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 03:59 PM

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