views:

361

answers:

4

Hi all,

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!

+3  A: 

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

Alex Farber
+4  A: 

In C++:

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

There is also a full documentation on communication resources.

avakar
+4  A: 

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.

Enrico Carlesso
+3  A: 

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.

AlberT
Just a point, pyserial is not installed as default in most system.
Enrico Carlesso
Right, it is simply available via easy-install. +1 for you as your answer was the first one :)
AlberT