Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to set 250000 baud rate in pyserial ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
kura...@gmail.com  
View profile  
 More options Oct 25 2012, 7:09 am
Newsgroups: comp.lang.python
From: kura...@gmail.com
Date: Thu, 25 Oct 2012 04:09:56 -0700 (PDT)
Local: Thurs, Oct 25 2012 7:09 am
Subject: How to set 250000 baud rate in pyserial ?
I use Arduino 1280 and Arduino 2560 under Fedora 15.
1280 creates ttyUSB0 port  and can be set at 2500000 successfully.
2560 creates ttyACM0 port and can be only set at speeds from list (no 250000) in pyserial. How to set 250000 to ttyACM0 port?? Need I patch kernel or python?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Grant Edwards  
View profile  
 More options Oct 25 2012, 5:14 pm
Newsgroups: comp.lang.python
From: Grant Edwards <inva...@invalid.invalid>
Date: Thu, 25 Oct 2012 21:14:23 +0000 (UTC)
Local: Thurs, Oct 25 2012 5:14 pm
Subject: Re: How to set 250000 baud rate in pyserial ?
On 2012-10-25, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:

> On Thu, 25 Oct 2012 04:09:56 -0700 (PDT), kura...@gmail.com wrote:

>> I use Arduino 1280 and Arduino 2560 under Fedora 15.  1280 creates
>> ttyUSB0 port and can be set at 2500000 successfully. 2560 creates
>> ttyACM0 port and can be only set at speeds from list (no 250000) in
>> pyserial. How to set 250000 to ttyACM0 port?? Need I patch kernel or
>> python?

> You don't say what error you are receiving but looking at the source
> (serialposix.py) implies that it accepts nearly anything on Linux, and
> relies on the OS returning a success/failure if the value is allowed or
> not.

1) Are you sure it matters?  I've never played with an Arduino board,
   but other stuff I've used that implements a "virtual serial port"
   using a ttyUSB or ttyACM device (e.g. oscilloscope, various Atmel
   eval boards, JTAG interfaces, etc.) didn't have actual UARTs in
   them with real baud rate generators.  You got the same high-speed
   transfers no matter what baud rate you told the tty driver.

2) If you want a non-standard baud rate, there is a termios2 API on
   Linux that allows that (assuming the low-level driver and hardwdare
   support it).  The last time I looked, it wasn't supported by
   pyserial, but you can ask pyserial for the underlying file
   descriptor and do the ioctl manually.  The slightly ugly bit is
   that you'll have to use struct (or maybe ctypes) to handle the
   termios2 "C" structure.

   The behavior of baud rate requests that can't be met exactly is
   probably not very consistent.  IIRC, the recommended approach is
   for the low level driver to pick the closest supported baud, and
   then report the actual baud rate back when you subsequently read
   the termios2 structure. However, I do know of some devices that
   will always report the requested baud rate even if the physical
   baud rate that was selected wasn't exactly the same as the request
   rate.

Here's how you set an arbitrary baud rate in C:

-------------------------arbitrary-baud.c--------------------------
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/termios.h>

int ioctl(int d, int request, ...);

int main(int argc, char *argv[])
{
  struct termios2 t;
  int fd,baud;

  if (argc != 3)
    {
      fprintf(stderr,"usage: %s <device> <baud>\n", argv[0]);
      return 1;
    }

  fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);

  if (fd == -1)
      {
        fprintf(stderr, "error opening %s: %s", argv[1], strerror(errno));
        return 2;
      }

  baud = atoi(argv[2]);

  if (ioctl(fd, TCGETS2, &t))
    {
      perror("TCGETS2");
      return 3;
    }

  t.c_cflag &= ~CBAUD;
  t.c_cflag |= BOTHER;
  t.c_ispeed = baud;
  t.c_ospeed = baud;

  if (ioctl(fd, TCSETS2, &t))
    {
      perror("TCSETS2");
      return 4;
    }

  if (ioctl(fd, TCGETS2, &t))
    {
      perror("TCGETS2");
      return 5;
    }

  printf("actual speed reported %d\n", t.c_ospeed);
  return 0;

}

--------------------------------------------------------------------

--
Grant Edwards               grant.b.edwards
                                  at      
                              gmail.com    


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kura...@gmail.com  
View profile  
 More options Oct 26 2012, 6:01 pm
Newsgroups: comp.lang.python
From: kura...@gmail.com
Date: Fri, 26 Oct 2012 15:01:43 -0700 (PDT)
Local: Fri, Oct 26 2012 6:01 pm
Subject: Re: How to set 250000 baud rate in pyserial ?
Error is like cannot set special baud rate.
But as I said pyserial set this speed without problem  for ttyUSB0
So it seems pyserial uses diefferent code depending of port type.
I tried to simlink ln -s ttyACM0 ttyUSB0 but it does not work


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kura...@gmail.com  
View profile  
 More options Oct 26 2012, 6:01 pm
Newsgroups: comp.lang.python
From: kura...@gmail.com
Date: Fri, 26 Oct 2012 15:01:43 -0700 (PDT)
Local: Fri, Oct 26 2012 6:01 pm
Subject: Re: How to set 250000 baud rate in pyserial ?
Error is like cannot set special baud rate.
But as I said pyserial set this speed without problem  for ttyUSB0
So it seems pyserial uses diefferent code depending of port type.
I tried to simlink ln -s ttyACM0 ttyUSB0 but it does not work


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Torrie  
View profile  
 More options Oct 26 2012, 6:08 pm
Newsgroups: comp.lang.python
From: Michael Torrie <torr...@gmail.com>
Date: Fri, 26 Oct 2012 16:08:05 -0600
Local: Fri, Oct 26 2012 6:08 pm
Subject: Re: How to set 250000 baud rate in pyserial ?
On 10/26/2012 04:01 PM, kura...@gmail.com wrote:

> Error is like cannot set special baud rate. But as I said pyserial
> set this speed without problem  for ttyUSB0 So it seems pyserial uses
> diefferent code depending of port type. I tried to simlink ln -s
> ttyACM0 ttyUSB0 but it does not work

No the difference in how baud rate is set is most likely in the driver.
 pyserial just uses standard kernel apis and ioctls to control the device.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »