Search code examples
cwinapiioserial-port

what is the easiest way to read and process serial data for windows 32-bit systems?


hello and good day to you guys. I am running Windows XP which I am given to understand is a 32 bit windows system.

I have a microcontroller that continuously sends data serially through a COM port. I want to process data in a C program. The options I'm looking at so far are:

  1. get serial data via python and pass to C
  2. read data serially and use in C

The first option seems too hard for me. I was trying to use swig and am stuck. any other suggestions?


Solution

  • You'll find it much easier just to receive the data straight via C, if you're going to process it there in the end anyway. Here's a quick overview of how to set things up. Essentially you call CreateFile on, eg, "COM1", then use GetCommState and SetCommState on the resulting handle to configure the port. If you need to do GUI interaction as well, have the reading code run on a different thread, and communicate the data it reads back to the GUI thread by posting custom (WM_USER, etc) messages to one of your windows.