Update of /cvsroot/pure-data/externals/iem/comport/comport In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24794
Modified Files: comport-help.pd comport.c Log Message: added HUPCL support in an attempt to get things working better with the Arduino Diecimila
Index: comport.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** comport.c 22 Jul 2007 19:10:50 -0000 1.29 --- comport.c 10 Oct 2007 00:20:56 -0000 1.30 *************** *** 67,70 **** --- 67,71 ---- int xonxoff; /* nonzero if xonxoff handshaking is on */ int ctsrts; /* nonzero if ctsrts handshaking is on */ + int hupcl; /* nonzero if hang-up on close is on */ short rxerrors; /* holds the rx line errors */ t_clock *x_clock; *************** *** 229,232 **** --- 230,234 ---- static int set_rts(t_comport *x, int nr); static int set_xonxoff(t_comport *x, int nr); + static int set_hupcl(t_comport *x, int nr); static int set_serial(t_comport *x); static int write_serial(t_comport *x, unsigned char serial_byte); *************** *** 254,257 **** --- 256,260 ---- static void comport_rts(t_comport *x,t_floatarg f); static void comport_xonxoff(t_comport *x,t_floatarg f); + static void comport_hupcl(t_comport *x,t_floatarg f); static void comport_close(t_comport *x); static void comport_open(t_comport *x, t_floatarg f); *************** *** 268,271 **** --- 271,275 ---- static void comport_output_rtscts(t_comport *x); static void comport_output_xonxoff(t_comport *x); + static void comport_output_hupcl(t_comport *x); static void comport_enum(t_comport *x); static void comport_info(t_comport *x); *************** *** 465,469 **** break; } ! post("** ERROR ** could not open device %s:\n failure(%d) %s\n", &x->serial_device->s_name[4], dw, errStr); return INVALID_HANDLE_VALUE; --- 469,473 ---- break; } ! pd_error(x, "[comport]: could not open device %s:\n failure(%d) %s\n", &x->serial_device->s_name[4], dw, errStr); return INVALID_HANDLE_VALUE; *************** *** 474,478 **** if (!GetCommState(fd, &(x->dcb_old))) { ! post("** ERROR ** could not get old dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); --- 478,482 ---- if (!GetCommState(fd, &(x->dcb_old))) { ! pd_error(x, "[comport]: could not get old dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); *************** *** 484,488 **** if (!GetCommState(fd, &(x->dcb))) { ! post("** ERROR ** could not get new dcb of device %s\n", &x->serial_device->s_name[4]);
--- 488,492 ---- if (!GetCommState(fd, &(x->dcb))) { ! pd_error(x, "[comport]: could not get new dcb of device %s\n", &x->serial_device->s_name[4]);
*************** *** 530,534 **** else { ! error("[comport] ** ERROR ** could not set params to control dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); --- 534,538 ---- else { ! pd_error(x, "[comport] could not set params to control dcb of device %s\n", &x->serial_device->s_name[4]); CloseHandle(fd); *************** *** 663,666 **** --- 667,673 ---- while(i < BAUDRATETABLE_LEN && baudratetable[i] > *baud) i++;
+ if(baudratetable[i] != *baud) + post("[comport]: %d not valid, using closest value: ", *baud, baudratetable[i]); + /* nearest Baudrate finding */ if(i==BAUDRATETABLE_LEN || baudspeedbittable[i] < 0) *************** *** 670,673 **** --- 677,681 ---- } *baud = baudratetable[i]; + post("get_baud_ratebits: %f", *baud);
return baudspeedbittable[i]; *************** *** 678,684 **** struct termios *tio = &(x->com_termio); speed_t baudbits = get_baud_ratebits(&baud); ! ! cfsetispeed(tio, baudbits); ! cfsetospeed(tio, baudbits);
return baud; --- 686,694 ---- struct termios *tio = &(x->com_termio); speed_t baudbits = get_baud_ratebits(&baud); ! post("set_baudrate baudbits: %d", baudbits); ! if( cfsetispeed(tio, baudbits) != 0 ) ! post("[comport]: ERROR failed to set bitrate: %d", baudbits); ! if( cfsetospeed(tio, baudbits) != 0 ) ! post("[comport]: ERROR failed to set bitrate: %d", baudbits);
return baud; *************** *** 795,798 **** --- 805,832 ---- }
+ static int set_hupcl(t_comport *x, int nr) + { + struct termios settings; + int result; + + result = tcgetattr(x->comhandle, &settings); + if (result < 0) + { + perror ("error in tcgetattr"); + return 0; + } + settings.c_iflag &= ~HUPCL; + if(nr) + settings.c_iflag |= HUPCL; + result = tcsetattr(x->comhandle, TCSANOW, &settings); + if (result < 0) + { + pd_error(x,"[comport] could not set HUPCL"); + return 0; + } + x->hupcl = nr; + return 1; + } + static int open_serial(unsigned int com_num, t_comport *x) { *************** *** 1022,1025 **** --- 1056,1060 ---- unsigned char serial_byte; fd_set com_rfds; + int count = 0;
FD_ZERO(&com_rfds); *************** *** 1031,1035 **** --- 1066,1073 ---- /* while( (err = read(fd,(char *) &serial_byte,1)) > 0){ */ outlet_float(x->x_data_outlet, (t_float) serial_byte); + ++count; } + // if( count > 0) + // post("--- %d", count); } #endif *************** *** 1092,1095 **** --- 1130,1134 ---- test.ctsrts = 0; /* default no hardware handshaking */ test.xonxoff = 0; /* default no software handshaking */ + test.hupcl = 1; /* default hangup on close */ fd = open_serial((unsigned int)com_num, &test);
*************** *** 1107,1110 **** --- 1146,1150 ---- x->ctsrts = test.ctsrts; x->xonxoff = test.xonxoff; + x->hupcl = test.hupcl; x->comhandle = fd; /* holds the comport handle */
*************** *** 1362,1365 **** --- 1402,1413 ---- }
+ static void comport_hupcl(t_comport *x,t_floatarg f) + { + //#ifdef _WIN32 + //#else + set_hupcl(x,f); + //#endif + } + static void comport_close(t_comport *x) { *************** *** 1608,1611 **** --- 1656,1664 ---- }
+ static void comport_output_hupcl(t_comport *x) + { + comport_output_status(x, gensym("hupcl"), x->hupcl); + } + static void comport_output_open_status(t_comport *x) { *************** *** 1633,1636 **** --- 1686,1690 ---- comport_output_rtscts(x); comport_output_xonxoff(x); + comport_output_hupcl(x); }
*************** *** 1663,1666 **** --- 1717,1721 ---- " dtr <0|1> ... set dtr off|on\n" " rts <0|1> ... set rts off|on\n" + " hupcl <0|1> ... set hang-up on close off|on\n" " close ... close device\n" " open <num> ... open device number num\n" *************** *** 1696,1699 **** --- 1751,1755 ---- class_addmethod(comport_class, (t_method)comport_parity, gensym("parity"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_xonxoff, gensym("xonxoff"), A_FLOAT, 0); + class_addmethod(comport_class, (t_method)comport_hupcl, gensym("hupcl"), A_FLOAT, 0); class_addmethod(comport_class, (t_method)comport_close, gensym("close"), 0); class_addmethod(comport_class, (t_method)comport_open, gensym("open"), A_FLOAT, 0);
Index: comport-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/iem/comport/comport/comport-help.pd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** comport-help.pd 19 Jul 2007 15:26:57 -0000 1.8 --- comport-help.pd 10 Oct 2007 00:20:56 -0000 1.9 *************** *** 1,3 **** ! #N canvas 504 0 746 619 10; #X obj 18 436 comport 1 9600; #X msg 13 189 66; --- 1,3 ---- ! #N canvas 504 22 750 623 10; #X obj 18 436 comport 1 9600; #X msg 13 189 66; *************** *** 11,24 **** #X text 49 283 run; #X text 50 323 sleep; ! #X msg 314 61 bits 8; ! #X msg 314 87 stopbit 0; ! #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); --- 11,24 ---- #X text 49 283 run; #X text 50 323 sleep; ! #X msg 314 51 bits 8; ! #X msg 314 77 stopbit 0; ! #X msg 314 103 parity 0; ! #X text 381 102 parity 1=even , -1=odd , 0=off; ! #X text 385 76 extra stopbit 1=on , 0=off; ! #X text 363 50 databits 5 , 6 , 7 , 8; #X obj 56 414 r comctl; #X obj 245 438 s comctl; ! #X text 394 128 use handshake xon/off 1=on 0=off; ! #X text 386 154 cts/rts hardwarehandshake 1=on 0=off; #X msg 318 214 pollintervall 1; #X text 428 213 (default is 1 tick 1ms); *************** *** 143,156 **** #X connect 33 0 24 0; #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 --- 143,156 ---- #X connect 33 0 24 0; #X restore 622 72 pd bauds; ! #X msg 314 129 xonxoff $1; ! #X obj 286 130 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 -1 0 1; ! #X msg 314 155 rtscts $1; ! #X obj 286 157 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 0 1; #X msg 317 320 ports; #X obj 111 462 route baud dsr cts parity stop data rtscts xonxoff port *************** *** 159,162 **** --- 159,166 ---- #X text 363 319 list available ports on right outlet; #X text 110 360 print usage info; + #X obj 289 182 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685 + -1 0 1; + #X msg 318 179 hupcl $1; + #X text 386 179 hang-up-on-close 1=on 0=off; #X connect 0 1 78 0; #X connect 1 0 0 0; *************** *** 208,209 **** --- 212,215 ---- #X connect 78 10 79 0; #X connect 78 11 49 0; + #X connect 82 0 83 0; + #X connect 83 0 18 0;