pl2303_ttyUSB0 userspace application not able to control RTS line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
   I am using a prolific tech USB-to-serial converter on linux kernel version 2.6.35.
I wrote a userspace program to enable/disable RTS line which is working fine with
standard serial port like ttyS0 and ttyS1.

But when I used the USB-to-serial port (ttyUSB0) to enable/disable the RTS line,ttyUSB0
is not able to do that as well as some times gives

pl2303_ttyUSB0 : pl2303_open-failed submitting read urb -error 22.

Attached is the userspace application and kernel log is also given below,

/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_open -  port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x40:0x1:0x8:0x0  0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x40:0x1:0x9:0x0  0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios -  port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - data bits = 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - baud = 9600
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - stop bits = 1
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - parity = none
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x21:0x20:0:0  7
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x40:0x1:0x0:0x0  0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_open - submitting read urb
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_open - submitting interrupt urb
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x540b
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x540b
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x5402
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x5402
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios -  port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - data bits = 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - baud = 9600
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - stop bits = 1
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - parity = none
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x21:0x20:0:0  7
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x40:0x1:0x0:0x61  0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_tiocmget (0)
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_tiocmget - result = 6
/home/teleset/Desktop/USB-Serial/pl2303.c: set_control_lines - value = 3, retval = 0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_tiocmget (0)
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_tiocmget - result = 6
/home/teleset/Desktop/USB-Serial/pl2303.c: set_control_lines - value = 1, retval = 0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x5402
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x5402
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios -  port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - data bits = 8
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - baud = 9600
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - stop bits = 1
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_set_termios - parity = none
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x21:0x20:0:0  7
/home/teleset/Desktop/USB-Serial/pl2303.c: set_control_lines - value = 3, retval = 0
/home/teleset/Desktop/USB-Serial/pl2303.c: 0xa1:0x21:0:0  7 - 80 25 0 0 0 0 8
/home/teleset/Desktop/USB-Serial/pl2303.c: 0x40:0x1:0x0:0x0  0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl (0) cmd = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_ioctl not supported = 0x5401
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_close - port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_close - shutting down urbs
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_read_bulk_callback - port 0
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_read_bulk_callback - urb status = -2
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_read_bulk_callback - port is closed,
exiting.
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_read_int_callback (0)
/home/teleset/Desktop/USB-Serial/pl2303.c: pl2303_read_int_callback - urb shutting do

Thanks-
Raj
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


static struct termios oldterminfo;


void closeserial(int fd)
{
    tcsetattr(fd, TCSANOW, &oldterminfo);
    if (close(fd) < 0)
        perror("closeserial()");
}


int openserial(char *devicename)
{
    int fd;
    struct termios attr;

    if ((fd = open(devicename, O_RDWR)) == -1) {
        perror("openserial(): open()");
        return 0;
    }
    if (tcgetattr(fd, &oldterminfo) == -1) {
        perror("openserial(): tcgetattr()");
        return 0;
    }
    attr = oldterminfo;
    attr.c_cflag |= CRTSCTS | CLOCAL;
    attr.c_oflag = 0;
    if (tcflush(fd, TCIOFLUSH) == -1) {
        perror("openserial(): tcflush()");
        return 0;
    }
    if (tcsetattr(fd, TCSANOW, &attr) == -1) {
        perror("initserial(): tcsetattr()");
        return 0;
    }
    return fd;
}


int setRTS(int fd, int level)
{
    int status;

    if (ioctl(fd, TIOCMGET, &status) == -1) {
        perror("setRTS(): TIOCMGET");
        return 0;
    }
    if (level)
        status |= TIOCM_RTS;
    else
        status &= ~TIOCM_RTS;
    if (ioctl(fd, TIOCMSET, &status) == -1) {
        perror("setRTS(): TIOCMSET");
        return 0;
    }
    return 1;
}


int main()
{
    int fd;
    char *serialdev = "/dev/ttyUSB0";

    fd = openserial(serialdev);
    if (!fd) {
        fprintf(stderr, "Error while initializing %s.\n", serialdev);
        return 1;
    }

    setRTS(fd,1);
    usleep(10000);      
    setRTS(fd, 0);

    closeserial(fd);
    return 0;
}

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux