[PD-cvs] externals/iem/comport/comport comport.c,1.22,1.23

Martin Peach mrpeach at users.sourceforge.net
Tue Sep 26 06:12:13 CEST 2006


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

Modified Files:
	comport.c 
Log Message:
added devices message to enumerate available devices
info message outputs realtime status 


Index: comport.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** comport.c	24 Sep 2006 21:18:43 -0000	1.22
--- comport.c	26 Sep 2006 04:12:11 -0000	1.23
***************
*** 13,16 ****
--- 13,17 ----
  MP 20060824 added clock_delay call in comport_devicename
  MP 20060924 added comport_enum to list available ports in Windows
+ MP 20060925 add devices message to enumerate actual devices, info just outputs current port state
  */
  
***************
*** 195,204 ****
  static int set_serial(t_comport *x);
  static int write_serial(t_comport *x, unsigned char serial_byte);
! int comport_get_dsr(t_comport *x);
! int comport_get_cts(t_comport *x);
  #ifdef _WIN32
  static HANDLE open_serial(unsigned int com_num, t_comport *x);
  static HANDLE close_serial(t_comport *x);
- static void comport_enum(void);
  #else
  static int open_serial(unsigned int com_num, t_comport *x);
--- 196,204 ----
  static int set_serial(t_comport *x);
  static int write_serial(t_comport *x, unsigned char serial_byte);
! static int comport_get_dsr(t_comport *x);
! static int comport_get_cts(t_comport *x);
  #ifdef _WIN32
  static HANDLE open_serial(unsigned int com_num, t_comport *x);
  static HANDLE close_serial(t_comport *x);
  #else
  static int open_serial(unsigned int com_num, t_comport *x);
***************
*** 232,236 ****
--- 232,238 ----
  static void comport_output_rtscts(t_comport *x);
  static void comport_output_xonxoff(t_comport *x);
+ static void comport_enum(t_comport *x);
  static void comport_info(t_comport *x);
+ static void comport_devices(t_comport *x);
  static void comport_verbose(t_comport *x, t_floatarg f);
  static void comport_help(t_comport *x);
***************
*** 538,542 ****
  }
  
! int comport_get_dsr(t_comport *x)
  {
      short  dsr_state = 0;
--- 540,544 ----
  }
  
! static int comport_get_dsr(t_comport *x)
  {
      short  dsr_state = 0;
***************
*** 848,855 ****
  }
  
