RS422 Serial Communication Codes in C++

Discussion in 'C++' started by fulltime, Aug 1, 2007.

  1. fulltime

    fulltime Guest

    Hi all,

    I installed a PCI bus interface board with 2 RS422 com ports on it. I
    am attempting to transfer data between these 2 com ports. (for eg. com
    3 send data to com 4)

    The pseudo code of my main program is as follows:

    1. Configure the 2 ports
    2. Open both ports
    3. Call sendByte () for com 3 to send data out.
    4. Call readByte () for com 4 to read in data.
    5. Close both ports

    However, the whole program hangs inside the readByte () which is
    listed below.

    ///////////////////////////////////////////////////////
    // Function name : CSerialComm::ReadByte
    // Description : Reads a byte from the selected port
    // Return type : BOOL
    // Argument : BYTE& by
    ///////////////////////////////////////////////////////
    BOOL CSerialComm::ReadByte(BYTE& by)
    {
    BYTE byResByte;
    by=0;

    DWORD dwBytesTxD=0;

    if (ReadFile (m_hComm, &byResByte, 1, &dwBytesTxD, 0))
    {
    if (dwBytesTxD == 1)
    {
    by=byResByte;
    return TRUE;
    }
    }
    return FALSE;
    }

    /
    =========================================================================

    Can anyone provide me with some advice?

    Since the data is first sent out via com3, My intial guess is that by
    the time the receiver wants to read in the data, no more data exist
    for it to be read in..

    Thks alot for whatever advice u may provide.
    FT
     
    fulltime, Aug 1, 2007
    #1
    1. Advertising

  2. * fulltime:
    > [off topic]


    Even though your question is off-topic in this group, please don't feel
    unwelcome. Spend some time reading posted articles to familiarize
    yourself with the group, read the FAQ. The FAQ also gives good advice
    about relevant groups where you can post your Windows programming
    question (the only advice relevant in this group, is to use C++ 'bool',
    'true' and 'false' rather than macros for completely different purpose).

    C U L8R,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Aug 1, 2007
    #2
    1. Advertising

  3. fulltime

    fulltime Guest

    so sorry that i posted on the wrong group. :(

    I was trying to search for the FAQ, as to which group shld i post my
    queries on. Can any kind soul pls advise me? thks

    FT
     
    fulltime, Aug 1, 2007
    #3
  4. fulltime

    Shadowman Guest

    fulltime wrote:
    > so sorry that i posted on the wrong group. :(
    >
    > I was trying to search for the FAQ, as to which group shld i post my
    > queries on. Can any kind soul pls advise me? thks
    >
    >

    The FAQ:
    http://www.parashift.com/c -faq-lite/

    As for a group suggestion, perhaps start at
    comp.os.ms-windows.programmer.win32 ?


    --
    SM
    rot13 for email
     
    Shadowman, Aug 1, 2007
    #4
  5. fulltime

    Jim Langston Guest

    "fulltime" <> wrote in message
    news:...
    > Hi all,
    >
    > I installed a PCI bus interface board with 2 RS422 com ports on it. I
    > am attempting to transfer data between these 2 com ports. (for eg. com
    > 3 send data to com 4)
    >
    > The pseudo code of my main program is as follows:
    >
    > 1. Configure the 2 ports
    > 2. Open both ports
    > 3. Call sendByte () for com 3 to send data out.
    > 4. Call readByte () for com 4 to read in data.
    > 5. Close both ports
    >
    > However, the whole program hangs inside the readByte () which is
    > listed below.
    >
    > ///////////////////////////////////////////////////////
    > // Function name : CSerialComm::ReadByte
    > // Description : Reads a byte from the selected port
    > // Return type : BOOL
    > // Argument : BYTE& by
    > ///////////////////////////////////////////////////////
    > BOOL CSerialComm::ReadByte(BYTE& by)
    > {
    > BYTE byResByte;
    > by=0;
    >
    > DWORD dwBytesTxD=0;
    >
    > if (ReadFile (m_hComm, &byResByte, 1, &dwBytesTxD, 0))
    > {
    > if (dwBytesTxD == 1)
    > {
    > by=byResByte;
    > return TRUE;
    > }
    > }
    > return FALSE;
    > }
    >
    > /
    > =========================================================================
    >
    > Can anyone provide me with some advice?
    >
    > Since the data is first sent out via com3, My intial guess is that by
    > the time the receiver wants to read in the data, no more data exist
    > for it to be read in..


    This is mostly OT as it is OS specific, but OT in the case of why it is
    hanging. Apparently ReadFile is "blocking". Blocking means it won't return
    until data is ready to be read. The solution, however, is OT because you
    need to find out in your OS how to determine if data is ready to be read.
     
    Jim Langston, Aug 4, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. petrus bitbyter

    Re: RS422 to I2C Converter

    petrus bitbyter, Jun 28, 2003, in forum: VHDL
    Replies:
    0
    Views:
    2,727
    petrus bitbyter
    Jun 28, 2003
  2. Niv
    Replies:
    1
    Views:
    3,432
  3. Greg  --
    Replies:
    4
    Views:
    2,241
  4. Replies:
    2
    Views:
    2,933
    Malcolm
    Aug 20, 2005
  5. Allen
    Replies:
    1
    Views:
    676
    Mark Rae [MVP]
    Dec 3, 2007
Loading...

Share This Page