Solved

Serial ports communication

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PCAnywhere 2 135
Old Xray equipment running on Win XP so can't upgrade to the latest Eaglesoft 10 79
What program can open a .sig file image? 6 44
Gaming Software 1 19
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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