Serial Port

This is a discussion on Serial Port within the Windows Programming forums, part of the Platform Specific Boards category; Hi Guys, I need to be able to create a program that allows a WinXP machine to communicate with an ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    37

    Serial Port

    Hi Guys,

    I need to be able to create a program that allows a WinXP machine to communicate with an LCD Screen through Com 1 RS 232. I need to program it in ANSI C (GCC compiler) . If I could send characters to the screen I would be very happy.


    Any input would be greatly appreciated.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    37
    I don't qiute understand what you mean?

    I have tried to convert C++ code to C but have been unsuccessful.

    I am mostly having trouble with includes such as bios.h and using termios.


    If anyone could help me from scratch I would delighted.

    The code I have been trying to alter can be found at Crystalfontz: Serial LCD and USB LCD Modules, Graphic LCD displays (Liquid Crystal Displays) and OLED display modules . I have tried modifying both the code from the 635 version and the cf_linux_example version but have had no luck. I have also found various other solutions on the internet which support linux platforms, but can't modify those to work either.

    To get a solution to work in a Win32 terminal would suffice.

    Thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Unix and Linux are VERY different in how they handle serial port. Is the protocol for your LCD panel fairly straight-forward (as in, if you send stuff out the serial port, does it appear immediately, or do you have to do lots of things) - if it's simple, I'd try it out just using HyperTerminal or some such, to see if you have it wired up right, before you start writing code.

    Is there any REAL reason why you need to use C and not C++?

    By the way, I think the link I sent _IS_ a good way to learn how to do this. If that's beyond your abilities, then perhaps you should study C and Windows API a bit more - yes, I know, we all try to do things that are beyond our capabilities, but there is only so far you can reach without failing - there's a balance between stretching, and trying to do something you are completely unqualified for.

    [Having a quick look at the specifications for the serial LCD panel in your link, it seems like it should work to just send text to it].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    37
    I must write the code in C becuase my boss has requested that I do so. I think it is because the device I need to communicate with is only has 8-bytes of memory whereas the original C++ code was written for 16-bytes. I'm not qute sure but all I know is that I HAVE to write it in C.

    Thanks for the link but all the examples are in C++? Would you be able to help me out in converting the C++ code for CreateFile() to an equivelant C function? Or is there much in setting up the port for communication?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Quote Originally Posted by samuelmoneill
    I must write the code in C becuase my boss has requested that I do so. I think it is because the device I need to communicate with is only has 8-bytes of memory whereas the original C++ code was written for 16-bytes. I'm not qute sure but all I know is that I HAVE to write it in C.
    If you find that most of the available relevant material is in C++, then it might be simpler to feedback to your boss for permission to get it done in C++ instead. As for 8 bytes versus 16 bytes: I do not see why that should be a problem. If it were a problem, it could exist in a C version as well.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you be more specific. The code in the MSDN link I gave are definitely not C++ - it is pure ANSI C - it may not be simple, but it's ANSI (or at least very close to ANSI standard).
    Code:
    14/02/1996  11:57             4,569 ABOUT.C
    24/05/1996  06:45             1,974 ABSTRACT.TXT
    20/03/1996  15:47             4,885 ERROR.C
    28/02/1996  11:55            17,078 INIT.C
    29/05/1996  10:26             1,484 MAKEFILE
    20/03/1996  15:24            28,974 MTTTY.C
    24/05/1996  08:24             6,101 MTTTY.H
    13/11/1995  16:40             1,398 MTTTY.ICO
    29/05/1996  09:20             9,559 MTTTY.MAK
    20/03/1996  15:21            16,719 MTTTY.RC
    14/11/1995  08:37             1,398 MTTTY2.ICO
    14/11/1995  08:37             1,398 MTTTY3.ICO
    14/11/1995  08:37             1,398 MTTTY4.ICO
    14/02/1996  12:10             6,118 READER.C
    28/02/1996  11:55             9,064 READSTAT.C
    19/03/1996  17:34             4,961 RESOURCE.H
    29/05/1996  09:38            44,077 SETTINGS.C
    29/05/1996  09:36            22,566 STATUS.C
    24/05/1996  08:31            27,648 TRANSFER.C
    28/02/1996  11:55             4,636 TTYINFO.H
    24/05/1996  08:25            27,704 WRITER.C
    That's the files in the MTTTY example in the link - not a .cpp in sight.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    The link matsp posted is the defacto solution for windows applications. Its really even simpler, all you do is open "COM1:" as the file name and then use ReadFile() adn WriteFile(). There are other function for settign up the baud rate, parity, and stop bits if you dont want the default.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

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, 07:52 AM
  2. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 06:56 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  4. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 01: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, 04:59 PM

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