Solved

RS232

Posted on 1998-08-21
5
404 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.
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.

773 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