Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert gcc function to visual c for win

Posted on 1998-12-03
2
Medium Priority
?
289 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
[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
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

664 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