Solved

Serial ports communication

Posted on 1998-06-15
1
247 Views
Last Modified: 2013-11-15
Hiya,

I'm just getting into c++ and I have a small problem. How do I open, put, and get chars from the com ports?
Some examples would be nice!
0
Comment
Question by:Severin
1 Comment
 

Accepted Solution

by:
FabMan earned 50 total points
ID: 1165924
If you are talking about the Win32 environment, you should use functions like CreateFile, CloseHanlde, WriteFile, ReadFile, SetupComm, SetCommState and others. If you are programming for Windows for the Windows API (16-bits) you should use functions like OpenComm, CloseComm, SendComm and ReceiveComm. When working with DOS, just use regular file functions, specifying COM1: or COM2: (or whatever the case) as a file name. Here's an example of how to use CreateFile in the Win32 API to open a serial port (there are plenty of other examples in the functions documentation):

  HANDLE hPort = CreateFile("COM1:",
      GENERIC_READ | GENERIC_WRITE,
      0,    /* comm devices must be opened w/exclusive-access */
      NULL, /* no security attrs */
      OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
      0,    /* not overlapped I/O */
      NULL  /* hTemplate must be NULL for comm devices */
      );

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Driver Problem 12 84
fatal error: vector: No such file or directory   Visual Studio 2015 for Arduino 4 56
Safe conversion? 4 58
Christmas family picture with greetings 19 83
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now