开发者

Reading from the serial port from C++ or Python on windows

I need to read the serial port from windows, using either Python or C++. What 开发者_运维百科API/Library should I use? Can you direct me to a tutorial? Thanks!


In python you've excellent package pyserial that should be cross-platform (I've used only in GNU/Linux environment).

Give it a look, it's very simple to use but very powerful!

Of course examples are provided!

By the way, if it can be useful here you can find a project of mine which use pyserial, as an extended example.


In C++:

  1. CreateFile("\\\\.\\COM39", ...)
  2. SetCommState
  3. SetCommTimeouts
  4. ReadFile, WriteFile
  5. CloseHandle

There is also a full documentation on communication resources.


This is classic article about Win32 serial communications: http://msdn.microsoft.com/en-us/library/ms810467.aspx


In python it is as simple as importing pyserial and use its open() method (if you are using quite standard system, otherwise you have to adjust a number of parameters to match your environment of course).

EDIT:
As pointed out by Enrico, pyserial is not a default package in many distributions, so you have to install it by your own. I suggest to install and use easy-install, by setuptools to handle your python addons packages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