Update of /cvsroot/pure-data/externals/iem/comport/comport In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11508
Modified Files: comport.c comport-help.pd Log Message: Added 'ports' method to output list of available ports on status outlet.
Index: comport.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** comport.c 29 Dec 2006 05:41:10 -0000 1.27 --- comport.c 19 Jul 2007 15:26:57 -0000 1.28 *************** *** 15,18 **** --- 15,19 ---- MP 20060925 add devices message to enumerate actual devices, info just outputs current port state 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 */
*************** *** 270,273 **** --- 271,275 ---- static void comport_info(t_comport *x); static void comport_devices(t_comport *x); + static void comport_ports(t_comport *x); static void comport_verbose(t_comport *x, t_floatarg f); static void comport_help(t_comport *x); *************** *** 1357,1360 **** --- 1359,1431 ---- }
+ static void comport_ports(t_comport *x) + { /* the same as comport_enum except outputs list of available ports on status outlet */ + unsigned int i, j = 0; + int ports[COMPORT_MAX]; /* we don't know how many there might be but 99 is probably safe */ + #ifdef _WIN32 + HANDLE fd; + char device_name[10]; + 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)||(dw == ERROR_ACCESS_DENIED)) ports[j++]=i; + } + #else + 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) && (j < COMPORT_MAX); 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) + ports[j++] = i;/* this one really exists */ + close (fd); + } + } + #endif /* _WIN32 */ + if (j) + { + t_atom *output_atom = getbytes(j*sizeof(t_atom)); + for (i = 0; i < j; ++i) SETFLOAT(&output_atom[i], ports[i]); + outlet_anything( x->x_status_outlet, gensym("ports"), j, output_atom); + freebytes(output_atom, j*sizeof(t_atom)); + } + } + static void comport_output_print(t_comport *x) { *************** *** 1476,1479 **** --- 1547,1551 ---- " info ... output info on status outlet\n" " devices ... post list of available devices\n" + " ports ... output list of available devices on status outlet\n" " help ... post this help"); } *************** *** 1509,1512 **** --- 1581,1585 ---- class_addmethod(comport_class, (t_method)comport_info, gensym("info"), 0); class_addmethod(comport_class, (t_method)comport_devices, gensym("devices"), 0); + class_addmethod(comport_class, (t_method)comport_ports, gensym("ports"), 0);
#ifndef _WIN32
Index: comport-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport-help.pd,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** comport-help.pd 2 Nov 2006 04:25:54 -0000 1.7 --- comport-help.pd 19 Jul 2007 15:26:57 -0000 1.8 *************** *** 1,4 **** ! #N canvas 95 38 746 619 10; ! #X obj 18 415 comport 1 9600; #X msg 13 189 66; #X msg 7 147 64; --- 1,4 ---- ! #N canvas 504 0 746 619 10; ! #X obj 18 436 comport 1 9600; #X msg 13 189 66; #X msg 7 147 64; *************** *** 15,29 **** #X msg 314 113 parity 0; #X text 381 112 parity 1=even , -1=odd , 0=off; ! #X text 392 86 extra stopbit 1=on , 0=off; #X text 363 60 databits 5 , 6 , 7 , 8; ! #X obj 43 394 r comctl; ! #X obj 199 447 s comctl; #X text 394 138 use handshake xon/off 1=on 0=off; ! #X text 392 166 cts/rts hardwarehandshake 1=on 0=off; #X msg 318 214 pollintervall 1; ! #X text 428 214 (default is 1 tick 1ms); #X msg 317 246 close; #X msg 317 272 open 1; ! #X text 356 246 Close Serial port; #X msg 313 415 devicename /dev/ttyS1; #X text 313 432 Danger !!! you can open every file in your system and --- 15,29 ---- #X msg 314 113 parity 0; #X text 381 112 parity 1=even , -1=odd , 0=off; ! #X text 385 86 extra stopbit 1=on , 0=off; #X text 363 60 databits 5 , 6 , 7 , 8; ! #X obj 56 414 r comctl; ! #X obj 245 438 s comctl; #X text 394 138 use handshake xon/off 1=on 0=off; ! #X text 386 164 cts/rts hardwarehandshake 1=on 0=off; #X msg 318 214 pollintervall 1; ! #X text 428 213 (default is 1 tick 1ms); #X msg 317 246 close; #X msg 317 272 open 1; ! #X text 356 245 Close Serial port; #X msg 313 415 devicename /dev/ttyS1; #X text 313 432 Danger !!! you can open every file in your system and *************** *** 35,65 **** #X floatatom 183 76 5 0 0 0 - - -; #X text 60 35 you can send bytes directly (0-255):; ! #X text 360 272 Open serial port by number; ! #X text 473 416 open the serial port by name; ! #X msg 313 353 dtr $1; ! #X obj 293 353 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 ! 1; ! #X obj 292 388 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 ! 1; ! #X msg 312 388 rts $1; ! #X text 362 352 dtr output; ! #X text 361 388 rts output; ! #X msg 172 384 help; ! #X msg 313 323 verbose $1; ! #X obj 294 323 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X text 377 197 set poll interval for read in ms; #X msg 123 191 info; #X floatatom 111 499 7 0 0 1 baud - -; ! #X floatatom 237 547 4 0 0 3 parity - -; ! #X floatatom 279 547 4 0 0 2 stop - -; ! #X floatatom 322 547 4 0 0 3 data - -; ! #X obj 526 498 print; ! #X floatatom 448 496 4 0 0 0 port - -; ! #X msg 136 291 devices; #X obj 141 74 % 255; #X floatatom 149 95 5 0 0 0 - - -; #X text 158 191 status list on right outlet; ! #X text 192 290 print available devices (wait for it...); #X text 393 -9 2006 Martin Peach; #X obj 69 75 key; --- 35,65 ---- #X floatatom 183 76 5 0 0 0 - - -; #X text 60 35 you can send bytes directly (0-255):; ! #X text 364 271 Open serial port by number; ! #X text 473 414 open the serial port by name; ! #X msg 362 360 dtr $1; ! #X obj 342 360 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 ! -1 0 1; ! #X obj 364 380 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -1 -1 0 1; + #X msg 384 380 rts $1; + #X text 411 359 dtr output; + #X text 433 379 rts output; + #X msg 76 361 help; + #X msg 342 339 verbose $1; + #X obj 323 339 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 + -1 0 1; #X text 377 197 set poll interval for read in ms; #X msg 123 191 info; #X floatatom 111 499 7 0 0 1 baud - -; ! #X floatatom 214 540 4 0 0 3 parity - -; ! #X floatatom 249 540 4 0 0 2 stop - -; ! #X floatatom 283 539 4 0 0 3 data - -; ! #X obj 491 502 print; ! #X floatatom 387 502 4 0 0 0 port - -; ! #X msg 317 298 devices; #X obj 141 74 % 255; #X floatatom 149 95 5 0 0 0 - - -; #X text 158 191 status list on right outlet; ! #X text 375 297 print available devices (wait for it...); #X text 393 -9 2006 Martin Peach; #X obj 69 75 key; *************** *** 67,82 **** #X floatatom 58 119 5 0 0 0 ascii - -; #X text 10 76 terminal:; ! #X msg 152 222 open 0; ! #X obj 364 514 tgl 15 0 empty empty rts/cts -10 20 1 11 -262144 -1 -1 0 1; ! #X obj 406 514 tgl 15 0 empty empty xon/xoff -14 20 1 11 -262144 -1 -1 0 1; ! #X text 87 546 serial packet format:; ! #X text 277 512 handshaking:; ! #X text 3 571 flow control inputs:; ! #X obj 153 572 tgl 15 0 empty empty dsr 0 20 1 11 -262144 -1 -1 0 1 ! ; ! #X obj 195 572 tgl 15 0 empty empty cts 0 20 1 11 -262144 -1 -1 0 1 ! ; #N canvas 513 22 735 499 bauds 0; #X msg 229 314 baud 57600; --- 67,82 ---- #X floatatom 58 119 5 0 0 0 ascii - -; #X text 10 76 terminal:; ! #X msg 227 272 open 0; ! #X obj 318 505 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699 -1 0 1; ! #X obj 352 530 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699 -1 0 1; ! #X text 64 539 serial packet format:; ! #X text 229 502 handshaking:; ! #X text 0 571 flow control inputs:; ! #X obj 145 571 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1 ! 0 1; ! #X obj 180 571 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1 ! 0 1; #N canvas 513 22 735 499 bauds 0; #X msg 229 314 baud 57600; *************** *** 144,159 **** #X restore 622 72 pd bauds; #X msg 314 139 xonxoff $1; ! #X obj 275 139 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 ! 1; ! #X msg 314 167 rtscts $1; ! #X obj 274 167 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 ! 1; #X text 117 11 comport: a serial port interface; #X msg 102 118 13; ! #X obj 111 470 route baud dsr cts parity stop data rtscts xonxoff port ! open; ! #X obj 484 499 tgl 15 0 empty empty open -6 20 1 11 -262144 -1 -1 0 ! 1; ! #X connect 0 1 76 0; #X connect 1 0 0 0; #X connect 2 0 0 0; --- 144,163 ---- #X restore 622 72 pd bauds; #X msg 314 139 xonxoff $1; ! #X obj 286 140 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 ! -1 0 1; ! #X msg 314 165 rtscts $1; ! #X obj 286 167 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 ! -1 0 1; #X text 117 11 comport: a serial port interface; #X msg 102 118 13; ! #X obj 421 501 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699 ! -1 1 1; ! #X msg 317 320 ports; ! #X obj 111 462 route baud dsr cts parity stop data rtscts xonxoff port ! open ports; ! #X obj 456 530 print port_list; ! #X text 363 319 list available ports on right outlet; ! #X text 110 360 print usage info; ! #X connect 0 1 78 0; #X connect 1 0 0 0; #X connect 2 0 0 0; *************** *** 175,183 **** #X connect 36 0 37 0; #X connect 37 0 18 0; ! #X connect 40 0 18 0; #X connect 41 0 18 0; #X connect 42 0 41 0; #X connect 44 0 0 0; ! #X connect 51 0 0 0; #X connect 52 0 0 0; #X connect 52 0 53 0; --- 179,187 ---- #X connect 36 0 37 0; #X connect 37 0 18 0; ! #X connect 40 0 0 0; #X connect 41 0 18 0; #X connect 42 0 41 0; #X connect 44 0 0 0; ! #X connect 51 0 18 0; #X connect 52 0 0 0; #X connect 52 0 53 0; *************** *** 185,189 **** #X connect 58 1 59 0; #X connect 58 1 0 0; ! #X connect 61 0 0 0; #X connect 70 0 18 0; #X connect 71 0 70 0; --- 189,193 ---- #X connect 58 1 59 0; #X connect 58 1 0 0; ! #X connect 61 0 18 0; #X connect 70 0 18 0; #X connect 71 0 70 0; *************** *** 191,203 **** #X connect 73 0 72 0; #X connect 75 0 0 0; ! #X connect 76 0 45 0; ! #X connect 76 1 67 0; ! #X connect 76 2 68 0; ! #X connect 76 3 46 0; ! #X connect 76 4 47 0; ! #X connect 76 5 48 0; ! #X connect 76 6 62 0; ! #X connect 76 7 63 0; ! #X connect 76 8 50 0; ! #X connect 76 9 77 0; ! #X connect 76 10 49 0; --- 195,209 ---- #X connect 73 0 72 0; #X connect 75 0 0 0; ! #X connect 77 0 18 0; ! #X connect 78 0 45 0; ! #X connect 78 1 67 0; ! #X connect 78 2 68 0; ! #X connect 78 3 46 0; ! #X connect 78 4 47 0; ! #X connect 78 5 48 0; ! #X connect 78 6 62 0; ! #X connect 78 7 63 0; ! #X connect 78 8 50 0; ! #X connect 78 9 76 0; ! #X connect 78 10 79 0; ! #X connect 78 11 49 0;