Solved

Serial ports communication

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stamp tool on acrobat 1 39
Software to generate custom JPGs 12 118
DCT of  2D array using fftw in c++ 9 41
WinX Downloader fails to analyze. 10 40
Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
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…
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.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

822 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