UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-01-31 12:09 PM

usha
Member
Registered: 2005-11-16
Posts: 32

Re: serial device

hi
  i am writing a program which communicates with a fingre print device through a serial port.
   when i am running the program on windows it is running successfully. but on linux its not.
   its getting stuck
                   kindly help me
                                thanking u
                                        usha


[i]usha[/i]

Offline

#2 2006-01-31 05:44 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: serial device

We can't help you if you don't post any source code.

Offline

#3 2006-02-02 05:54 AM

usha
Member
Registered: 2005-11-16
Posts: 32

Re: serial device

#include<stdio.h>   /*Standatd input output definitions*/
#include<string.h>  /*String function definitions*/
#include<unistd.h>  /*Unix standard function definitions*/
#include<fcntl.h>   /*File control definitions*/
#include<errno.h>   /*Error number definitions*/
#include<termios.h> /*Posix terminal control definitions*/

int main()
{
  int fd,i,j,k,s;
  char c,d;
  struct termios options;
  fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
  if(fd == -1)
    perror("Unable to open /dev/ttyS0\n"); 
  else
  {
    fcntl(fd,F_SETFL,0);
    tcgetattr(fd,&options);
    cfsetispeed(&options,B9600);
    cfsetospeed(&options,B9600);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;
    options.c_lflag &= ~(ICANON | ECHO);
    options.c_oflag &= ~OPOST;
  
    tcsetattr(fd,TCSANOW,&options);
    while(1)
    {
                            
              j = read(fd,&c,1);
                                               //write(1,&d,1);
              if(j<0)
                fprintf(stderr,"read from port failed\n");
              write(1,&c,1);
  }
  } 
  close(fd);
  return(0);
}

[i]usha[/i]

Offline

#4 2006-02-03 08:47 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: serial device

I've not much experience with serial port programming, so my help is limited. Try checking the obvious things first:

- Doublecheck that /dev/ttyS0 is the right port (it are the silly things that cost us the most time).

- Make sure that you're using the correct options for the fingerprint device (check with the specs I suppose).

- Check that the port is configured correctly (maybe with stty -F /dev/ttyS0 -a, or better in your program with tcgetattr).

Are you sure that those open() options are correct? I'm mainly suspicious about that O_NDELAY, as that can have different meanings on device files and you're using blocking IO anyway.

I assume the program is stuck in that read() call?

Offline

#5 2006-02-04 05:50 AM

usha
Member
Registered: 2005-11-16
Posts: 32

Re: serial device


[i]usha[/i]

Offline

#6 2006-02-04 01:48 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: serial device

How much data is expected to be sent by that device? What if you do something like the following:

int count;
char buffer[10000];

count = read(fd, buffer, 10000);
printf("Read %i bytes\n", count);

What data is the device supposed to send? ASCII text or binary things? If the latter it's not that strange if you don't get any output anymore.

Offline

#7 2006-02-07 10:00 AM

usha
Member
Registered: 2005-11-16
Posts: 32

Re: serial device

int count;
char buffer[10000];

count = read(fd, buffer, 10000);
printf("Read %i bytes\n", count);

[i]usha[/i]

Offline

#8 2006-02-07 01:22 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: serial device

The difference is that hopefully all data is read at once without doing anything with it. It tells us how many bytes are sent by the device and perhaps give a clue where the problem is.

Do you have the specification of the device? Maybe it want some acknowledgement or something before it continues. It seems a bit strange that you don't know how much data to expect.

Offline

#9 2009-09-08 08:43 AM

dannydesiliva
Guest

Re: serial device

Thanks for the help but the screen appears before the login option. And its appearing in 1 one of the terminal client. I will try to attach a screen shot of the screen. And I have not done any kind of bios update or firmware update or software update. I am still using NCT 2000-xp software only. So please help me as how do I eliminate this error.

Board footer

Powered by FluxBB