#15 Allow selection of nonstandard baudrates on Linux

closed-duplicate
nobody
None
5
2008-08-21
2008-08-10
Jeff Epler
No

Linux supports a pair of ioctls, TIOCGSERIAL and TIOCSSERIAL. Using these ioctls, baudrates without predefined symbols like B38400 can be used. On some USB serial adapters, high rates like 1Mbps are available.

With my patch, serialposix.Serial._reconfigurePort will prefer TIOCxSERIAL for baud rate configuration even if the requested baud rate is a standard rate. It will reject baud rates that have more than 1% error.

This patch on pyserial-2.2 is lightly tested on 64-bit Ubuntu 8.08 with an Arduino Diecimila (FT232 USB interface chip). It successfully communicates both at 38400 baud (a standard rate) and 1000000 baud (a nonstandard rate).

I do not have access to any non-Linux systems to test this patch. However, when TIOCxSERIAL is not avaiable in the FCNTL module, my new code should have no effect.

Thank you for considering this patch for inclusion.

Discussion

  • Jeff Epler

    Jeff Epler - 2008-08-10

    Logged In: YES
    user_id=2772
    Originator: YES

    I'm unsure what to do about the .BAUDRATE attribute in the case that TIOCxSERIAL is supported, and about valid baud rates in general.

    The baud rates available are not the same as all the integer divisors of baud_base. There may be a minimum and maximum divisor, and some divisors may be forbidden. For instance, in the FT232BM reports a baud_base of 24000000 but the highest baudrate available is actually 3000000 and the lowest is 183.1. (the available baud rates apparently correspond to divisors 8, 12, 16, 17, ..., 131078, 131079)

    When an invalid divisor is selected, TIOCSSERIAL doesn't signal an error and TIOCGSERIAL reads back the invalid custom_divisor.

     
  • Chris Liechti

    Chris Liechti - 2008-08-21
    • status: open --> closed-duplicate
     
  • Chris Liechti

    Chris Liechti - 2008-08-21

    Logged In: YES
    user_id=403744
    Originator: NO

    already implemented in 2.4, see also
    https://sourceforge.net/tracker/index.php?func=detail&aid=1783159&group_id=46487&atid=446304

    but thanks for your interest :-)

    as for your concern that illegal settings are not detected, this is true. if the device accepts setting the baud rate without error, pyserial will continue happily. i guess that this is not a big issue. devices with odd baud rates are rare. and if it fails to set the baud rate correctly, i'd expect that any halfway smart application detects that the communication isn't working (let's hope their protocol has a checksum ;-).

    the BAUDRATE array was an idea, so that applications can use this if it wants to display a list. but it is impossible to create a list based on the actual, opened, serial port for all supported platforms. so you application can fill a GUI baud rate selection with the list, but it would be smart to allow the user enter any baud rate manually if all possibilities should be open. but i'd only expect that from terminal programs. programs communicating with a dedicated device should get a long with hardcoding a baud rate or two and the end user isn't bothered with these details.

     
  • Chris Liechti

    Chris Liechti - 2008-08-21

    Logged In: YES
    user_id=403744
    Originator: NO

    already implemented in 2.4, see also
    https://sourceforge.net/tracker/index.php?func=detail&aid=1783159&group_id=46487&atid=446304

    but thanks for your interest :-)

    as for your concern that illegal settings are not detected, this is true. if the device accepts setting the baud rate without error, pyserial will continue happily. i guess that this is not a big issue. devices with odd baud rates are rare. and if it fails to set the baud rate correctly, i'd expect that any halfway smart application detects that the communication isn't working (let's hope their protocol has a checksum ;-).

    the BAUDRATE array was an idea, so that applications can use this if it wants to display a list. but it is impossible to create a list based on the actual, opened, serial port for all supported platforms. so you application can fill a GUI baud rate selection with the list, but it would be smart to allow the user enter any baud rate manually if all possibilities should be open. but i'd only expect that from terminal programs. programs communicating with a dedicated device should get a long with hardcoding a baud rate or two and the end user isn't bothered with these details.

     
  • Jeff Epler

    Jeff Epler - 2008-08-21

    Logged In: YES
    user_id=2772
    Originator: YES

    great, thanks!

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks