ts-7000
[Top] [All Lists]

[ts-7000] Serial Port 1 ...Interrup driven

To: <>
Subject: [ts-7000] Serial Port 1 ...Interrup driven
From: "LaksCEO" <>
Date: Fri, 29 Feb 2008 19:53:06 +0530
Hi
I am trying to connect an RFID reader through the serial port2 ("/dev/ttyAM1)
 
i tried two programs one interrupt driven other one none interrupt
both are working without any problem in com1 ( "/dev/ttyAM0 ")
 
where as in port2 the interrupt driven pgm is not reading the data from my rfid reader
 
where as the non interupt driven progrm reads the data and diplays it in the minicom environment
 
i run the program from com1 port console
 
i use 115200 baud rate
 
 
for com1 i just change this define statement #define MODEMDEVICE "/dev/ttyAM1" to /dev/ttyAM0
is there any thing else i have to do?
-laks

 

Here is the program for com2...(/dev/ttyAM1)

#include <termios.h>

#include <stdio.h>

#include <unistd.h>

#include <fcntl.h>

#include <sys/signal.h>

#include <sys/types.h>

#include <sys/stat.h>

/*baudrate settings are defined in <asm/termbits.h>, which is included by termios.h */

#define BAUDRATE B115200

 

/* change the following for the correct port */

#define MODEMDEVICE "/dev/ttyAM1"

#define _POSIX_SOURCE 1

/* POSIX complaint source */

#define FALSE 0

#define TRUE 1

volatile int STOP=FALSE;

void signal_handler_IO (int status);/* defn of signal handler */

int wait_flag=TRUE; /* TRUE while no signal recvd */

main()

{

int fd,c,res;

struct termios oldtio,newtio;

struct sigaction saio; /*definition of signal action*/

char buf[255];

/* open modem device for reading and wring and not as controlling tty to avoid

getting killed by ^c */

/* open the device as non blocking */

fd = open (MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK );

if (fd < 0 ) { perror (MODEMDEVICE); exit (-1);}

/* install the signal handler before making the device asynchronous */

saio.sa_handler = signal_handler_IO;

/* saio.sa_mask = NULL; */

saio.sa_flags = 0;

saio.sa_restorer = NULL;

sigaction(SIGIO, &saio, NULL);

/* allow the process to receive SIGIO */

fcntl (fd, F_SETFL, FASYNC);

tcgetattr(fd, &oldtio); /* save currnet serial port settings */

/* bzero(&newtio, sizeof(newtio)); /* clr struct for new port settings */

/* BAUDRATE set bps rate you can also cfsetispeed and set cfsetospeed

CRTSCTS hardware flow control

CS8 : 8n1

CLOCAL : local connection no modem control

CREAD : enable receiving characters

*/

newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;

newtio.c_iflag = IGNPAR | ICRNL;

newtio.c_oflag = 0;

newtio.c_lflag = ICANON; /*enable canonical input*/

/* initalise control chars */

newtio.c_cc[VINTR] = 0; /* CTRL-C */

newtio.c_cc[VQUIT] = 0; /* CTRL-\ */

newtio.c_cc[VERASE] = 0; /* del */

newtio.c_cc[VKILL] = 0; /* @ */

newtio.c_cc[VEOF] = 4; /* CTRL-d */

newtio.c_cc[VTIME] = 0; /* inter char time */

newtio.c_cc[VMIN] = 1; /* blocking read until 1 char arrives */

newtio.c_cc[VSWTC] = 0; /* '\0' */

newtio.c_cc[VSTART] = 0; /* CTRL-q */

newtio.c_cc[VSTOP] = 0; /* CTRL-s */

newtio.c_cc[VSUSP] = 0; /* CTRL-z */

newtio.c_cc[VEOL] = 0; /* '\0' */

newtio.c_cc[VREPRINT] = 0; /* CTRL-r */

newtio.c_cc[VDISCARD] = 0; /* CTRL-u */

newtio.c_cc[VWERASE] = 0; /* CTRL-w */

newtio.c_cc[VLNEXT] = 0; /* CTRL-v */

newtio.c_cc[VEOL2] = 0; /* '\0' */

/* now clean the modem line */

tcflush (fd, TCIFLUSH);

tcsetattr (fd, TCSANOW , &newtio);

/* terminal settings done inputtinf 'z' at the beg of the line will exit the pgm */

while (STOP==FALSE)

{

/*printf(".\n");usleep(100000);

/*after recving SIGIO wait_flag = FALSE input available for and can be read*/

if (wait_flag==FALSE)

{

res = read (fd,buf,255);

buf[res] = 0; /* set end of string with null for printf */

printf(":%s:%d\r\n", buf, res);

if (res==1) STOP=TRUE;/*stop loop if only CR was input */

wait_flag = TRUE; /*wait for new input */

}

}

/* RESTORE OLD PORT SETTINGS */

tcsetattr (fd, TCSANOW, &oldtio);

}

/******************************************************************************

* signal handler sets wait_flag to FALSE to indicate above loop that chrs is recvd

*******************************************************************************/

void signal_handler_IO (int status)

{

/*printf("received SIGIO signal.\r\n");*/

wait_flag = FALSE;

}

__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
  • [ts-7000] Serial Port 1 ...Interrup driven, LaksCEO <=
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU