Solved

Serial ports communication

Posted on 1998-06-15
1
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to properly read C++ console input into several variables with scanf 2 38
internet fax? 7 31
why doesn't assert terminate here? 2 16
Computer Virus 30 66
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
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…

738 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