Solved

convert gcc function to visual c for win

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

617 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