[PD-cvs] externals/iem/comport/comport comport.c,1.13,1.14

Hans-Christoph Steiner eighthave at users.sourceforge.net
Mon May 22 15:55:17 CEST 2006


Update of /cvsroot/pure-data/externals/iem/comport/comport
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5997

Modified Files:
	comport.c 
Log Message:
made [devicename( message open the port by devicename directly; commented out code for 2nd inlet for status because it was causing segfaults :-/

Index: comport.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** comport.c	21 May 2006 13:35:20 -0000	1.13
--- comport.c	22 May 2006 13:55:14 -0000	1.14
***************
*** 63,66 ****
--- 63,68 ----
    int verbose;
  
+ 	t_outlet *x_data_outlet;
+ 	t_outlet *x_status_outlet;
  } t_comport;
  
***************
*** 407,411 ****
    };
  
!   
    return fd;
  }
--- 409,415 ----
    };
  
! // this causes a segfault... WHY?!?
! //  outlet_float(x->x_status_outlet, (t_float)com_num);
! 
    return fd;
  }
***************
*** 415,430 ****
    if(x->comhandle != INVALID_HANDLE_VALUE){
  
!     if (!SetCommState(x->comhandle, &(x->dcb_old)) )
        {
! 	post("** ERROR ** could not reset params to DCB of device %s\n",
! 	     x->serial_device->s_name);
        }
! 
!     if (!SetCommTimeouts(x->comhandle, &(x->old_timeouts))){
!       post("Couldnt reset old_timeouts for serial device");
!     };
!     CloseHandle(x->comhandle); 
    }
! 
    return INVALID_HANDLE_VALUE;
  }
--- 419,438 ----
    if(x->comhandle != INVALID_HANDLE_VALUE){
  
! 	  if (!SetCommState(x->comhandle, &(x->dcb_old)) )
        {
! 		  post("[comport] ** ERROR ** could not reset params to DCB of device %s\n",
! 			   x->serial_device->s_name);
        }
! 	  
! 	  if (!SetCommTimeouts(x->comhandle, &(x->old_timeouts))){
! 		  post("[comport] Couldnt reset old_timeouts for serial device");
! 	  };
! 	  CloseHandle(x->comhandle); 
! // for some reason, this causes a segfault...
! //	  post("[comport] closed %s",x->serial_device->s_name);
    }
! // this causes a segfault... WHY?!?
! //  outlet_float(x->x_status_outlet, 0);
!   
    return INVALID_HANDLE_VALUE;
  }
***************
*** 558,599 ****
    glob_t glob_buffer;
  
!   if(com_num >= COMPORT_MAX) {
! 	  post("[comport] ** WARNING ** port %d not valid, must be between 0 and %d",
! 		   com_num, COMPORT_MAX - 1);
! 	  return INVALID_HANDLE_VALUE;
!   }
  //  post("[comport] globbing %s",x->serial_device_name);
!   /* get the device path based on the com# and the glob pattern */
!   switch( glob( x->serial_device_name, 0, NULL, &glob_buffer ) )
!   {
!   case GLOB_NOSPACE: 
! 	  error("[comport] out of memory for \"%s\"",x->serial_device_name); 
  		  break;
!   case GLOB_ABORTED: 
! 	  error("[comport] aborted \"%s\"",x->serial_device_name); 
  		  break;
!   case GLOB_NOMATCH: 
! 	  error("[comport] no serial devices found for \"%s\"",x->serial_device_name); 
! 	  break;
!   }
!   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)",
! 		   com_num,glob_buffer.gl_pathc - 1);
  	  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",
! 			  x->serial_device->s_name,errno,strerror(errno));
! 		return INVALID_HANDLE_VALUE;
!     }
! 
    /* set no wait on any operation */
    fcntl(fd, F_SETFL, FNDELAY);
--- 566,611 ----
    glob_t glob_buffer;
  
! /* if com_num == 9999, use device name directly, else try port # */
!   if(com_num != 9999)
!   {  
! 	  if(com_num >= COMPORT_MAX) 
! 	  {
! 		  post("[comport] ** WARNING ** port %d not valid, must be between 0 and %d",
! 			   com_num, COMPORT_MAX - 1);
! 		  return INVALID_HANDLE_VALUE;
! 	  }
  //  post("[comport] globbing %s",x->serial_device_name);
! 	  /* get the device path based on the port# and the glob pattern */
! 	  switch( glob( x->serial_device_name, 0, NULL, &glob_buffer ) )
! 	  {
! 	  case GLOB_NOSPACE: 
! 		  error("[comport] out of memory for \"%s\"",x->serial_device_name); 
  		  break;
! 	  case GLOB_ABORTED: 
! 		  error("[comport] aborted \"%s\"",x->serial_device_name); 
  		  break;
! 	  case GLOB_NOMATCH: 
! 		  error("[comport] no serial devices found for \"%s\"",x->serial_device_name); 
! 		  break;
! 	  }
! 	  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)",
! 			   com_num,glob_buffer.gl_pathc - 1);
! 		  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",
! 			x->serial_device->s_name,errno,strerror(errno));
  	  return INVALID_HANDLE_VALUE;
    }
