Programming the RS232 port in C++

This is a discussion on Programming the RS232 port in C++ within the C++ Programming forums, part of the General Programming Boards category; Hi, I need to send ascii strings to a device via a rs232 port. Is it possible to just set ...

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

    Programming the RS232 port in C++

    Hi, I need to send ascii strings to a device via a rs232 port.

    Is it possible to just set up the port, and send the string, assuming no hand shaking is needed?


    I browsed through alot of codes and they are all so complicated and most don't compile which I don't know why.


    Thanks very much. I am not proficient in using the C/C++ language for accessing serial ports hope someone can help me out.

    Thanks!
    Nick

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    Please start by telling us which OS and Compiler you have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    4

    Compiler and OS

    Hi, I'm using Windows XP and Visual C++ 2005 Express


    Thank you.
    Nick

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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.*

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    4

    Error

    Hi, i tried the following codes but I have this error:

    C:/Dev-Cpp/thisistestingonly.cpp: In function `int main()':
    C:/Dev-Cpp/thisistestingonly.cpp:81: invalid conversion from `int*' to `DWORD*'

    code:
    status = WriteFile(hCom,
    &sdata,
    length,
    &bytes_written,
    NULL);


    Can anyone help with this? I have no idea what is wrong.

    Thanks
    Nick

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    Seems pretty obvious to me.
    One of the parameters you have a & in front of should have been declared as a DWORD and not as an int.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Here's a clue ...

    [code]
    BOOL WriteFile( HANDLE hFile,
    LPCVOID lpBuffer,
    DWORD nNumberOfBytesToWrite,
    LPDWORD lpNumberOfBytesWritten,
    LPOVERLAPPED lpOverlapped
    );
    ]/code]

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    4

    Thanks all!

    Thanks all!, I appear to have results now, jus that I have yet the opportunity to use it on the equipment.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. codes for com port Rs232 in serial communication
    By justinwandji in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2009, 01:33 AM
  2. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  3. Communication using RS232 port
    By edesign in forum C Programming
    Replies: 27
    Last Post: 03-26-2008, 03:06 AM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. Send and Recive Information through the serial Port RS232
    By amigoloko in forum C# Programming
    Replies: 4
    Last Post: 04-14-2006, 12:34 PM

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