aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comport/comport-help.pd322
-rw-r--r--comport/comport.c55
2 files changed, 228 insertions, 149 deletions
diff --git a/comport/comport-help.pd b/comport/comport-help.pd
index a91f8b8..6e3b538 100644
--- a/comport/comport-help.pd
+++ b/comport/comport-help.pd
@@ -1,74 +1,72 @@
-#N canvas 67 105 1015 636 10;
-#X obj 488 438 comport 1 9600;
-#X msg 276 421 66;
-#X msg 234 421 64;
-#X text 273 403 point;
-#X text 231 403 stream;
-#X msg 318 421 86;
-#X text 315 403 position;
-#X msg 380 421 70;
-#X msg 420 421 71;
-#X text 376 403 run;
-#X text 416 403 sleep;
-#X msg 314 61 bits 8;
-#X msg 340 87 stopbit 0;
-#X msg 400 147 parity 0;
-#X text 467 146 parity 1=even \, -1=odd \, 0=off;
-#X text 363 60 databits 5 \, 6 \, 7 \, 8;
-#X obj 488 412 r comctl;
-#X obj 694 458 s comctl;
-#X text 500 166 use handshake xon/off 1=on 0=off;
-#X text 512 186 cts/rts hardwarehandshake 1=on 0=off;
-#X msg 460 207 pollintervall 1;
-#X msg 482 229 close;
-#X msg 503 250 open 1;
-#X text 521 228 Close Serial port;
-#X msg 666 413 devicename /dev/ttyS1;
-#X text 35 511 (C) 1998-2005 IEM Winfried Ritsch GPL (see LICENSE.txt)
-;
-#X obj 135 50 hsl 128 15 0 255 0 0 empty empty empty -2 -6 0 8 -262144
+#N canvas 106 261 1181 656 10;
+#X obj 534 458 comport 1 9600;
+#X msg 322 441 66;
+#X msg 280 441 64;
+#X text 319 423 point;
+#X text 277 423 stream;
+#X msg 364 441 86;
+#X text 361 423 position;
+#X msg 426 441 70;
+#X msg 466 441 71;
+#X text 422 423 run;
+#X text 462 423 sleep;
+#X msg 374 61 bits 8;
+#X msg 400 87 stopbit 0;
+#X msg 460 147 parity 0;
+#X text 527 146 parity 1=even \, -1=odd \, 0=off;
+#X text 423 60 databits 5 \, 6 \, 7 \, 8;
+#X obj 534 432 r comctl;
+#X obj 754 458 s comctl;
+#X text 560 166 use handshake xon/off 1=on 0=off;
+#X text 572 186 cts/rts hardwarehandshake 1=on 0=off;
+#X msg 520 207 pollintervall 1;
+#X msg 542 229 close;
+#X msg 563 250 open 1;
+#X text 581 228 Close Serial port;
+#X msg 726 413 devicename /dev/ttyS1;
+#X obj 190 72 hsl 128 15 0 255 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
-#X text 550 249 Open serial port by number;
-#X text 804 413 open the serial port by name;
-#X msg 606 353 dtr \$1;
-#X obj 575 354 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+#X text 610 249 Open serial port by number;
+#X text 879 413 open the serial port by name;
+#X msg 666 353 dtr \$1;
+#X obj 635 354 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
-#X obj 595 374 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -258113
+#X obj 655 374 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -258113
-1 0 1;
-#X msg 626 373 rts \$1;
-#X text 655 352 dtr output;
-#X text 675 372 rts output;
-#X msg 367 300 help;
-#X msg 585 332 verbose \$1;
-#X obj 554 334 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+#X msg 686 373 rts \$1;
+#X text 715 352 dtr output;
+#X text 735 372 rts output;
+#X msg 413 320 help;
+#X msg 645 332 verbose \$1;
+#X obj 614 334 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
-#X text 560 206 set poll interval for read in ms;
-#X msg 321 254 info;
-#X floatatom 569 527 10 0 0 1 baud - -;
-#X floatatom 644 568 3 0 0 3 parity - -;
-#X floatatom 669 568 3 0 0 2 stop - -;
-#X floatatom 694 567 3 0 0 3 data - -;
-#X floatatom 770 529 3 0 0 0 port - -;
-#X msg 544 291 devices;
-#X obj 141 74 % 255;
-#X floatatom 179 91 5 0 0 0 - - -;
-#X text 602 290 print available devices (wait for it...);
-#X obj 142 113 key;
-#X obj 170 130 sel 0;
-#X floatatom 249 147 4 0 0 0 ascii - -;
-#X msg 524 271 open 0;
-#X obj 719 533 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699
+#X text 629 206 set poll interval for read in ms;
+#X msg 367 274 info;
+#X floatatom 629 527 10 0 0 1 baud - -, f 10;
+#X floatatom 725 604 3 0 0 3 parity - -, f 3;
+#X floatatom 757 604 3 0 0 2 stop - -, f 3;
+#X floatatom 789 603 3 0 0 3 data - -, f 3;
+#X floatatom 885 529 3 0 0 0 port - -, f 3;
+#X msg 604 291 devices;
+#X obj 187 94 % 255;
+#X floatatom 225 111 5 0 0 0 - - -, f 5;
+#X text 662 290 print available devices (wait for it...);
+#X obj 183 133 key;
+#X obj 211 150 sel 0;
+#X floatatom 290 167 4 0 0 0 ascii - -, f 4;
+#X msg 584 271 open 0;
+#X obj 821 533 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699
-1 0 1;
-#X obj 745 549 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699
+#X obj 853 549 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699
-1 0 1;
-#X text 508 567 serial packet format:;
-#X text 660 517 handshaking:;
-#X text 466 599 flow control inputs:;
-#X obj 594 599 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1
+#X text 574 603 serial packet format:;
+#X text 762 517 handshaking:;
+#X text 533 552 flow control inputs:;
+#X obj 661 552 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1
0 1;
-#X obj 619 599 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1
+#X obj 693 552 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1
0 1;
-#N canvas 307 43 789 479 bauds 0;
+#N canvas 307 50 789 479 bauds 0;
#X msg 319 274 baud 57600;
#X msg 357 312 baud 230400;
#X msg 338 293 baud 115200;
@@ -100,10 +98,10 @@
#X text 519 298 gives 14400 baud instead of 38400;
#X text 517 284 "setserial /dev/ttyS0 spd_cust divisor 8";
#X msg 419 163 115200;
-#X floatatom 392 104 7 1 115200 1 divisor - -;
+#X floatatom 392 104 7 1 115200 1 divisor - -, f 7;
#X obj 431 192 / 1;
#X obj 392 123 sel 0;
-#X floatatom 431 212 7 0 0 0 - - -;
+#X floatatom 431 212 7 0 0 0 - - -, f 7;
#X text 482 103 (1-115200);
#X obj 419 143 t b f;
#X text 390 86 On Windows some other baud rates might work:;
@@ -134,52 +132,69 @@
#X connect 32 0 24 0;
#X connect 34 0 28 0;
#X connect 34 1 30 1;
-#X restore 314 37 pd bauds;
-#X msg 420 167 xonxoff \$1;
-#X obj 387 167 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+#X restore 374 37 pd bauds;
+#X msg 480 167 xonxoff \$1;
+#X obj 447 167 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
-#X msg 440 187 rtscts \$1;
-#X obj 408 187 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+#X msg 500 187 rtscts \$1;
+#X obj 468 187 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
#X text 17 -4 comport: a serial port interface;
-#X msg 243 176 13;
-#X obj 795 530 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699
+#X msg 289 196 13;
+#X obj 917 530 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699
-1 0 1;
-#X msg 565 312 ports;
-#X obj 820 564 print port_list;
-#X text 611 311 list available ports on right outlet;
-#X msg 275 208 48 49 50 51 52 53 54 55 56 57;
-#X text 137 207 send a list of bytes:;
-#X msg 295 228 print hello_world;
-#X text 196 228 send some text:;
-#X msg 646 393 hupcl \$1;
-#X obj 614 394 tgl 15 0 empty empty empty 17 7 0 10 -257985 -258113
+#X msg 625 312 ports;
+#X obj 949 564 print port_list;
+#X text 671 311 list available ports on right outlet;
+#X msg 321 228 48 49 50 51 52 53 54 55 56 57;
+#X text 170 229 send a list of bytes:;
+#X msg 341 248 print hello_world;
+#X text 232 248 send some text:;
+#X msg 706 393 hupcl \$1;
+#X obj 674 394 tgl 15 0 empty empty empty 17 7 0 10 -257985 -258113
-1 0 1;
-#X text 704 386 hang up connection on last close;
-#X text 717 398 (not on Windows);
-#X obj 934 520 print other;
-#X text 205 176 <CR>:;
-#X text 143 254 status list on right outlet:;
-#X text 257 300 print usage info:;
-#X obj 845 527 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699
+#X text 764 386 hang up connection on last close;
+#X text 777 398 (not on Windows);
+#X obj 1046 521 print other;
+#X text 251 196 <CR>:;
+#X text 167 274 status list on right outlet:;
+#X text 290 320 print usage info:;
+#X obj 981 527 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699
-1 0 1;
-#X msg 452 110 1;
-#X msg 482 110 1.5;
-#X msg 513 110 2;
-#X text 444 127 number of stopbits (Windows only);
-#X msg 380 127 stopbit \$1;
-#X text 403 86 extra stopbit 1=on \, 0=off (linux \, MacOS);
-#X text 16 30 You can send bytes directly (0-255):;
-#X text 12 112 or from the terminal:;
-#X text 56 420 messages for the bird patch:;
-#X floatatom 870 540 10 0 0 1 rxerrors - -;
-#X obj 569 490 route baud dsr cts parity stop data rtscts xonxoff port
+#X msg 512 110 1;
+#X msg 542 110 1.5;
+#X msg 573 110 2;
+#X text 504 127 number of stopbits (Windows only);
+#X msg 440 127 stopbit \$1;
+#X text 463 86 extra stopbit 1=on \, 0=off (linux \, MacOS);
+#X text 35 53 You can send bytes directly (0-255):;
+#X text 30 133 or from the terminal:;
+#X text 80 441 messages for the bird patch:;
+#X floatatom 1013 540 10 0 0 1 rxerrors - -, f 10;
+#X obj 629 490 route baud dsr cts parity stop data rtscts xonxoff port
open ports hupcl rxerrors;
-#X text 37 526 2006-2010 Martin Peach;
-#X msg 685 433 retries 10;
-#X text 754 432 how many times to retry a lost connection;
-#X text 761 206 (default is 1 tick 10ms);
-#X connect 0 1 94 0;
+#X text 97 526 2006-2010 Martin Peach;
+#X msg 745 433 retries 10;
+#X text 822 432 how many times to retry a lost connection;
+#X text 862 206 (default is 1 tick 10ms);
+#X msg 502 409 break \$1;
+#X obj 502 388 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+-1 0 1;
+#X text 95 511 (C) 1998-2015 IEM Winfried Ritsch GPL (see LICENSE.txt)
+;
+#X obj 107 197 spigot;
+#X obj 146 173 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
+-1 0 1;
+#X text 30 172 ...if this is on;
+#X text 562 409 (not on Windows);
+#X obj 502 365 delay 50;
+#X obj 470 339 t b b;
+#X obj 470 318 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X floatatom 555 341 5 0 0 0 - - -, f 5;
+#X text 522 388 send break;
+#X text 488 318 send 50ms break;
+#X connect 0 1 93 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 5 0 0 0;
@@ -193,48 +208,57 @@ open ports hupcl rxerrors;
#X connect 21 0 17 0;
#X connect 22 0 17 0;
#X connect 24 0 17 0;
-#X connect 26 0 46 0;
-#X connect 29 0 17 0;
-#X connect 30 0 29 0;
-#X connect 31 0 32 0;
-#X connect 32 0 17 0;
-#X connect 35 0 0 0;
-#X connect 36 0 17 0;
-#X connect 37 0 36 0;
-#X connect 39 0 0 0;
-#X connect 45 0 17 0;
-#X connect 46 0 0 0;
-#X connect 46 0 47 0;
-#X connect 49 0 50 0;
-#X connect 50 1 51 0;
-#X connect 50 1 0 0;
-#X connect 52 0 17 0;
-#X connect 61 0 17 0;
-#X connect 62 0 61 0;
-#X connect 63 0 17 0;
-#X connect 64 0 63 0;
-#X connect 66 0 0 0;
-#X connect 68 0 17 0;
-#X connect 71 0 0 0;
-#X connect 73 0 0 0;
-#X connect 75 0 17 0;
-#X connect 76 0 75 0;
-#X connect 84 0 88 0;
-#X connect 85 0 88 0;
-#X connect 86 0 88 0;
-#X connect 88 0 17 0;
-#X connect 94 0 40 0;
-#X connect 94 1 58 0;
-#X connect 94 2 59 0;
-#X connect 94 3 41 0;
-#X connect 94 4 42 0;
-#X connect 94 5 43 0;
-#X connect 94 6 53 0;
-#X connect 94 7 54 0;
-#X connect 94 8 44 0;
-#X connect 94 9 67 0;
-#X connect 94 10 69 0;
-#X connect 94 11 83 0;
-#X connect 94 12 93 0;
-#X connect 94 13 79 0;
-#X connect 96 0 17 0;
+#X connect 25 0 45 0;
+#X connect 28 0 17 0;
+#X connect 29 0 28 0;
+#X connect 30 0 31 0;
+#X connect 31 0 17 0;
+#X connect 34 0 0 0;
+#X connect 35 0 17 0;
+#X connect 36 0 35 0;
+#X connect 38 0 0 0;
+#X connect 44 0 17 0;
+#X connect 45 0 46 0;
+#X connect 45 0 101 0;
+#X connect 48 0 49 0;
+#X connect 49 1 50 0;
+#X connect 49 1 101 0;
+#X connect 51 0 17 0;
+#X connect 60 0 17 0;
+#X connect 61 0 60 0;
+#X connect 62 0 17 0;
+#X connect 63 0 62 0;
+#X connect 65 0 0 0;
+#X connect 67 0 17 0;
+#X connect 70 0 0 0;
+#X connect 72 0 0 0;
+#X connect 74 0 17 0;
+#X connect 75 0 74 0;
+#X connect 83 0 87 0;
+#X connect 84 0 87 0;
+#X connect 85 0 87 0;
+#X connect 87 0 17 0;
+#X connect 93 0 39 0;
+#X connect 93 1 57 0;
+#X connect 93 2 58 0;
+#X connect 93 3 40 0;
+#X connect 93 4 41 0;
+#X connect 93 5 42 0;
+#X connect 93 6 52 0;
+#X connect 93 7 53 0;
+#X connect 93 8 43 0;
+#X connect 93 9 66 0;
+#X connect 93 10 68 0;
+#X connect 93 11 82 0;
+#X connect 93 12 92 0;
+#X connect 93 13 78 0;
+#X connect 95 0 17 0;
+#X connect 98 0 0 0;
+#X connect 99 0 98 0;
+#X connect 101 0 0 0;
+#X connect 102 0 101 1;
+#X connect 105 0 99 0;
+#X connect 106 0 99 0;
+#X connect 106 1 105 0;
+#X connect 107 0 106 0;
+#X connect 108 0 105 1;
diff --git a/comport/comport.c b/comport/comport.c
index 55117b5..3db3541 100644
--- a/comport/comport.c
+++ b/comport/comport.c
@@ -240,6 +240,7 @@ static float set_parity(t_comport *x,int n);
static float set_stopflag(t_comport *x, t_float nr);
static int set_ctsrts(t_comport *x, int nr);
static int set_dtr(t_comport *x, int nr);
+static int set_break(t_comport *x, int on);
static int set_rts(t_comport *x, int nr);
static int set_xonxoff(t_comport *x, int nr);
static int set_serial(t_comport *x);
@@ -269,6 +270,7 @@ static void comport_stopbit(t_comport *x,t_floatarg f);
static void comport_rtscts(t_comport *x,t_floatarg f);
static void comport_dtr(t_comport *x,t_floatarg f);
static void comport_rts(t_comport *x,t_floatarg f);
+static void comport_break(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);
@@ -407,6 +409,19 @@ static int set_rts(t_comport *x, int nr)
return -1; /* didn't work, GetLastError tells why */
}
+static int set_break(t_comport *x, int on)
+{
+ HANDLE fd = x->comhandle;
+ BOOL status;
+ DWORD dwFunc = (on==0)?CLRBREAK:SETBREAK;
+
+ if (fd == INVALID_HANDLE_VALUE) return -1;
+
+ status = EscapeCommFunction(fd, dwFunc);
+ if (status != 0) return nr;
+ return -1; /* didn't work, GetLastError tells why */
+}
+
static int set_xonxoff(t_comport *x, int nr)
{
/* x->dcb.fTXContinueOnXoff = FALSE; XOFF continues Tx */
@@ -838,6 +853,21 @@ static int set_hupcl(t_comport *x, int nr)
return 1;
}
+static int set_break(t_comport *x, int on)
+{
+ int fd = x->comhandle;
+ int status;
+
+ if (fd == INVALID_HANDLE_VALUE) return -1;
+
+ if (on == 0)
+ status = ioctl(fd, TIOCCBRK); // Turn break off, that is, stop sending zero bits.
+ else
+ status = ioctl(fd, TIOCSBRK); // Turn break on, that is, start sending zero bits.
+
+ return ((status < 0)? status: (on != 0));
+}
+
static int open_serial(unsigned int com_num, t_comport *x)
{
int fd;
@@ -1556,6 +1586,30 @@ static void comport_rts(t_comport *x,t_floatarg f)
#endif
}
+static void comport_break(t_comport *x,t_floatarg f)
+{
+ f = set_break(x,f);
+
+ if(x->comhandle == INVALID_HANDLE_VALUE)return;
+
+ if(f < 0)
+ {
+ pd_error(x,"[comport] ** ERROR ** could not set break of device %s\n",
+#ifdef _WIN32
+ &x->serial_device->s_name[4]);
+#else
+ x->serial_device->s_name);
+#endif
+ }
+ else if(x->verbose > 0)
+ post("[comport] set break of %s to %g\n",
+#ifdef _WIN32
+ &x->serial_device->s_name[4], f);
+#else
+ x->serial_device->s_name, f);
+#endif
+}
+
static void comport_xonxoff(t_comport *x,t_floatarg f)
{
f = set_xonxoff(x,f);
@@ -1946,6 +2000,7 @@ void comport_setup(void)
class_addmethod(comport_class, (t_method)comport_rtscts, gensym("rtscts"), A_FLOAT, 0);
class_addmethod(comport_class, (t_method)comport_dtr, gensym("dtr"), A_FLOAT, 0);
class_addmethod(comport_class, (t_method)comport_rts, gensym("rts"), A_FLOAT, 0);
+ class_addmethod(comport_class, (t_method)comport_break, gensym("break"), A_FLOAT, 0);
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);