instead of just closing a lost connection, retry for a settable number of tries
svn path=/trunk/externals/iem/comport/; revision=16059
This commit is contained in:
parent
17bd34efc3
commit
dcb81d5330
2 changed files with 273 additions and 243 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#N canvas 157 178 1031 627 10;
|
#N canvas 67 105 1015 636 10;
|
||||||
#X obj 488 438 comport 1 9600;
|
#X obj 488 438 comport 1 9600;
|
||||||
#X msg 276 421 66;
|
#X msg 276 421 66;
|
||||||
#X msg 234 421 64;
|
#X msg 234 421 64;
|
||||||
|
|
@ -16,23 +16,20 @@
|
||||||
#X text 467 146 parity 1=even \, -1=odd \, 0=off;
|
#X text 467 146 parity 1=even \, -1=odd \, 0=off;
|
||||||
#X text 363 60 databits 5 \, 6 \, 7 \, 8;
|
#X text 363 60 databits 5 \, 6 \, 7 \, 8;
|
||||||
#X obj 488 412 r comctl;
|
#X obj 488 412 r comctl;
|
||||||
#X obj 674 438 s comctl;
|
#X obj 694 458 s comctl;
|
||||||
#X text 500 166 use handshake xon/off 1=on 0=off;
|
#X text 500 166 use handshake xon/off 1=on 0=off;
|
||||||
#X text 512 186 cts/rts hardwarehandshake 1=on 0=off;
|
#X text 512 186 cts/rts hardwarehandshake 1=on 0=off;
|
||||||
#X msg 460 207 pollintervall 1;
|
#X msg 460 207 pollintervall 1;
|
||||||
#X text 761 206 (default is 1 tick 1ms);
|
|
||||||
#X msg 482 229 close;
|
#X msg 482 229 close;
|
||||||
#X msg 503 250 open 1;
|
#X msg 503 250 open 1;
|
||||||
#X text 521 228 Close Serial port;
|
#X text 521 228 Close Serial port;
|
||||||
#X msg 666 413 devicename /dev/ttyS1;
|
#X msg 666 413 devicename /dev/ttyS1;
|
||||||
#X text 742 432 Danger !!! you can open every file in your system and
|
|
||||||
maybe if suid is root damage the system.;
|
|
||||||
#X text 35 511 (C) 1998-2005 IEM Winfried Ritsch GPL (see LICENSE.txt)
|
#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
|
#X obj 135 50 hsl 128 15 0 255 0 0 empty empty empty -2 -6 0 8 -262144
|
||||||
-1 -1 0 1;
|
-1 -1 0 1;
|
||||||
#X text 550 249 Open serial port by number;
|
#X text 550 249 Open serial port by number;
|
||||||
#X text 878 413 open the serial port by name;
|
#X text 804 413 open the serial port by name;
|
||||||
#X msg 606 353 dtr \$1;
|
#X msg 606 353 dtr \$1;
|
||||||
#X obj 575 354 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
|
#X obj 575 354 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
|
|
@ -47,11 +44,11 @@ maybe if suid is root damage the system.;
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
#X text 560 206 set poll interval for read in ms;
|
#X text 560 206 set poll interval for read in ms;
|
||||||
#X msg 321 254 info;
|
#X msg 321 254 info;
|
||||||
#X floatatom 569 497 10 0 0 1 baud - -;
|
#X floatatom 569 527 10 0 0 1 baud - -;
|
||||||
#X floatatom 644 538 3 0 0 3 parity - -;
|
#X floatatom 644 568 3 0 0 3 parity - -;
|
||||||
#X floatatom 669 538 3 0 0 2 stop - -;
|
#X floatatom 669 568 3 0 0 2 stop - -;
|
||||||
#X floatatom 694 537 3 0 0 3 data - -;
|
#X floatatom 694 567 3 0 0 3 data - -;
|
||||||
#X floatatom 770 499 3 0 0 0 port - -;
|
#X floatatom 770 529 3 0 0 0 port - -;
|
||||||
#X msg 544 291 devices;
|
#X msg 544 291 devices;
|
||||||
#X obj 141 74 % 255;
|
#X obj 141 74 % 255;
|
||||||
#X floatatom 179 91 5 0 0 0 - - -;
|
#X floatatom 179 91 5 0 0 0 - - -;
|
||||||
|
|
@ -60,16 +57,16 @@ maybe if suid is root damage the system.;
|
||||||
#X obj 170 130 sel 0;
|
#X obj 170 130 sel 0;
|
||||||
#X floatatom 249 147 4 0 0 0 ascii - -;
|
#X floatatom 249 147 4 0 0 0 ascii - -;
|
||||||
#X msg 524 271 open 0;
|
#X msg 524 271 open 0;
|
||||||
#X obj 719 503 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699
|
#X obj 719 533 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
#X obj 745 519 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699
|
#X obj 745 549 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
#X text 508 537 serial packet format:;
|
#X text 508 567 serial packet format:;
|
||||||
#X text 660 487 handshaking:;
|
#X text 660 517 handshaking:;
|
||||||
#X text 466 569 flow control inputs:;
|
#X text 466 599 flow control inputs:;
|
||||||
#X obj 594 569 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1
|
#X obj 594 599 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1
|
||||||
0 1;
|
0 1;
|
||||||
#X obj 619 569 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1
|
#X obj 619 599 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1
|
||||||
0 1;
|
0 1;
|
||||||
#N canvas 307 43 789 479 bauds 0;
|
#N canvas 307 43 789 479 bauds 0;
|
||||||
#X msg 319 274 baud 57600;
|
#X msg 319 274 baud 57600;
|
||||||
|
|
@ -146,10 +143,10 @@ maybe if suid is root damage the system.;
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
#X text 17 -4 comport: a serial port interface;
|
#X text 17 -4 comport: a serial port interface;
|
||||||
#X msg 243 176 13;
|
#X msg 243 176 13;
|
||||||
#X obj 795 500 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699
|
#X obj 795 530 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699
|
||||||
-1 1 1;
|
-1 0 1;
|
||||||
#X msg 565 312 ports;
|
#X msg 565 312 ports;
|
||||||
#X obj 820 534 print port_list;
|
#X obj 820 564 print port_list;
|
||||||
#X text 611 311 list available ports on right outlet;
|
#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 msg 275 208 48 49 50 51 52 53 54 55 56 57;
|
||||||
#X text 137 207 send a list of bytes:;
|
#X text 137 207 send a list of bytes:;
|
||||||
|
|
@ -160,12 +157,12 @@ maybe if suid is root damage the system.;
|
||||||
-1 0 1;
|
-1 0 1;
|
||||||
#X text 704 386 hang up connection on last close;
|
#X text 704 386 hang up connection on last close;
|
||||||
#X text 717 398 (not on Windows);
|
#X text 717 398 (not on Windows);
|
||||||
#X obj 934 490 print other;
|
#X obj 934 520 print other;
|
||||||
#X text 205 176 <CR>:;
|
#X text 205 176 <CR>:;
|
||||||
#X text 143 254 status list on right outlet:;
|
#X text 143 254 status list on right outlet:;
|
||||||
#X text 257 300 print usage info:;
|
#X text 257 300 print usage info:;
|
||||||
#X obj 845 497 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699
|
#X obj 845 527 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699
|
||||||
-1 1 1;
|
-1 0 1;
|
||||||
#X msg 452 110 1;
|
#X msg 452 110 1;
|
||||||
#X msg 482 110 1.5;
|
#X msg 482 110 1.5;
|
||||||
#X msg 513 110 2;
|
#X msg 513 110 2;
|
||||||
|
|
@ -175,11 +172,14 @@ maybe if suid is root damage the system.;
|
||||||
#X text 16 30 You can send bytes directly (0-255):;
|
#X text 16 30 You can send bytes directly (0-255):;
|
||||||
#X text 12 112 or from the terminal:;
|
#X text 12 112 or from the terminal:;
|
||||||
#X text 56 420 messages for the bird patch:;
|
#X text 56 420 messages for the bird patch:;
|
||||||
#X floatatom 870 510 10 0 0 1 rxerrors - -;
|
#X floatatom 870 540 10 0 0 1 rxerrors - -;
|
||||||
#X obj 569 460 route baud dsr cts parity stop data rtscts xonxoff port
|
#X obj 569 490 route baud dsr cts parity stop data rtscts xonxoff port
|
||||||
open ports hupcl rxerrors;
|
open ports hupcl rxerrors;
|
||||||
#X text 37 526 2006-2010 Martin Peach;
|
#X text 37 526 2006-2010 Martin Peach;
|
||||||
#X connect 0 1 96 0;
|
#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 connect 1 0 0 0;
|
#X connect 1 0 0 0;
|
||||||
#X connect 2 0 0 0;
|
#X connect 2 0 0 0;
|
||||||
#X connect 5 0 0 0;
|
#X connect 5 0 0 0;
|
||||||
|
|
@ -190,50 +190,51 @@ open ports hupcl rxerrors;
|
||||||
#X connect 13 0 17 0;
|
#X connect 13 0 17 0;
|
||||||
#X connect 16 0 0 0;
|
#X connect 16 0 0 0;
|
||||||
#X connect 20 0 17 0;
|
#X connect 20 0 17 0;
|
||||||
|
#X connect 21 0 17 0;
|
||||||
#X connect 22 0 17 0;
|
#X connect 22 0 17 0;
|
||||||
#X connect 23 0 17 0;
|
#X connect 24 0 17 0;
|
||||||
#X connect 25 0 17 0;
|
#X connect 26 0 46 0;
|
||||||
#X connect 28 0 48 0;
|
#X connect 29 0 17 0;
|
||||||
#X connect 31 0 17 0;
|
#X connect 30 0 29 0;
|
||||||
#X connect 32 0 31 0;
|
#X connect 31 0 32 0;
|
||||||
#X connect 33 0 34 0;
|
#X connect 32 0 17 0;
|
||||||
#X connect 34 0 17 0;
|
#X connect 35 0 0 0;
|
||||||
#X connect 37 0 0 0;
|
#X connect 36 0 17 0;
|
||||||
#X connect 38 0 17 0;
|
#X connect 37 0 36 0;
|
||||||
#X connect 39 0 38 0;
|
#X connect 39 0 0 0;
|
||||||
#X connect 41 0 0 0;
|
#X connect 45 0 17 0;
|
||||||
#X connect 47 0 17 0;
|
#X connect 46 0 0 0;
|
||||||
#X connect 48 0 0 0;
|
#X connect 46 0 47 0;
|
||||||
#X connect 48 0 49 0;
|
#X connect 49 0 50 0;
|
||||||
#X connect 51 0 52 0;
|
#X connect 50 1 51 0;
|
||||||
#X connect 52 1 53 0;
|
#X connect 50 1 0 0;
|
||||||
#X connect 52 1 0 0;
|
#X connect 52 0 17 0;
|
||||||
#X connect 54 0 17 0;
|
#X connect 61 0 17 0;
|
||||||
|
#X connect 62 0 61 0;
|
||||||
#X connect 63 0 17 0;
|
#X connect 63 0 17 0;
|
||||||
#X connect 64 0 63 0;
|
#X connect 64 0 63 0;
|
||||||
#X connect 65 0 17 0;
|
#X connect 66 0 0 0;
|
||||||
#X connect 66 0 65 0;
|
#X connect 68 0 17 0;
|
||||||
#X connect 68 0 0 0;
|
#X connect 71 0 0 0;
|
||||||
#X connect 70 0 17 0;
|
|
||||||
#X connect 73 0 0 0;
|
#X connect 73 0 0 0;
|
||||||
#X connect 75 0 0 0;
|
#X connect 75 0 17 0;
|
||||||
#X connect 77 0 17 0;
|
#X connect 76 0 75 0;
|
||||||
#X connect 78 0 77 0;
|
#X connect 84 0 88 0;
|
||||||
#X connect 86 0 90 0;
|
#X connect 85 0 88 0;
|
||||||
#X connect 87 0 90 0;
|
#X connect 86 0 88 0;
|
||||||
#X connect 88 0 90 0;
|
#X connect 88 0 17 0;
|
||||||
#X connect 90 0 17 0;
|
#X connect 94 0 40 0;
|
||||||
#X connect 96 0 42 0;
|
#X connect 94 1 58 0;
|
||||||
#X connect 96 1 60 0;
|
#X connect 94 2 59 0;
|
||||||
#X connect 96 2 61 0;
|
#X connect 94 3 41 0;
|
||||||
#X connect 96 3 43 0;
|
#X connect 94 4 42 0;
|
||||||
#X connect 96 4 44 0;
|
#X connect 94 5 43 0;
|
||||||
#X connect 96 5 45 0;
|
#X connect 94 6 53 0;
|
||||||
#X connect 96 6 55 0;
|
#X connect 94 7 54 0;
|
||||||
#X connect 96 7 56 0;
|
#X connect 94 8 44 0;
|
||||||
#X connect 96 8 46 0;
|
#X connect 94 9 67 0;
|
||||||
#X connect 96 9 69 0;
|
#X connect 94 10 69 0;
|
||||||
#X connect 96 10 71 0;
|
#X connect 94 11 83 0;
|
||||||
#X connect 96 11 85 0;
|
#X connect 94 12 93 0;
|
||||||
#X connect 96 12 95 0;
|
#X connect 94 13 79 0;
|
||||||
#X connect 96 13 81 0;
|
#X connect 96 0 17 0;
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ typedef struct comport
|
||||||
short rxerrors; /* holds the rx line errors */
|
short rxerrors; /* holds the rx line errors */
|
||||||
t_clock *x_clock;
|
t_clock *x_clock;
|
||||||
int x_hit;
|
int x_hit;
|
||||||
|
int x_retries;
|
||||||
|
int x_retry_count;
|
||||||
double x_deltime;
|
double x_deltime;
|
||||||
int verbose;
|
int verbose;
|
||||||
t_outlet *x_data_outlet;
|
t_outlet *x_data_outlet;
|
||||||
|
|
@ -230,6 +232,7 @@ static long baudratetable[] =
|
||||||
t_class *comport_class;
|
t_class *comport_class;
|
||||||
|
|
||||||
static void comport_pollintervall(t_comport *x, t_floatarg g);
|
static void comport_pollintervall(t_comport *x, t_floatarg g);
|
||||||
|
static void comport_retries(t_comport *x, t_floatarg g);
|
||||||
static void comport_tick(t_comport *x);
|
static void comport_tick(t_comport *x);
|
||||||
static float set_baudrate(t_comport *x, t_float baud);
|
static float set_baudrate(t_comport *x, t_float baud);
|
||||||
static float set_bits(t_comport *x, int nr);
|
static float set_bits(t_comport *x, int nr);
|
||||||
|
|
@ -938,6 +941,8 @@ static int open_serial(unsigned int com_num, t_comport *x)
|
||||||
set_xonxoff(x, x->xonxoff); /* (IXON | IXOFF | IXANY) */
|
set_xonxoff(x, x->xonxoff); /* (IXON | IXOFF | IXANY) */
|
||||||
set_baudrate(x, *baud);
|
set_baudrate(x, *baud);
|
||||||
|
|
||||||
|
x->x_retry_count = 0; /* reset retry counter */
|
||||||
|
|
||||||
if(tcsetattr(fd, TCSAFLUSH, new) != -1)
|
if(tcsetattr(fd, TCSAFLUSH, new) != -1)
|
||||||
{
|
{
|
||||||
post("[comport] opened serial line device %d (%s)\n",
|
post("[comport] opened serial line device %d (%s)\n",
|
||||||
|
|
@ -1012,6 +1017,12 @@ static void comport_pollintervall(t_comport *x, t_floatarg g)
|
||||||
x->x_deltime = g;
|
x->x_deltime = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void comport_retries(t_comport *x, t_floatarg g)
|
||||||
|
{
|
||||||
|
if (g < 0) g = 0;
|
||||||
|
x->x_retries = g;
|
||||||
|
}
|
||||||
|
|
||||||
static void comport_tick(t_comport *x)
|
static void comport_tick(t_comport *x)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
@ -1085,9 +1096,25 @@ static void comport_tick(t_comport *x)
|
||||||
* otherwise there is a race condition when the serial
|
* otherwise there is a race condition when the serial
|
||||||
* port gets interrupted, like if the USB gets yanked
|
* port gets interrupted, like if the USB gets yanked
|
||||||
* out or a bluetooth connection drops */
|
* out or a bluetooth connection drops */
|
||||||
pd_error(x, "[comport]: lost connection to port %i (%s)!",
|
if(x->x_retry_count < x->x_retries)
|
||||||
x->comport, x->serial_device->s_name);
|
{
|
||||||
comport_close(x);
|
t_atom retrying_atom;
|
||||||
|
SETFLOAT(&retrying_atom, x->x_retry_count);
|
||||||
|
outlet_anything(x->x_status_outlet, gensym("retrying"), 1, &retrying_atom);
|
||||||
|
|
||||||
|
pd_error(x, "[comport]: lost connection to port %i (%s), retrying...",
|
||||||
|
x->comport, x->serial_device->s_name);
|
||||||
|
if (!x->x_hit)
|
||||||
|
clock_delay(x->x_clock, 1000); /* retry every second */
|
||||||
|
x->x_retry_count++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pd_error(x, "[comport]: Giving up on port %i (%s)!",
|
||||||
|
x->comport, x->serial_device->s_name);
|
||||||
|
comport_close(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
whicherr = errno;
|
whicherr = errno;
|
||||||
|
|
@ -1149,7 +1176,7 @@ endsendevent:
|
||||||
#endif /*_WIN32*/
|
#endif /*_WIN32*/
|
||||||
x->x_outbuf_wr_index = 0; /* for now we just drop anything that didn't send */
|
x->x_outbuf_wr_index = 0; /* for now we just drop anything that didn't send */
|
||||||
}
|
}
|
||||||
if (!x->x_hit) clock_delay(x->x_clock, x->x_deltime); /* default 1 ms */
|
if (!x->x_hit) clock_delay(x->x_clock, x->x_deltime); /* default 10 ms */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1321,6 +1348,7 @@ allows COM port numbers to be specified. */
|
||||||
* going to give the data as fast as 1ms polling with a lot less
|
* going to give the data as fast as 1ms polling with a lot less
|
||||||
* CPU time wasted. */
|
* CPU time wasted. */
|
||||||
x->x_deltime = 10;
|
x->x_deltime = 10;
|
||||||
|
x->x_retries = 10;
|
||||||
x->x_clock = clock_new(x, (t_method)comport_tick);
|
x->x_clock = clock_new(x, (t_method)comport_tick);
|
||||||
|
|
||||||
clock_delay(x->x_clock, x->x_deltime);
|
clock_delay(x->x_clock, x->x_deltime);
|
||||||
|
|
@ -1926,6 +1954,7 @@ void comport_setup(void)
|
||||||
class_addmethod(comport_class, (t_method)comport_devicename, gensym("devicename"), A_SYMBOL, 0);
|
class_addmethod(comport_class, (t_method)comport_devicename, gensym("devicename"), A_SYMBOL, 0);
|
||||||
class_addmethod(comport_class, (t_method)comport_print, gensym("print"), A_GIMME, 0);
|
class_addmethod(comport_class, (t_method)comport_print, gensym("print"), A_GIMME, 0);
|
||||||
class_addmethod(comport_class, (t_method)comport_pollintervall, gensym("pollintervall"), A_FLOAT, 0);
|
class_addmethod(comport_class, (t_method)comport_pollintervall, gensym("pollintervall"), A_FLOAT, 0);
|
||||||
|
class_addmethod(comport_class, (t_method)comport_retries, gensym("retries"), A_FLOAT, 0);
|
||||||
class_addmethod(comport_class, (t_method)comport_verbose, gensym("verbose"), A_FLOAT, 0);
|
class_addmethod(comport_class, (t_method)comport_verbose, gensym("verbose"), A_FLOAT, 0);
|
||||||
class_addmethod(comport_class, (t_method)comport_help, gensym("help"), 0);
|
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_info, gensym("info"), 0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue