Solved

convert gcc function to visual c for win

Posted on 1998-12-03
2
286 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

734 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