[linux-ileri] Re: Seri porttan interrupt - Serdar Hoca'ya

---------

From: Derya Sezen (funky@gsu.linux.org.tr)
Date: Thu 21 Aug 2003 - 15:41:31 EEST

  • Next message: Ozan K. Bekmezci: "[linux-ileri] WINE"

    > fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK);
    >
    Ben de bu sekilde actim.

    Data gonderen kod asagidaki gibidir :

    #include <stdio.h>
    #include <sys/signal.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <termios.h>
    #include <fcntl.h>
                                                                                                                                 
    #define SIGPLC 17
    #define _POSIX_SOURCE 1
                                                                                                                                 
    #define DEVAM 1
    #define DUR 0
                                                                                                                                 
    #define baudrate B19200
    #define port "/dev/ttyS0"
                                                                                                                                 
    int state = DEVAM;
                                                                                                                                 
    int BaudToConstant(int brate)
    {
      int result=0;
                                                                                                                                 
            switch (brate)
            {
                    case 9600 :
                            result=B9600;
                    break;
                    case 19200 :
                            result=B19200;
                    break;
                    case 38400 :
                            result=B38400;
     
                    break;
                    case 57600 :
                            result=B57600;
                    break;
                    case 115200 :
                            result=B115200;
                    break;
            }
            return result;
    }
                                                                                                                                 
                                                                                                                                 
    int main()
    {
        int fd, c, res;
        struct termios eski, yeni;
        struct sigaction sig;
                                                                                                                                 
        char buf[255];
    // volatile int dongustate = CIKISLARI_HAZIRLA_VE_GONDER;
                                                                                                                                 
        if( (fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK)) <0 ){
            printf("seri porta ulasim sorunu\n");
            exit(1);
        }
                                                                                                                                 
        /* proses SIGIO alabilmeli */
        fcntl(fd, F_SETOWN, getpid());
        /* fd asenkronize tanimlaniyor */
        fcntl(fd, F_SETFL, FASYNC);

        tcgetattr(fd,&eski);
        cfsetispeed(&eski, BaudToConstant(baudrate));
        cfsetospeed(&eski, BaudToConstant(baudrate));
                                                                                                                                 
        eski.c_cflag |= (CREAD|CLOCAL);
        eski.c_cflag &= ~(CSIZE);
        eski.c_cflag |= CS8;
        eski.c_cflag &= ~(PARENB);
        eski.c_cflag &= ~(CSTOPB); /* 1 stop bit yaptim.. */
        eski.c_iflag &= ~(IXON | IXOFF);
        eski.c_cflag &= ~CRTSCTS;
        eski.c_lflag |= (ICANON);
        eski.c_lflag &= ~(ECHO | ECHOE | ISIG |ECHOK|ECHONL);
                                                                                                                                 
        tcflush(fd, TCIFLUSH);
        tcsetattr(fd, TCSANOW, &eski);

        sprintf(buf,"%s\r","deneme");
                                                                                                                                 
        while( state == DEVAM ) {
                                                                                                                                 
            res = write(fd, buf, 3);
                                                                                                                                 
            printf("result: %d\n", res);
                                                                                                                                 
            sleep(1);
                                                                                                                                 
        }
                                                                                                                                 
        return 1;
                                                                                                                                 
    }

    ******************

    tabii normalde read 'i de icine gomecegim ama write kisminin calisiyor
    oldugunu gormem gerek ilk asamada, shu an bunu basaramiyorum...

    tesekkurler

    Derya Sezen
    a.k.a. funky
    GSULinuX


  • Next message: Ozan K. Bekmezci: "[linux-ileri] WINE"

    ---------

    Bu arsiv hypermail 2.1.6 tarafindan uretilmistir.