Solved

Serial ports communication

Posted on 1998-06-15
1
245 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

705 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

21 Experts available now in Live!

Get 1:1 Help Now