Solved

RS232

Posted on 1998-08-21
5
405 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
ID: 1170887
For what platform?
0
 

Expert Comment

by:staggart
ID: 1170888
What platform?
0
 

Author Comment

by:SJW082198
ID: 1170889
Windows 95
0
 

Expert Comment

by:bozhidar
ID: 1170890
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
ID: 1170891
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

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

840 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