Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RS232

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

596 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