Solved

convert gcc function to visual c for win

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 51
Using Delphi code in a Builder project that uses a DLL 3 107
Lambda for random numbers problem 7 106
is twain_32.dll cmpatible with windows 10 ? 10 123
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

929 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

14 Experts available now in Live!

Get 1:1 Help Now