![]() |
problem sending code via rs232
Hi,
i always receive 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 |
Re: problem sending code via rs232
Martin Petzold <mpetzold@gmx.net> scribbled the following:
> Hi, > i always receive 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? Your question concerns a non-standard extension to C and is thus off-topic on comp.lang.c. Please ask in a newsgroup dedicated to your own OS. -- /-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\ \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/ "Insanity is to be shared." - Tailgunner |
Re: problem sending code via rs232
>Martin Petzold <mpetzold@gmx.net> scribbled the following:
>> i always receive an "arrow up" instead an "A" when i do this (snipped!): >> BYTE Byte; >> Byte = 0x41; >> PortWrite((BYTE)(&Byte)); Presumably "BYTE" is a typedef-name or #define for some integral type (int, char, unsigned long, whatever). If so, why is there a cast here? >> BOOL PortWrite (BYTE Byte) >> { >> WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL); >> return TRUE; >> } Presumably BOOL is another typedef-name or #define for some integral type, again. If PortWrite needs a "BYTE" (int, unsigned char, whatever), passing the address of an object ("BYTE Byte = 0x41" then "&Byte") is probably not right. Another clue that there is something wrong is that the call contains a cast, to change the value produced by &Byte into a new value of whatever type the name BYTE stands for. >> what is the problem? Impossible to say for certain, but if you have a BYTE object and PortWrite() demands a BYTE value, it is more likely to work right if you pass the object's value, rather than its address. :-) In article <news:c5emt7$hp$1@oravannahka.helsinki.fi> Joona I Palaste <palaste@cc.helsinki.fi> writes: >Your question concerns a non-standard extension to C and is thus >off-topic on comp.lang.c. Please ask in a newsgroup dedicated to your >own OS. This may also be (part of) the problem, but -- as shown above -- there is a Standard C issue that can be addressed here as well. As usual, code with casts is suspicious at best. Always take a second look at casts -- there is a significant chance that, if some piece of code requires a cast to compile without a warning, that piece of code is wrong. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: forget about it http://web.torek.net/torek/index.html Reading email is like searching for food in the garbage, thanks to spammers. |
Re: problem sending code via rs232
"Martin Petzold" <mpetzold@gmx.net> a écrit dans le message de news:c5emor$l7f$1@newsreader2.netcologne.de... > Hi, Hi, Your post is off-topic here as Joona said, but... > i always receive an "arrow up" instead an "A" when i do this (snipped!): > > BYTE Byte; <win32> BYTE is a 8 bit unsigned integer. </win32> > > Byte = 0x41; OK for 'A' in ASCII. > PortWrite((BYTE)(&Byte)); PortWrite(&Byte); Perhaps you meant passing the adress of Byte to PortWrite, but it's not OK, since you cast &Byte to a BYTE value (the representation of the adress of Byte (of a BYTE element) may be different, e.g. the adress of a BYTE could be a 32 bit value). I guess you did it probably to fit the types (I see below that PortWrite takes an argument of type BYTE). > > BOOL PortWrite (BYTE Byte) > { > WriteFile (hPort, &Byte, sizeof (&Byte), NULL, NULL); > return TRUE; > } <win32> The third argument of WriteFile is the number of bytes (of the buffer whose the adress is passed as second argument) to write in hPort. It's the same kind of matter as above : sizeof(&Byte) returns the number of bytes which are needed to represent the adress of a BYTE element in memory, not the number of bytes to represent a BYTE element itself. Change in sizeof(BYTE) or sizeof (*Byte). Finally, WriteFile returns a non-zero value (of type BOOL) if it has succeeded. You should use it. BOOL PortWrite(BYTE * Byte) { return WriteFile(hPort, Byte, sizeof(BYTE), NULL, NULL); } </win32> HTH Regis > what is the problem? > > thx martin |
Re: problem sending code via rs232
Martin Petzold wrote:
> > i always receive 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? As far as I can see the only defined things in your code snippet are "0x41" and "return". If you had bothered to #include <stdio.h> "NULL" would also be included. Did your cat walk over your keyboard? How long have you lurked here? Did you read the welcome message? -- Some useful references: <http://www.ungerhu.com/jxh/clc.welcome.txt> <http://www.eskimo.com/~scs/C-faq/top.html> <http://benpfaff.org/writings/clc/off-topic.html> |
| All times are GMT. The time now is 06:26 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.