Solved

convert gcc function to visual c for win

Posted on 1998-12-03
2
278 Views
Last Modified: 2008-02-01
Below is a function which is well-tested and error-free when compiled
with gcc and running with Red Had Linux 5.1.

We need to rewrite the same function using Visual C++ to run under
Windows.

Can anyone name library functions in Visual C++ which correspond to the
library functions from gcc used below?

submitted by amw23

/* some globals: */

#define COM_PORT        "/dev/cua0"
int            comTimeOut=COMTIMEOUT;
int            comport;
int            comsocket;
struct termios old_port;
struct termios new_port;


/* the function: */
/*******************************  OpenPort  *********************************/
void OpenPort() {
  void ClosePort();

  if ((comport = open(COM_PORT,O_RDWR | O_NONBLOCK))==-1) { /****************/
    perror("comserver (open)");                      /* Open the com port.  */
    exit(1);                                        /************************/
  }

  if (tcgetattr(comport, &old_port)!=0) {                  /*****************/
    perror("comserver (tcgetattr)");                      /* Get attributes */
    exit(1);                                             /* on com port.    */
  }                                                     /********************/
                                                /****************************/
  new_port = old_port;                         /* Save current settings, so */
  atexit (ClosePort);                             /* they can be resorted latter*/
                                             /*******************************/
  cfsetispeed(&new_port, B1200);                    /* Adjust port settings */
  cfsetospeed(&new_port, B1200);                   /*     1200 baud         */
  cfmakeraw(&new_port);                           /*      set RAW data mode */
  tcsetattr (comport, TCSANOW, &new_port);       /* Apply new settings.     */
                                                /****************************/
}




0
Comment
Question by:amw23
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 1179180
Ooops, this will have to be completly re-written for Win32 - 'open()' is superseded by 'CreateFile()' whereas 'cfsetispeed()'   'cfsetospeed()' and 'tcsetattr()' are replaced by a call to 'SetCommState()'. The functions and the programming model don't correspond at all, but the MS scheme is quite straightfoward... The most comprehensive information on serial programming on Win32 is an MSDN article named 'Serial Communications in Win32' at 'http://www.microsoft.com/win32dev/base/serial.htm' - feel free to ask if you have further questions or need some sample source code...
0
 

Author Comment

by:amw23
ID: 1179181
Your reply and the references you cite appear to be on point.
We are examining each one.  We will post another question if
we need more help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 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.

705 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

18 Experts available now in Live!

Get 1:1 Help Now