Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 975
static_rtti Avatar asked Mar 01 '10 09:03

static_rtti


People also ask

How do I read a COM port in Windows?

1) Click Start. 2) Click Control Panel in the Start menu. 3) Click Device Manager in the Control Panel. 4) Click + next to Port in the Device Manager to display the port list.

How do I read serial data on my computer?

In Serial Port Reader go to the “Main menu”, choose “Session -> New session”. Alternately, you can click on the “New” icon on the main toolbar or press “Ctrl + N”. This invokes the “New monitoring session” screen. Terminal view – all received data is displayed in ASCII characters on a text console.

How do you send data to a serial port in Python?

Transmitting Data: Firstly, we need to include the serial library. We can then declare an instance of the serial port and add the SerialPort, baudRate and timeOut parameters , I'm using serial0, 115200 and 0.050. To find your Pi serial port use the command 'lsdev'. In my case, my serial port was serial0.


2 Answers

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.

like image 122
Enrico Carlesso Avatar answered Nov 14 '22 22:11

Enrico Carlesso


In C++:

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

There is also a full documentation on communication resources.

like image 27
avakar Avatar answered Nov 14 '22 23:11

avakar