Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > problem sending code via rs232

Reply
Thread Tools

problem sending code via rs232

 
 
Martin Petzold
Guest
Posts: n/a
 
      04-12-2004
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
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      04-12-2004
Martin Petzold <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Insanity is to be shared."
- Tailgunner
 
Reply With Quote
 
 
 
 
Chris Torek
Guest
Posts: n/a
 
      04-12-2004
>Martin Petzold <(E-Mail Removed)> 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$(E-Mail Removed)>
Joona I Palaste <(E-Mail Removed)> 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.
 
Reply With Quote
 
Régis Troadec
Guest
Posts: n/a
 
      04-12-2004

"Martin Petzold" <(E-Mail Removed)> a écrit dans le message de
news:c5emor$l7f$(E-Mail Removed)...
> 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



 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      04-12-2004
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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL code for RS232 bus controller jasperng VHDL 0 10-08-2008 03:39 PM
Rs232/Usb device via webservices? Is it possible? Marco Savioli Java 0 07-14-2007 12:26 AM
sending <STX><ETX > charaters to RS232 port jyotish.bora@gmail.com C++ 2 01-19-2006 10:06 PM
problem sending code via rs232 Martin Petzold C++ 8 04-12-2004 11:23 PM
Sending pictures via email Via OE6+Win XP - I no longer get prompt to "make all my pictures smaller" Ian Roberts Digital Photography 3 09-21-2003 04:57 PM



Advertisments