Fixed Windows stop bit settings (tracker# 1944125) so that 1, 1.5 or 2 stop bits can be set.

svn path=/trunk/externals/iem/comport/; revision=10289
This commit is contained in:
Martin Peach 2008-09-16 20:17:56 +00:00
parent 790cf21a9b
commit 9fb73a2023

View file

@ -17,6 +17,7 @@ MP 20061016 write_serial checks for GetOverlappedResult to avoid tx buffer overf
MP 20070719 added "ports" method to output list of available ports on status outlet MP 20070719 added "ports" method to output list of available ports on status outlet
MP 20071011 added comport_list and write_serials for list processing based on code by Thomas O Fredericks <tof@danslchamp.org> MP 20071011 added comport_list and write_serials for list processing based on code by Thomas O Fredericks <tof@danslchamp.org>
MP 20071113 modified non-windows open_serial to set the index of the port when it's opened by name MP 20071113 modified non-windows open_serial to set the index of the port when it's opened by name
MP 20080916 fixed Windows version stop bits to set and display 1, 1.5 or 2 for "stopbits" input of 1, 1.5 or 2
*/ */
#include "m_pd.h" #include "m_pd.h"
@ -227,7 +228,7 @@ static void comport_tick(t_comport *x);
static float set_baudrate(t_comport *x, t_float baud); static float set_baudrate(t_comport *x, t_float baud);
static float set_bits(t_comport *x, int nr); static float set_bits(t_comport *x, int nr);
static float set_parity(t_comport *x,int n); static float set_parity(t_comport *x,int n);
static float set_stopflag(t_comport *x, int nr); static float set_stopflag(t_comport *x, t_float nr);
static int set_ctsrts(t_comport *x, int nr); static int set_ctsrts(t_comport *x, int nr);
static int set_dtr(t_comport *x, int nr); static int set_dtr(t_comport *x, int nr);
static int set_rts(t_comport *x, int nr); static int set_rts(t_comport *x, int nr);
@ -333,16 +334,26 @@ static float set_parity(t_comport *x,int n)
} }
/* activate second stop bit with 1, 0(default)*/ /* Windows lets you have three different stop bit styles: 1,1.5 and 2 */
static float set_stopflag(t_comport *x, int nr) /* The message argument is the number of stop bits */
static float set_stopflag(t_comport *x, t_float nr)
{ {
if(nr == 1) if(nr == 1)
{ {
x->dcb.StopBits = 1; /* 0,1,2 = 1, 1.5, 2 */ x->dcb.StopBits = 0; /* ONESTOPBIT = 0 */
return 1; return nr;
} }
else x->dcb.StopBits = 0; /* 0,1,2 = 1, 1.5, 2 */ if(nr == 2)
{
x->dcb.StopBits = 2; /* TWOSTOPBITS = 2 */
return nr;
}
if(nr == 1.5)
{
x->dcb.StopBits = 1; /* ONE5STOPBITS = 1 */
return nr;
}
post("comport stopbit number (%f) out of range (0, 1.5, 2)", nr);
return 0; return 0;
} }
@ -408,7 +419,10 @@ static int set_serial(t_comport *x)
x->baud = x->dcb.BaudRate; x->baud = x->dcb.BaudRate;
x->data_bits = x->dcb.ByteSize; x->data_bits = x->dcb.ByteSize;
x->parity_bit = x->dcb.fParity; x->parity_bit = x->dcb.fParity;
x->stop_bits = x->dcb.StopBits; /* ONESTOPBIT=0, ONE5STOPBITS=1, TWOSTOPBITS=2*/
if(x->dcb.StopBits == 0) x->stop_bits = 1;
else if(x->dcb.StopBits == 1) x->stop_bits = 1.5;
else if(x->dcb.StopBits == 2) x->stop_bits = 2;
x->xonxoff = (x->dcb.fOutX)?1:0; x->xonxoff = (x->dcb.fOutX)?1:0;
x->ctsrts = (x->dcb.fOutxCtsFlow)?1:0; x->ctsrts = (x->dcb.fOutxCtsFlow)?1:0;
return 0; return 0;
@ -1204,7 +1218,11 @@ that allows COM port numbers to be specified.
test.baud = fbaud; test.baud = fbaud;
test.data_bits = 8; /* default 8 data bits */ test.data_bits = 8; /* default 8 data bits */
test.parity_bit = 0;/* default no parity bit */ test.parity_bit = 0;/* default no parity bit */
#ifdef _WIN32
test.stop_bits = 1;/* default 1 stop bit */
#else
test.stop_bits = 0;/* default 1 stop bit */ test.stop_bits = 0;/* default 1 stop bit */
#endif /* _WIN32 */
test.ctsrts = 0; /* default no hardware handshaking */ test.ctsrts = 0; /* default no hardware handshaking */
test.xonxoff = 0; /* default no software handshaking */ test.xonxoff = 0; /* default no software handshaking */
test.hupcl = 1; /* default hangup on close */ test.hupcl = 1; /* default hangup on close */
@ -1361,19 +1379,21 @@ static void comport_stopbit(t_comport *x,t_floatarg f)
if(set_serial(x) == 0) if(set_serial(x) == 0)
{ {
error("[comport] ** ERROR ** could not set extra stopbit of device %s\n",
#ifdef _WIN32 #ifdef _WIN32
&x->serial_device->s_name[4]); error("[comport] ** ERROR ** could not set stopbits of device %s to %f\n",
&x->serial_device->s_name[4], f);
#else #else
error("[comport] ** ERROR ** could not set extra stopbit of device %s\n",
x->serial_device->s_name); x->serial_device->s_name);
#endif #endif
return; return;
} }
else if(x->verbose > 0) else if(x->verbose > 0)
post("[comport] set extra stopbit of %s to %f\n",
#ifdef _WIN32 #ifdef _WIN32
post("[comport] set stopbits of %s to %f\n",
&x->serial_device->s_name[4], f); &x->serial_device->s_name[4], f);
#else #else
post("[comport] set extra stopbit of %s to %f\n",
x->serial_device->s_name, f); x->serial_device->s_name, f);
#endif #endif
x->stop_bits = f; x->stop_bits = f;
@ -1714,7 +1734,11 @@ static void comport_output_parity_bit(t_comport *x)
static void comport_output_stop_bits(t_comport *x) static void comport_output_stop_bits(t_comport *x)
{ {
#ifdef _WIN32
comport_output_status(x, gensym("stop"), x->stop_bits);
#else
comport_output_status(x, gensym("stop"), x->stop_bits+1); comport_output_status(x, gensym("stop"), x->stop_bits+1);
#endif
} }
static void comport_output_data_bits(t_comport *x) static void comport_output_data_bits(t_comport *x)