Need programming help

Need programming help

Post by Mik » Mon, 11 Jan 1999 04:00:00



Hello,

I'm fairly new to the Linux/Unix programming environment and I could
sure use some help.

I'm in the middle of a project which entails porting a program from
AIX to Linux. I have finally go it to compile but the binary is
* on a system function call and I am stuck.

Here is a simplified version of the code:

#include <stdio.h>
#include <unistd.h>

void main(void)
{

FILE *modem;
int file_desc,i,eflag;
char file_string[25] = "/dev/cua1";
char buff[20],c;

if ((modem = fopen(file_string,"r")) == NULL)
  {
  printf("can't open modem\n");
  exit(1);
  }
file_desc = fileno(modem);

printf("the file desc is %d\n", file_desc);
i = read(file_desc, buff, 1);

fclose(modem);
exit(0);

Quote:}

As you can see I am trying to get a string from a modem. The program
is getting a valid file descriptor, but it just hangs in the

i = read(file_desc, buf,1)

statement. I have zero experience with modems(I'm learning on the fly
unfortunatly) and I would sure appreciate any help or suggestions.

I'm compiling this on RedHat 5.0, it was originally done for AIX
version 3.2 (I think)

Thanks,
Mike


 
 
 

Need programming help

Post by Jerry Lynn Krep » Mon, 11 Jan 1999 04:00:00


From "Linux Device Drivers" by Alessandro Rubini, O'Reilly & Assoc pubs.
page 270ff,

#include <termios.h>

struct termios {
        tcflag_t c_iflag;       /* input mode flag */
        tcflag_t c_oflag;       /* output mode flag */
        tcflag_t c_lflag;       /* local mode flag */
        cc_t     c_line;        /* line disipline (something cau's don't have) */
        cc_t    c_cc[NCCS];     /* control characters */

Quote:};

int tcgetattr (int fd, struct termios *tp);
int tcsetattr (int fd, int oact, struct termios *tp);

There is a complete serial I/O program example on pg 273ff. It is called
robin.c
The souce code may be at
http://www.veryComputer.com/
or
ftp://ftp.awl.com/cseng/books/lad/src/

erratta is at
.../lad/errata/

Jerry


> Hello,

> I'm fairly new to the Linux/Unix programming environment and I could
> sure use some help.

> I'm in the middle of a project which entails porting a program from
> AIX to Linux. I have finally go it to compile but the binary is
>* on a system function call and I am stuck.

> Here is a simplified version of the code:

> #include <stdio.h>
> #include <unistd.h>

> void main(void)
> {

> FILE *modem;
> int file_desc,i,eflag;
> char file_string[25] = "/dev/cua1";
> char buff[20],c;

> if ((modem = fopen(file_string,"r")) == NULL)
>   {
>   printf("can't open modem\n");
>   exit(1);
>   }
> file_desc = fileno(modem);

> printf("the file desc is %d\n", file_desc);
> i = read(file_desc, buff, 1);

> fclose(modem);
> exit(0);
> }

> As you can see I am trying to get a string from a modem. The program
> is getting a valid file descriptor, but it just hangs in the

> i = read(file_desc, buf,1)

> statement. I have zero experience with modems(I'm learning on the fly
> unfortunatly) and I would sure appreciate any help or suggestions.

> I'm compiling this on RedHat 5.0, it was originally done for AIX
> version 3.2 (I think)

> Thanks,
> Mike




 
 
 

Need programming help

Post by Jerry Lynn Krep » Mon, 11 Jan 1999 04:00:00


Opps!
The book was "Linux Application Development"
Erik W. Troan and Michael K. Johnson
Addison-Wesley publishers
ISBN:0-201-30821-5
Sorry

> From "Linux Device Drivers" by Alessandro Rubini, O'Reilly & Assoc pubs.
> page 270ff,

> #include <termios.h>

> struct termios {
>         tcflag_t c_iflag;       /* input mode flag */
>         tcflag_t c_oflag;       /* output mode flag */
>         tcflag_t c_lflag;       /* local mode flag */
>         cc_t     c_line;        /* line disipline (something cau's don't have) */
>         cc_t    c_cc[NCCS];     /* control characters */
> };

> int tcgetattr (int fd, struct termios *tp);
> int tcsetattr (int fd, int oact, struct termios *tp);

> There is a complete serial I/O program example on pg 273ff. It is called
> robin.c
> The souce code may be at
> http://www.veryComputer.com/
> or
> ftp://ftp.awl.com/cseng/books/lad/src/

> erratta is at
> .../lad/errata/

> Jerry


> > Hello,

> > I'm fairly new to the Linux/Unix programming environment and I could
> > sure use some help.

> > I'm in the middle of a project which entails porting a program from
> > AIX to Linux. I have finally go it to compile but the binary is
> >* on a system function call and I am stuck.

> > Here is a simplified version of the code:

> > #include <stdio.h>
> > #include <unistd.h>

> > void main(void)
> > {

> > FILE *modem;
> > int file_desc,i,eflag;
> > char file_string[25] = "/dev/cua1";

> > char buff[20],c;

> > if ((modem = fopen(file_string,"r")) == NULL)
> >   {
> >   printf("can't open modem\n");
> >   exit(1);
> >   }
> > file_desc = fileno(modem);

> > printf("the file desc is %d\n", file_desc);
> > i = read(file_desc, buff, 1);

> > fclose(modem);
> > exit(0);
> > }

> > As you can see I am trying to get a string from a modem. The program
> > is getting a valid file descriptor, but it just hangs in the

> > i = read(file_desc, buf,1)

> > statement. I have zero experience with modems(I'm learning on the fly
> > unfortunatly) and I would sure appreciate any help or suggestions.

> > I'm compiling this on RedHat 5.0, it was originally done for AIX
> > version 3.2 (I think)

> > Thanks,
> > Mike



 
 
 

Need programming help

Post by Jan Pantelt » Mon, 11 Jan 1999 04:00:00


You may get an answere by posting to comp.os.linux.development.apps
 
 
 

Need programming help

Post by Walter Stro » Mon, 11 Jan 1999 04:00:00


: You may get an answere by posting to comp.os.linux.development.apps

Also, there's a ng dedicated to the gcc compiler (they'll point out, with
great enthusiasm, calls that aren't valid under gcc).  I forget the name
of the ng, just search for "gcc".

 
 
 

Need programming help

Post by Gary Momariso » Mon, 11 Jan 1999 04:00:00



> Hello,

> I'm fairly new to the Linux/Unix programming environment and I could
> sure use some help.

> I'm in the middle of a project which entails porting a program from
> AIX to Linux. I have finally go it to compile but the binary is
>* on a system function call and I am stuck.

Just general suggestions here.  Of course, books are good.  And in
this level of programming, the best course is often to just hunt down
some code that might be doing something similar to what you're doing
and try to learn from it.

Of course, with the way almost everybody copyrights and licences
code, you can't just copy their code. Ya gotta learn the method
and recode from scratch, unless you want to jump through the
licencing hoops, which in the case of GPL or LGPL means you've
got to release everything you write under the same licence so
nobody can freely copy your code either.

You can find some related resourses in Gary's Encyclopedia at:

http://www.veryComputer.com/~swear/pedia/programming.html
http://www.veryComputer.com/~swear/pedia/device-drivers.html