Serial communications: Linux vs. Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Serial communications: Linux vs. Windows

Schwab,Wilhelm K

The linux vm codes stop bits as follows: 0=1.5, 1=1, 2=2.  I have long seen it (on Windows) expressed as

        ONESTOPBIT := 0.
        ONE5STOPBITS := 1.
        TWOSTOPBITS := 2.

Someone trying to write code that works across platforms will get snagged, at least if using the usual Windows definitions.  Is this something that can/should be done better to make the stop bits as platform-neutral as possible?  What would you change?


Reply | Threaded
Open this post in threaded view
|

Re: Serial communications: Linux vs. Windows

David T. Lewis
 
On Wed, Nov 24, 2010 at 02:10:44PM -0500, Schwab,Wilhelm K wrote:
>
> The linux vm codes stop bits as follows: 0=1.5, 1=1, 2=2.  I have long seen it (on Windows) expressed as
>
> ONESTOPBIT := 0.
> ONE5STOPBITS := 1.
> TWOSTOPBITS := 2.

The Windows and Unix SerialPlugin code the stop bits identically, although
on Unix the 1.5 setting apparently gets rounded up to 2. See man termios
for the reason.

Windows:

  /* set stop bits */
  switch(stopBitsType) {
    case 0: dcb.StopBits = 1; break; /* 1.5 stop bits */
    case 1: dcb.StopBits = 0; break; /* 1 stop bit */
    case 2: dcb.StopBits = 2; break; /* 2 stop bits */
    default: goto errExit;
  }

Unix:

/* stopBits 0=1.5, 1=1, 2=2 */
/* I don't know how to get 1.5 stop bits. Oh well. So you get 2 instead */
#define MAX_STOP_BITS 2
/* c_cflag definitions */
static const unsigned int stopBitsDecode[MAX_STOP_BITS + 1] = { CSTOPB, 0, CSTOPB };

> Someone trying to write code that works across platforms will get snagged,
> at least if using the usual Windows definitions.  Is this something that
> can/should be done better to make the stop bits as platform-neutral as
> possible?  What would you change?

In the plugin, I would change nothing. In class SerialPlugin, I would
add some better method comments.

If I wanted my application code to be easier to understand for someone
accustomed to Windows headers, I might consider making ONESTOPBIT,
ONE5STOPBITS and TWOSTOPBITS be class variables somewhere in my
application. But that looks a bit silly, so I guess I just go with
the method comments and leave it at that.

Dave
 
Reply | Threaded
Open this post in threaded view
|

RE: Serial communications: Linux vs. Windows

Schwab,Wilhelm K
In reply to this post by Schwab,Wilhelm K

Dave,

I probably missed the stop-bits-type vs. stop-bits distinction when I first started porting.  It might be as simple as swapping two of my pool constants to match how the vm uses them.

Thanks!

Bill