Hi everybody,

I have a question.

I want to get (kind of) analog data into my PC; this analog data is
available as different frequencies (approx. 0,1 - 1000Hz) on a line. I
thought I connect this to the serial port and use TIOCMIWAIT and
gettimeofday() to time it and
calculate the analog data from there.

1st problem: with heavy cpu load, this may not work very well. Is there
some patch available to get signals sent, along with the pentuium cycle
counter or something like that?

2nd problem: when looking at /proc/interrupts, there are no interrupts for
the serial module. just says always 0.

3rd problem: I think because of 2, the least time difference I got was ~ 10
seconds. I'd like to get at LEAST 5ms or better!


I've already tried before to get SIGIO with the complete information (which
fd, ...) into another program - this wouldn't work too. maybe that would
work here?


please tell me what I've done wrong.


Here's the program I used:


#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include
<sys/types.h>       
#include <sys/stat.h>       
#include
<fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include
<linux/serial.h>
#include <termios.h>
        


#define E(s) do {
fprintf(stderr,"Error in %s: %d\n",s,errno); perror(""); exit(1); } while
(0)



int main(int argc, char *args[])
{
  int fd;
  int a,b;
  struct
timeval tv_1,tv_2;
  struct termios tio;
  struct serial_icounter_struct
scs;

  args++;
  if (argc <2) *args="/dev/ttyS1";


fd=open(*args,O_RDWR);
  if (fd==-1) E("open");

/*
a=ioctl(fd,TIOCGSERIAL,&ses);
  if (a) E("ioctl i1"); */
  
  if
(tcgetattr(fd,&tio))
    E("tcget");
  
/*  tio.c_iflag=IGNBRK | IGNPAR;

tio.c_oflag=OPOST;
  tio.c_cflag=CS8 | CREAD | CLOCAL;

tio.c_lflag=IEXTEN; */
  
  cfmakeraw(&tio);

  if
(cfsetispeed(&tio,B57600))
    E("cfsetispeed");

  if
(tcsetattr(fd,TCSANOW,&tio))
    E("tcget");

  b=TIOCM_RTS | TIOCM_RTS;

a=ioctl(fd,TIOCMBIS,&b);
  if (a) E("tioccmbis");

  printf("opened:\n");


 tv_2.tv_sec=tv_2.tv_usec=0;

  while (1)
  {
    tv_1=tv_2;

a=ioctl(fd,TIOCMIWAIT,TIOCM_RNG | TIOCM_DSR | TIOCM_CD | TIOCM_CTS);

gettimeofday(&tv_2,NULL);

    if (a==0)
    {
      if
(ioctl(fd,TIOCGICOUNT,&scs))
        E("tiocgicount");

      tv_1.tv_sec  =
tv_2.tv_sec  - tv_1.tv_sec;
      tv_1.tv_usec = tv_2.tv_usec -
tv_1.tv_usec;

      if (tv_1.tv_usec<0)
      { 
        tv_1.tv_usec+=1000000;

tv_1.tv_sec-=1;
      }
      
      printf("waited: %9d.%6d ...   %8d %8d
%8d %8d\n",
//        tv_2.tv_sec, tv_2.tv_usec,
          tv_1.tv_sec, tv_1.tv_usec,

 scs.cts, scs.dsr, scs.rng, scs.dcd);
    }
    else
    {

E("ioctl");
    }
  }

  
  close(fd);
}



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]

Reply via email to