From: "Deveau, Darrin" <[EMAIL PROTECTED]>
Subject: Re: Displaying serial data to screen

> >>    CharPtr sA, sX, cStatus, sBytes, sBuffer;
> >    ...

> >>    StrIToA(sBytes, (int)ulBytes);
>
> >This won't work.  You didn't allocate space for the string, so writing
> >to sBytes will over-write adjacent vars. (or possibly something else!)
> >
> I can allocate memory to sBytes fine.

In the code you posted, you declared sBytes as a pointer to a Char.  This
allocates probably 2 bytes for the pointer, but does not allocate any space
for the characters you plan to store.  Later, you attempt to convert ulBytes
to a string, storing the result wherever sBytes points to.  I didn't see
anywhere in between where you allocated any space to store that string.  You
need something like this:

Char sBytes[kMaxSize+1];    // allocate memory for kMaxSize+1 Chars
...
StrIToA(sBytes, (int)ulBytes);

Alternatively, you can declare sBytes as a CharPtr, then allocate space for
the string with

sBytes = (CharPtr)MemPtrNew(kMaxSize+1);

Or, you could use MemHandleNew().

> I do not know exactly what you mean by converting all the stuff you
receive
> from little-endian to big-endian (or vice-versa).

Big-endian and little-endian refer to which end of a binary number is
significant.  A big-endian architecture considers the leftmost bytes more
significant and the opposite is true for a little-endian machine.  Intel x86
processors are little-endian; Motorola processors are big-endian.  If you
send data from a little-endian to a big-endian machine then it will appear
that you aren't receiving what you sent due to the different interpretations
of the binary numbers.  I haven't used the serial manager to receive data
from a PC, but I suspect that in this situation, you will have to convert
the numbers from little- to big-endian when you receive them.



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to