problem sending code via rs232

Discussion in 'C++' started by Martin Petzold, Apr 12, 2004.

  1. Hi,
    i always resolve an "arrow up" instead an "A" when i do this (snipped!):

    BYTE Byte;

    Byte = 0x41;
    PortWrite((BYTE)(&Byte));

    BOOL PortWrite (BYTE Byte)
    {
    WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL);
    return TRUE;
    }

    what is the problem?

    thx martin
     
    Martin Petzold, Apr 12, 2004
    #1
    1. Advertising

  2. resolve = receive
     
    Martin Petzold, Apr 12, 2004
    #2
    1. Advertising

  3. * Martin Petzold <> schriebt:
    >


    This is off-topic in [comp.lang.c++].

    Perhaps try [comp.os.ms-windows.programmer.win32]?

    See the FAQ for some other possibilities & posting guidelines.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Apr 12, 2004
    #3
  4. Martin Petzold <> spoke thus:

    > i always resolve an "arrow up" instead an "A" when i do this (snipped!):


    What Mr. Steinbach said, and also never multi-post again.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Apr 12, 2004
    #4
  5. Martin Petzold wrote:

    >
    > I always resolve an "arrow up" instead an "A" when i do this (snipped!):
    >
    > BYTE Byte;
    >
    > Byte = 0x41;
    > PortWrite((BYTE)(&Byte));
    >
    > BOOL PortWrite (BYTE Byte) {
    > WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL);
    > return TRUE;
    > }
    >
    > what is the problem?


    You don't know what you are doing.

    It appears that you are attempting to write the address of a BYTE
    which contains the value 0x41.
     
    E. Robert Tisdale, Apr 12, 2004
    #5
  6. Martin Petzold

    David Harmon Guest

    On Mon, 12 Apr 2004 18:14:56 GMT in comp.lang.c++, (Alf
    P. Steinbach) wrote,
    >* Martin Petzold <> schriebt:
    >>

    >
    >This is off-topic in [comp.lang.c++].


    No it's not. The difference between a char, and the address of a char,
    and the address of an array of chars, is not to be ignored in any
    standard implementation of C++.
     
    David Harmon, Apr 12, 2004
    #6
  7. "Martin Petzold" <> wrote in message
    news:c5elhv$j4e$...
    > Hi,
    > i always resolve an "arrow up" instead an "A" when i do this (snipped!):
    >
    > BYTE Byte;
    >
    > Byte = 0x41;
    > PortWrite((BYTE)(&Byte));
    >
    > BOOL PortWrite (BYTE Byte)
    > {
    > WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL);
    > return TRUE;
    > }
    >
    > what is the problem?
    >
    > thx martin


    Assuming that WriteFile requires an address as the second parameter, and a
    size as the third parameter, you are writing the size of an address rather
    than the size of a byte.

    Perhaps this will fix it:
    WriteFile (hPort, &Byte, sizeof (Byte), NULL, NULL);
     
    Bill Thompson, Apr 12, 2004
    #7
  8. Martin Petzold

    Howard Guest

    "Martin Petzold" <> wrote in message
    news:c5elhv$j4e$...
    > Hi,
    > i always resolve an "arrow up" instead an "A" when i do this (snipped!):
    >
    > BYTE Byte;
    >
    > Byte = 0x41;
    > PortWrite((BYTE)(&Byte));


    PortWrite takes a BYTE, not a pointer to a BYTE, so just pass it Byte, not
    the address of Byte.

    >
    > BOOL PortWrite (BYTE Byte)
    > {
    > WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL);


    If you're intending to write the value stored in Byte, then the size you
    probably want is sizeof(BYTE), not the size of the address of the variable.

    > return TRUE;
    > }
    >
    > what is the problem?
    >
    > thx martin



    Perhaps you want this?

    PortWrite(Byte);
    ....
    BOOL PortWrite( BYTE Byte )
    {
    WriteFile( hPort, &Byte, sizeof(BYTE), NULL, NULL );
    ....
    }

    ?

    -Howard
     
    Howard, Apr 13, 2004
    #8
  9. Martin Petzold

    red floyd Guest

    (Alf P. Steinbach) wrote in message news:<>...
    > * Martin Petzold <> schriebt:
    > >

    >
    > This is off-topic in [comp.lang.c++].
    >
    > Perhaps try [comp.os.ms-windows.programmer.win32]?
    >
    > See the FAQ for some other possibilities & posting guidelines.



    Aside from the fact that you're OT, you should use "sizeof(Byte)"
    instead of "sizeof(&Byte)".
     
    red floyd, Apr 13, 2004
    #9
    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. Martin Petzold

    problem sending code via rs232

    Martin Petzold, Apr 12, 2004, in forum: C Programming
    Replies:
    4
    Views:
    605
    CBFalconer
    Apr 12, 2004
  2. Replies:
    2
    Views:
    5,556
    Ian Collins
    Jan 19, 2006
  3. Problem with rs232

    , Jul 5, 2007, in forum: C++
    Replies:
    4
    Views:
    364
  4. Marco Savioli
    Replies:
    0
    Views:
    495
    Marco Savioli
    Jul 14, 2007
  5. jasperng
    Replies:
    0
    Views:
    2,058
    jasperng
    Oct 8, 2008
Loading...

Share This Page