Correctly set port index when opened by name on linux & OSX.
svn path=/trunk/externals/iem/comport/; revision=8991
This commit is contained in:
parent
d774d0fefc
commit
790cf21a9b
1 changed files with 102 additions and 93 deletions
|
|
@ -16,6 +16,7 @@ MP 20060925 add devices message to enumerate actual devices, info just outputs c
|
|||
MP 20061016 write_serial checks for GetOverlappedResult to avoid tx buffer overflow errors
|
||||
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 20071113 modified non-windows open_serial to set the index of the port when it's opened by name
|
||||
*/
|
||||
|
||||
#include "m_pd.h"
|
||||
|
|
@ -873,15 +874,14 @@ static int set_hupcl(t_comport *x, int nr)
|
|||
static int open_serial(unsigned int com_num, t_comport *x)
|
||||
{
|
||||
int fd;
|
||||
unsigned int i;
|
||||
struct termios *old = &(x->oldcom_termio);
|
||||
struct termios *new = &(x->com_termio);
|
||||
float *baud = &(x->baud);
|
||||
glob_t glob_buffer;
|
||||
|
||||
/* if com_num == USE_DEVICENAME, use device name directly, else try port # */
|
||||
if(com_num != USE_DEVICENAME)
|
||||
{
|
||||
if(com_num >= COMPORT_MAX)
|
||||
if((com_num != USE_DEVICENAME)&&(com_num >= COMPORT_MAX))
|
||||
{
|
||||
post("[comport] ** WARNING ** port %d not valid, must be between 0 and %d",
|
||||
com_num, COMPORT_MAX - 1);
|
||||
|
|
@ -905,10 +905,19 @@ static int open_serial(unsigned int com_num, t_comport *x)
|
|||
break;
|
||||
#endif
|
||||
}
|
||||
if(com_num < glob_buffer.gl_pathc)
|
||||
if (com_num == USE_DEVICENAME)
|
||||
{ /* if possible, find the index of the devicename */
|
||||
for (i = 0; i < glob_buffer.gl_pathc; ++i)
|
||||
{
|
||||
x->serial_device = gensym(glob_buffer.gl_pathv[com_num]);
|
||||
if (0 == strcmp(x->serial_device->s_name, glob_buffer.gl_pathv[i]))
|
||||
{
|
||||
com_num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(com_num < glob_buffer.gl_pathc)
|
||||
x->serial_device = gensym(glob_buffer.gl_pathv[com_num]);
|
||||
else
|
||||
{
|
||||
post("[comport] ** WARNING ** port #%d does not exist! (max == %d)",
|
||||
|
|
@ -916,7 +925,7 @@ static int open_serial(unsigned int com_num, t_comport *x)
|
|||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
globfree( &(glob_buffer) );
|
||||
}
|
||||
|
||||
if((fd = open(x->serial_device->s_name, OPENPARAMS)) == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
error("[comport] ** ERROR ** could not open device %s:\n failure(%d): %s\n",
|
||||
|
|
|
|||
Loading…
Reference in a new issue