Re: Sending Chr(255) to Serial Port
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 2 Aug 2006 18:48:25 +0100
Vincent <mcnabb.vincent@xxxxxxxxx> wrote:
The fact IS, that SerialPort IS A STREAM, it has a property called
"Encoding" which you would have seen if you bothered to look in the
list that appears after you press the dot. Remember, the dot requires
you to use ONE finger, by placing it about the dot key, and moving it
down and up, a distance of less than half an inch. So difficult for
someone who wrote a book on the subject. I'm surprised really,
considering you wrote the book you should know this????
mySerialPort.Encoding = Encoding.ASCII;
mySerialPort.Write((char)255);
Hook it up to a computer with a nice terminal programme (e.g. one of
the ones that they had that were actually good before GUI's lip-stuck
everything) and you will see a nice little <FF> appear. Magical ! Wow!
Even if it does work, it won't be guaranteed to work in the future
though. MS would be quite within their rights to change Encoding.ASCII
to properly reflect the fact that ASCII is a 7-bit encoding.
Why suggest something which shouldn't work and might not in the future?
Although I agree with the poster that one should use bytes...
...because it makes more simple.
That's not the main reason - the main reason is because it's guaranteed
to work, whereas your suggestion isn't.
Though of course, things are simpler
if you use a real programming language like c, where byte and char are
pretty much the same thing.
That doesn't make things simpler at all. It confuses the ideas of text
and binary data.
Why didn't they keep char, and make a new
one called unchar (e.g. unicode character)? I don't know, just to
confuse those of us who considered a char to be 8 bits, but now it is
32 bits.
Well, in .NET a char is actually 16 bits, not 32...
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Sending Chr(255) to Serial Port
- From: Vincent
- Re: Sending Chr(255) to Serial Port
- References:
- Re: Sending Chr(255) to Serial Port
- From: *** Grier
- Re: Sending Chr(255) to Serial Port
- From: Vincent
- Re: Sending Chr(255) to Serial Port
- From: *** Grier
- Re: Sending Chr(255) to Serial Port
- From: Vincent
- Re: Sending Chr(255) to Serial Port
- Prev by Date: Re: Sending Chr(255) to Serial Port
- Next by Date: Re: Deploying .NET from a CD
- Previous by thread: Re: Sending Chr(255) to Serial Port
- Next by thread: Re: Sending Chr(255) to Serial Port
- Index(es):