!   
    /* set no wait on any operation */
    fcntl(fd, F_SETFL, FNDELAY);
***************
*** 641,644 ****
--- 653,658 ----
  		 post("[comport] opened serial line device %d (%s)\n",
  			  com_num,x->serial_device->s_name);
+ // this causes a segfault... WHY?!?
+ //		 outlet_float(x->x_status_outlet, (t_float)com_num);
  	 }
    else 
***************
*** 656,667 ****
  static int close_serial(t_comport *x)
  {
!   struct termios *tios = &(x->com_termio);
!   HANDLE fd = x->comhandle;
  
!    if(fd != INVALID_HANDLE_VALUE){
!     tcsetattr(fd, TCSANOW, tios);
!     close(fd);
!    }
!    return INVALID_HANDLE_VALUE;
  }
  
--- 670,685 ----
  static int close_serial(t_comport *x)
  {
! 	struct termios *tios = &(x->com_termio);
! 	HANDLE fd = x->comhandle;
  
! 	if(fd != INVALID_HANDLE_VALUE){
! 		tcsetattr(fd, TCSANOW, tios);
! 		close(fd);
! // for some reason, this causes a segfault...
! //		post("[comport] closed %s",x->serial_device->s_name);
! // this causes a segfault... WHY?!?
! //		outlet_float(x->x_status_outlet, 0);
! 	}
! 	return INVALID_HANDLE_VALUE;
  }
  
***************
*** 725,729 ****
  	    for(dwX=0;dwX<dwRead;dwX++)
  	      {
! 		outlet_float(x->x_obj.ob_outlet, (t_float) serial_byte[dwX]);
  	      }
  	  }
--- 743,747 ----
  	    for(dwX=0;dwX<dwRead;dwX++)
  	      {
! 		outlet_float(x->x_data_outlet, (t_float) serial_byte[dwX]);
  	      }
  	  }
***************
*** 747,751 ****
  
        /*  while(    (err = read(fd,(char *) &serial_byte,1)) > 0){ */
!       outlet_float(x->x_obj.ob_outlet, (t_float) serial_byte);
  
      };
--- 765,769 ----
  
        /*  while(    (err = read(fd,(char *) &serial_byte,1)) > 0){ */
!       outlet_float(x->x_data_outlet, (t_float) serial_byte);
  
      };
***************
*** 824,828 ****
    x->rxerrors = 0;             /* holds the rx line errors */
  
!   outlet_new(&x->x_obj, &s_float);
  
    x->x_hit = 0;
--- 842,848 ----
    x->rxerrors = 0;             /* holds the rx line errors */
  
!   x->x_data_outlet = (t_outlet *)outlet_new(&x->x_obj, &s_float);
! // for some unknown reason, outputting on this outlet causes segfaults...
! //  x->x_status_outlet = (t_outlet *)outlet_new(&x->x_obj, &s_float);
  
    x->x_hit = 0;
***************
*** 947,951 ****
      comport_close(x);
  
- 
    x->comhandle = open_serial(f,x);
  
--- 967,970 ----
***************
*** 960,971 ****
  static void comport_devicename(t_comport *x, t_symbol *s)
  {
!   if(x->comport >= 0 && x->comport < COMPORT_MAX){
!     x->serial_device->s_name = s->s_name;   
!     if(x->verbose > 0)
!         post("[comport] %d: set devicename %s",x->comport,x->serial_device->s_name);
!   }
!   else if(x->verbose > 0)
!      post("[comport] %d: could not set devicename %s",x->comport,s->s_name);
! 
  }
  
--- 979,984 ----
  static void comport_devicename(t_comport *x, t_symbol *s)
  {
! 	x->serial_device = s;   
! 	x->comhandle = open_serial(9999,x);
  }
  
***************
*** 1052,1056 ****
  #endif /* NOT _WIN32 */
    post("comport - PD external for unix/windows\n"
!        "LGPL 1998-2005,  Winfried Ritsch and others (see LICENCE.txt)\n"
         "Institute for Electronic Music - Graz");
  }
--- 1065,1069 ----
  #endif /* NOT _WIN32 */
    post("comport - PD external for unix/windows\n"
!        "LGPL 1998-2006,  Winfried Ritsch and others (see LICENCE.txt)\n"
         "Institute for Electronic Music - Graz");
  }





More information about the Pd-cvs mailing list