Thursday, November 20, 2008

UART-Access-in-Windowns (General)

To use the serial port in Win32 you can use the CreateFile ( function to setup a handle to the hardware. Specify the port name in place of the file name (e.g. "COM1"). Then you need to use the DCB ( struct. The DCB struct has members for setting up the baud rate, flow control, parity....etc. Set all of the parameters you want in the DCB struct, or have dialogs that let the user select the ones they want, and then use the SetCommState ( function to configure the port with the parameters in the DCb struct. You will also need to set the timeouts for the port with the SetCommTimeouts ( Also you'll need to set buffer sizes with the SetupComm ( function.

Once the port is opened (briefly outlined above) use the ReadFile and WriteFile functions to read and write from and to the port. To switch individual lines on the port (RTS, DTR..etc) use EscapeCommFunction (

That is just a quick overview but the links provided should get you started.


No comments: