Debian Codegraph @

debian/patches/usb_38400.patch

raw symbols SCIP
1 From: Jan Niehusmann <[email protected]>
2 Subject: Patch to fix setting USB-serial adapters to 38400 bps
3 Bug-Debian: http://bugs.debian.org/740098
4 Forwarded: no
5 Description: The following patch should fix the reported issue.
6 .
7 On serial ports not supporting the TIOCGSERIAL/TIOCSSERIAL mechanism,
8 this still means that the custom baud rates do not work, but at least
9 38400 works, again.
10 .
11 Perhaps an even better fix would be switching to the newer termios2 API,
12 as described here:
13 https://mail.python.org/pipermail/python-list/2012-October/633871.html
14 .
15 That API allows setting custom baud rates on the USB serial adapters I
16 have tested, where TIOCGSERIAL/TIOCSSERIAL was not supported.
17 .
18 But unfortunately, termios2 is not available through glibc, so one would
19 need to call linux-specific ioctls directly, which wouldn't be portable
20 at all, and I don't know how it interacts with the BSD / Hurd ports.
21 .
22 Therefore this is the minimal fix, for now.
23
24 --- a/src/SerialImp.c
25 +++ b/src/SerialImp.c
26 @@ -872,10 +872,14 @@
27 out and select baud rates 38400 then 28800 then 38400, you will get
28 a final baud rate of 28800 because you did not update the divisor.
29
30 + However, if the serial port doesn't support TIOCGSERIAL or custom speeds,
31 + don't fail: In this case, just use B38400 and assume that there is no way
32 + to set a custom speed on this port.
33 +
34 See the next ifdef below for the divisor.
35 */
36 #if defined(TIOCGSERIAL)
37 - if ( cspeed == B38400 )
38 + if ( cspeed == B38400 && ioctl( fd, TIOCGSERIAL, &sstruct ) == 0 )
39 cspeed = 38400;
40 #endif /* TIOCGSERIAL */
41 if( cfsetispeed( &ttyset, cspeed ) < 0 ||
42 @@ -905,10 +909,9 @@
43 return(1);
44 }
45 sstruct.custom_divisor = ( sstruct.baud_base/cspeed );
46 - cspeed = B38400;
47 #endif /* TIOCGSERIAL */
48 - if( cfsetispeed( &ttyset, cspeed ) < 0 ||
49 - cfsetospeed( &ttyset, cspeed ) < 0 )
50 + if( cfsetispeed( &ttyset, B38400 ) < 0 ||
51 + cfsetospeed( &ttyset, B38400 ) < 0 )
52 {
53 /* OK, we tried everything */
54 report( "nativeSetSerialPortParams: Cannot Set Speed\n" );
55 @@ -916,8 +919,11 @@
56 }
57 #if defined(TIOCSSERIAL)
58 /* It is assumed Win32 does this for us */
59 + /* Ignore errors if the target speed is 38400: In this case,
60 + * just assume TIOCSSERIAL is not supported and custom speeds are
61 + * not available. */
62 if ( sstruct.baud_base < 1 ||
63 - ioctl( fd, TIOCSSERIAL, &sstruct ) < 0 )
64 + ioctl( fd, TIOCSSERIAL, &sstruct ) < 0 && cspeed != 38400 )
65 {
66 return( 1 );
67 }