! int comport_get_dsr(t_comport *x)
  {
      short  dsr_state = 0;
!     
      if (x->comhandle != INVALID_HANDLE_VALUE)
      {
--- 850,857 ----
  }
  
! static int comport_get_dsr(t_comport *x)
  {
      short  dsr_state = 0;
! 
      if (x->comhandle != INVALID_HANDLE_VALUE)
      {
***************
*** 865,869 ****
  {
      short  cts_state = 0;
!     
      if (x->comhandle != INVALID_HANDLE_VALUE)
      {
--- 867,871 ----
  {
      short  cts_state = 0;
! 
      if (x->comhandle != INVALID_HANDLE_VALUE)
      {
***************
*** 1240,1246 ****
  }
  
! #ifdef _WIN32
! static void comport_enum(void)
  {
      HANDLE          fd;
      char            device_name[10];
--- 1242,1248 ----
  }
  
! static void comport_enum(t_comport *x)
  {
+ #ifdef _WIN32
      HANDLE          fd;
      char            device_name[10];
***************
*** 1266,1304 ****
          else if (dw == ERROR_ACCESS_DENIED)post("\t%d - COM%d (in use)", i, i);
      }
! }
! #endif // WIN32
! 
! static void comport_output_print(t_comport *x)
! {
! 	unsigned int i;
! 
! 	post("[comport]: available serial ports:");
! #ifdef _WIN32
!     comport_enum();
! #else	
      glob_t         glob_buffer;
! 	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;
  # ifdef GLOB_ABORTED
! 	case GLOB_ABORTED:
! 		error("[comport] aborted \"%s\"",x->serial_device_name);
! 		break;
  # endif /* GLOB_ABORTED */
  # ifdef GLOB_NOMATCH
! 	case GLOB_NOMATCH:
! 		error("[comport] no serial devices found for \"%s\"",x->serial_device_name);
! 		break;
  # endif /* GLOB_NOMATCH */
! 	}
! 	for(i=0; i<glob_buffer.gl_pathc; i++)
! 	{
! 		post("\t%d\t%s", i, glob_buffer.gl_pathv[i]);
! 	}
  #endif  /* _WIN32 */
  }
  
  
  static void comport_output_status(t_comport *x, t_symbol *selector, t_float output_value)
--- 1268,1314 ----
          else if (dw == ERROR_ACCESS_DENIED)post("\t%d - COM%d (in use)", i, i);
      }
! #else
!     unsigned int i;
      glob_t         glob_buffer;
!     int            fd;
!     struct termios test;
! 
! /* first look for registered devices in the filesystem */
!     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;
  # ifdef GLOB_ABORTED
!         case GLOB_ABORTED:
!         error("[comport] aborted \"%s\"",x->serial_device_name);
!         break;
  # endif /* GLOB_ABORTED */
  # ifdef GLOB_NOMATCH
!     case GLOB_NOMATCH:
!         error("[comport] no serial devices found for \"%s\"",x->serial_device_name);
!         break;
  # endif /* GLOB_NOMATCH */
!     }
!     for(i=0; i<glob_buffer.gl_pathc; i++)
!     {
! /* now try to open the device */
!         if((fd = open(glob_buffer.gl_pathv[i], OPENPARAMS)) != INVALID_HANDLE_VALUE)
!         {
! /* now see if it has attributes */
!             if ((tcgetattr(fd, &test)) != -1)
!                 post("\t%d\t%s", i, glob_buffer.gl_pathv[i]);// this one really exists
!                 close (fd);
!         }
!     }
  #endif  /* _WIN32 */
  }
  
+ static void comport_output_print(t_comport *x)
+ {
+     post("[comport]: available serial ports:");
+     comport_enum(x);
+ }
+ 
  
  static void comport_output_status(t_comport *x, t_symbol *selector, t_float output_value)
***************
*** 1355,1358 ****
--- 1365,1373 ----
  }
  
+ static void comport_devices(t_comport *x)
+ {
+ 	comport_output_print(x);
+ }
+ 
  static void comport_info(t_comport *x)
  {
***************
*** 1366,1370 ****
      comport_output_rtscts(x);
      comport_output_xonxoff(x);
- 	comport_output_print(x);
  }
  
--- 1381,1384 ----
***************
*** 1395,1403 ****
          "   close             ... close device\n"
          "   open <num>        ... open device number num\n"
!         "   devicename <d>    ... set device name to s (eg. /dev/ttyS8)\n"
          "   print <list>      ... print list of atoms on serial\n"
          "   pollintervall <t> ... set poll interval to t ticks\n"
          "   verbose <level>   ... for debug set verbosity to level\n"
          "   info              ... output info on status outlet\n"
          "   help              ... post this help");
  }
--- 1409,1418 ----
          "   close             ... close device\n"
          "   open <num>        ... open device number num\n"
!         "   devicename <d>    ... set device name to d (eg. /dev/ttyS8)\n"
          "   print <list>      ... print list of atoms on serial\n"
          "   pollintervall <t> ... set poll interval to t ticks\n"
          "   verbose <level>   ... for debug set verbosity to level\n"
          "   info              ... output info on status outlet\n"
+         "   devices           ... post list of available devices\n"
          "   help              ... post this help");
  }
***************
*** 1432,1435 ****
--- 1447,1451 ----
      class_addmethod(comport_class, (t_method)comport_help, gensym("help"), 0);
      class_addmethod(comport_class, (t_method)comport_info, gensym("info"), 0);
+     class_addmethod(comport_class, (t_method)comport_devices, gensym("devices"), 0);
  
  #ifndef _WIN32





More information about the Pd-cvs mailing list