MIDI baud rate (31250 baud). Can python understand it?

79 views
Skip to first unread message

Harry Van Haaren

unread,
May 17, 2009, 7:29:54 PM5/17/09
to python...@googlegroups.com
Hey guys,

I've managed to run myself into a lovely litte problem I think.
I'm working on an Arduino project, in which I hope to use
python to "understand" the MIDI messages the Arduino sends.

The data will be coming in on /dev/ttyUSB0   (linux) which
the python serial module opens no problem. Also when I call
serialObject.getSupportedBaudrate  I get a tuple of all the
supported rates.

Unfortunalty 31250 baud isnt there... And the MIDI baudrate is 31250!

So either: A:  I get over it, and reupload the code with a different baudrate
each time I need to switch between debugging code with the
PC and using the device in real life.
     B:  There is some way to make python understand the 31250 baudrate?
Google didnt show me any obvious "python midi baud rate" page..

Cheers for reading, -Harry

Aoife Hughes

unread,
May 17, 2009, 8:34:00 PM5/17/09
to python...@googlegroups.com
Hi,

First thing to mention is that I've not had many/any dealings with
serial port stuff, so I'm just working from what I see.

I'm guessing you're working with pyserial - I don't see serial modules
in the core module docs, and a google of serialObject got me to the
pyserial page.

So, looking at the pyserial docs - in serialposix.py (which is what
you're ultimately going to be using as you're doing this on linux),
there seems to be a lot of stuff surrounding custom baud rates in
_reconfigurePort. Basically, when the object is constructed and open()
is called, _reconfigurePort is called.

One of the tasks of that function is to check the baud rate. First, it
checks to see if it's one of the preconfigured rates (those that are
returned by getSupportedBaudRates), and if not, it tries to configure
it using magic I don't understand (again, because I'm not used to
working with serial ports), and it only bombs out if it absolutely
can't do it.

So, with all of that said, it basically seems to be simply a case of
setting the baudrate attribute to 31250 and hoping for the best.
Chances are, it won't complain. :)

As I said, this is only from reading the code, not using it, so you
might need some more specific help, but it does look like it should
work.

Best of luck.
Aoife

2009/5/18 Harry Van Haaren <harry...@gmail.com>:

Harry Van Haaren

unread,
May 18, 2009, 9:22:28 AM5/18/09
to python...@googlegroups.com
Hey Aoife,

Thanks for that, your right in assuming that Im working with
PySerial, probably should have mentioned that!

I had already tried the >>>serialObject.setBaudrate(31250)
approach, unfortunatly it does bomb out..

So i browsed around the source - great idea, thanks( )
and saw the "magic". I dont understand it either, so
I emailed the author of the module. Hopefully he has time
to respond to me in the next couple of days.. Ill post back here
if I find a solution!

Cheers, -Harry

Harry Van Haaren

unread,
May 18, 2009, 9:02:31 PM5/18/09
to python...@googlegroups.com
Hi all,

Thanks for the help, I got an email from the author of the module
there, seems that the SVN checkout version has support for
arbitrary baud rates. The older version i had (from the Debian linux
packages) does not have support for arbitrary baud rates.

Now (as Aoife suggested),
>>>serialObject.setBaudrate(31250)
doesnt bomb out anymore.

Perfect fix, Im back to coding. -Harry

Aoife Hughes

unread,
May 19, 2009, 4:47:42 AM5/19/09
to python...@googlegroups.com
D'oh, that would explain why I could see it when I browsed the source
- I was looking at the SVN version.

*facepalm*

Glad it works now.

2009/5/19 Harry Van Haaren <harry...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages