
Serial Port Communication in C#  - ionela
http://dev.emcelettronica.com/serial-port-communication-c
======
ajross
I'll never understand the mindset behind windows developers that says: "When
starting a project to do some simple low-level task, first throw up a
uselessly simple GUI application and put a button on it." I mean, half of this
article is about how to use the GUI wizard, just to show off about 10 lines of
code.

Beyond that, it's reasonably instructive. I'm happy to know that RS-232 isn't
forgotten in the .NET world; there is lots of legacy hardware out with
important things to say.

Although I was amused by this bit of hubris in the API design:

    
    
      serialPort1.StopBits= StopBits.One;
    

I'd be curious to hear why the designer felt that the concept of a "stop bit"
was so important or complicated that it deserved its own abstraction for the
number one. :)

~~~
jcl
It looks like the StopBits enumeration is in place for type-safety. It has the
values None, One, Two, and OnePointFive. With just those four values, any
representation other than an enumeration would be either inefficient or
confusing.

[http://msdn.microsoft.com/en-
us/library/system.io.ports.stop...](http://msdn.microsoft.com/en-
us/library/system.io.ports.stopbits.aspx)

<http://en.wikipedia.org/wiki/Asynchronous_start-stop>

~~~
ajross
Not really, no. The "stop bit" is an _asynchronous_ delay inserted between the
transition edge of the final bit of a byte and the rising edge of the next
start bit. It's a fundamentally analog unit of time that just happens to be
measured in "bits". In principle, there could be hardware that wants three
stop bits, or 0.7. To the extent that there are only four values, that's
purely because of historical convention (and maybe limitations of early PC
UARTs, I don't have datasheets handy).

All of which could have been easily and more robustly encapsulated by the use
of a float instead of the bizzaro-world enum that they chose.

------
ivankirigin
For any low-lever hardware engineers, I can highly recommend using Python. The
struct module is by far the easiest way to send and interpret exact bits along
a wire.

------
revolvingcur
Before you criticize this article as simplistic or unnecessary (arguments
about interest to this audience aside), consider that .NET 1.1 didn't have
built-in serial port communication. Having spent many hours hacking serial
comm in C#, I can say that this would have been a welcome resource, even given
its brevity.

------
ionela
The serial port is a serial communication interface through which information
transfers in or out one bit at a time.

~~~
prospero
C# is a Java-like language that uses the .NET runtime. Unlike Java, it has
first-class functions.

A dog is a four-legged animal that goes woof.

A cow is like a dog, but it's larger, and goes moooooo.

