Solved

RS232

Posted on 1998-08-21
5
402 Views
Last Modified: 2010-04-10
I am trying to write a RS232 interface in c++.  Is there any source code for this already on the web?
0
Comment
Question by:SJW082198
5 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
For what platform?
0
 

Expert Comment

by:staggart
Comment Utility
What platform?
0
 

Author Comment

by:SJW082198
Comment Utility
Windows 95
0
 

Expert Comment

by:bozhidar
Comment Utility
I'm not sure if there are any source on the web, but I can tell you a short list of functions which might help you :
CreateFile, CloseHandle,
GetCommState, SetCommState,
GetCommTimeouts , SetCommTimeouts
WriteFile, ReadFile ... etc.
Or you can read the following chapter in Platform SDK :
Windows Base Services\Hardware\Communications or
Windows Base Services\Files and I/O\Communications
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
Comment Utility
Hi, here is 3 simple programmes for Read/Write to RS232

static int idComDev = -1;
static DCB  dcb;

#define MAX_LEN_INPUT   1200
#define MAX_LEN_OUTPUT  1200
void DefineRS232(void)
{
  int err,;
  char
    *szInit = "COM1:9600, N, 8, 1",
    buff[20];                  //Com Command

  wsprintf(buff, "COM%d", i+1);
  idComDev = OpenComm(buff,MAX_LEN_INPUT , MAX_LEN_OUTPUT);
  if (idComDev >= 0)  //open?
    {
      err = BuildCommDCB(szInit, &dcb);
      if (err >= 0)
      err = SetCommState(&dcb);
      if (err < 0)                        //Error?
      {
        CloseComm(idComDev);
        idComDev  = -1;
      }
    }
}
void WriteRS232(char *s)
{
  if (idComDev >= 0)                  //OK?
    {                                    //send acknoledge
      err = WriteComm(idComDev,(LPCSTR)s,strlen(s));
      if (err < 0)             //error: close
      {
        CloseComm(idComDev);
        idComDev = -1;      //no!
      }
    }
}
void ReadRS232(char *buff)
{
  int err = ReadComm (idComDev,buff,MAX_LEN_OUTPUT);
  if (err < 0)             //error: close
    {
      CloseComm(idComDev);
      idComDev = -1;      //no!
    }
}
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

10 Experts available now in Live!

Get 1:1 Help Now