Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#69 pyserial too slow on linux

open
nobody
None
5
2009-11-23
2009-11-23
ryangt
No

So, I wouldn't normally put this in a bug tracker, but I don't see a support email group.

I am using pyserial very successfully in Windows. It works very well for my needs. I am running some experiments with a microcontroller and need to read 4 bytes and send 3 bytes once every 2 milli-seconds. No problem on Windows. It doesn't work well in Linux. I can't yet get the hard data to show explicitly that this is the problem, but it only runs correctly in Linux if I give it 5-10 milli-seconds to complete the serial transaction (as opposed to the 2 milli-second time interval in windows). There is very little going on during this time besides serial communication. The microcontroller code does not change from running the tests in Windows to Linux. I am using a buad rate of 115200, so I think the transmission time is quite reasonable. I have been poking around trying to time the execution and it seems like reading the 4 bytes from the microcontroller is the problem.

What can be done to make serial communication faster in Linux?

Thanks,

Ryan

Discussion

  • Chris Liechti
    Chris Liechti
    2010-01-02

    You have some sort of ping-pong communication, expecting an answer, to each 4 byte packet, on the uC within a few milliseconds?

    This sort of control can not be implemented with pyserial. Depending on operating system and CPU load the thread reading or writing might only get time every 15ms or slower. Such very short reaction times to send an answer upon received data can not be guaranteed from user space programs.

    You may be able to tweak things a bit by choosing a different scheduler for the Linux Kernel or playing with process priorities.

     
  • ryangt
    ryangt
    2010-01-13

    So, I understand that doing this communication in real time every 1-2 milli-seconds is demanding. The part I am trying to understand is why it works in Windows and not in Linux. It actually works nearly flawlessly in Windows. I find that annoying and don't want to have to boot into Windows every time I need to work with pyserial. So, saying this is too demanding of an application isn't a completely satisfactory answer to me because it apparently can be done, just not in Linux.