C program to read data from USB device connected to the system

前端 未结 1 1544
一个人的身影
一个人的身影 2021-02-09 13:17

I am trying to fetch data from the USB device (say pendrive) connected to the USB port of a system. Here, I am able to open the device file and read some random raw data. But I

1条回答
  •  梦如初夏
    2021-02-09 14:12

    you will need to set the correct port configuration...

    struct termios oldtio,newtio;
    
    // open port...
    // save existing attributes
    tcgetattr(fd,&oldtio);  
    
    // set attributes - these flags may change for your device
    #define BAUDRATE B9600 
    memset(&newtio, 0x00, sizeof(newtio));  
    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;   
    newtio.c_iflag = IGNPAR | ICRNL;          
    newtio.c_oflag = 0;  
    
    tcflush(fd, TCIFLUSH);  
    tcsetattr(fd,TCSANOW,&newtio); 
    
    //reset attributes
    tcsetattr(fd,TCSANOW,&oldtio); 
    

    I have a rough working example here... http://file-hub.com/cmd:thread/142300

    0 讨论(0)
提交回复
热议问题