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

Martin Peach mrpeach at users.sourceforge.net
Sun Sep 24 23:18:45 CEST 2006


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

Modified Files:
	comport.c 
Log Message:
Added comport_enum for Windows version


Index: comport.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** comport.c	11 Sep 2006 22:36:50 -0000	1.21
--- comport.c	24 Sep 2006 21:18:43 -0000	1.22
***************
*** 12,15 ****
--- 12,16 ----
  MP 20060709 All status goes out the status outlet when an info message is received
  MP 20060824 added clock_delay call in comport_devicename
+ MP 20060924 added comport_enum to list available ports in Windows
  */
  
***************
*** 199,202 ****
--- 200,204 ----
  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);
***************
*** 1238,1241 ****
--- 1240,1272 ----
  }
  
+ #ifdef _WIN32
+ static void comport_enum(void)
+ {
+     HANDLE          fd;
+     char            device_name[10];
+ 	unsigned int    i;
+     DWORD           dw;
+ 
+     for(i = 1; i < COMPORT_MAX; i++)
+ 	{
+         sprintf(device_name, "\\\\.\\COM%d", i);/* the recommended way to specify COMs above 9 */
+         fd = CreateFile( device_name,
+                 GENERIC_READ | GENERIC_WRITE,
+                 0,
+                 0,
+                 OPEN_EXISTING,
+                 FILE_FLAG_OVERLAPPED,
+                 0);
+         dw = 0L;
+         if(fd == INVALID_HANDLE_VALUE)
+             dw = GetLastError();
+         else
+             CloseHandle(fd);
+         if (dw == 0)post("\t%d - COM%d (free)", i, i);
+         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)
  {
***************
*** 1244,1253 ****
  	post("[comport]: available serial ports:");
  #ifdef _WIN32
! 	post("\t0 - COM1");
! 	for(i=1; i<COMPORT_MAX; i++)
! 	{
! 		/* TODO: this should actually probe ports */
! 		post("\t%d - COM%s", i, i);
! 	}
  #else	
      glob_t         glob_buffer;
--- 1275,1279 ----
  	post("[comport]: available serial ports:");
  #ifdef _WIN32
!     comport_enum();
  #else	
      glob_t         glob_buffer;





More information about the Pd-cvs mailing list