RPi-Serial

 view release on metacpan or  search on metacpan

Serial.xs  view on Meta::CPAN


    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);

    // 8N1
    toptions.c_cflag &= ~PARENB;
    toptions.c_cflag &= ~CSTOPB;
    toptions.c_cflag &= ~CSIZE;
    toptions.c_cflag |= CS8;
    // no flow control
    toptions.c_cflag &= ~CRTSCTS;

    toptions.c_cflag |= CREAD | CLOCAL;  // turn on READ & ignore ctrl lines
    toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl

    toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
    toptions.c_oflag &= ~OPOST; // make raw

    toptions.c_cc[VMIN]  = 0;
    toptions.c_cc[VTIME] = 10;

    if( tcsetattr(fd, TCSANOW, &toptions) < 0) {
        perror("init_serialport: Couldn't set term attributes");
        return -1;
    }

    return fd;
}

MODULE = RPi::Serial  PACKAGE = RPi::Serial

PROTOTYPES: DISABLE

int
tty_available (fd)
	int	fd

int
tty_putc (fd, b)
	int	fd
	char b

int
tty_puts (fd, str)
	int	fd
	const char *str

int
tty_getc (fd)
	int	fd

void
tty_gets (fd, nbytes)
	int	fd
	int	nbytes
    PREINIT:
        char *buf;
        int got = 0;
        int flags;
        int result;
    PPCODE:
        if (nbytes < 0)
            croak("tty_gets: nbytes must be a non-negative integer");
        /* tty_open() opens with O_NDELAY (non-blocking), which defeats the
           port's VMIN/VTIME read timeout. Clear it so a read blocks up to
           that timeout instead of returning EAGAIN immediately. */
        flags = fcntl(fd, F_GETFL, 0);
        if (flags != -1 && (flags & O_NONBLOCK))
            fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
        Newx(buf, nbytes > 0 ? nbytes : 1, char);
        while (got < nbytes) {
            result = read(fd, buf + got, nbytes - got);
            if (result > 0) {
                got += result;
                continue;
            }
            if (result == 0)
                break;                  /* VTIME timeout or EOF */
            if (errno == EINTR)
                continue;               /* interrupted by a signal; retry */
            Safefree(buf);
            croak("tty_gets: read error: %s", strerror(errno));
        }
        ST(0) = sv_2mortal(newSVpvn(buf, got));
        Safefree(buf);
        XSRETURN(1);

int
tty_open (serialport, baud)
	const char *serialport
	int	baud

void
tty_close (fd)
    int fd

unsigned short
crc16(data_p, length)
    char *data_p
    unsigned short length



( run in 0.752 second using v1.01-cache-2.11-cpan-5511b514fd6 )