?
Solved

RS232

Posted on 1998-08-21
5
Medium Priority
?
409 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
[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
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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

752 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