Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I've a problem with a serial port adapter. This is what i've done: lsusb PHP Code: Bus 001 Device 005 :  ID 05d1 : 5001 Brainboxes ,  Ltd  PHP Code: sudo modprobe usbserial vendor = 0x05d1 product = ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    5

    C/C++ Serial port programming


    Hi,
    I've a problem with a serial port adapter. This is what i've done:
    lsusb
    PHP Code:
    Bus 001 Device 005ID 05d1:5001 BrainboxesLtd 
    PHP Code:
    sudo modprobe usbserial vendor=0x05d1 product=0x5001
    sudo chmod o
    +rw /dev/ttyUSB0 
    and the adapter is attached to /dev/ttyUSB0 and /dev/ttyUSB1
    PHP Code:
    1596.261797usb 1-1.4: new full-speed USB device number 5 using ehci_hcd
    1596.368458usbserial_generic 1-1.4:1.0generic converter detected
    1596.368667usb 1-1.4generic converter now attached to ttyUSB0
    1596.371816usbserial_generic 1-1.4:1.1generic converter detected
    1596.371982usb 1-1.4generic converter now attached to ttyUSB1 
    Now, this is the code for comunication
    PHP Code:
    void SerialPort::openPort(char *port){
        
    struct termios options;
        
    this->fd open("/dev/ttyUSB0"O_RDWR O_NOCTTY O_NDELAY);
        if(
    this->fd == -1){
            
    std::cout << "Error open port" << std::endl;
            
    std::cout << "-" << strerrorerrno ) << "-" << std::endl;
        }
        
    fcntl(this->fdF_SETFLFNDELAY);

        
    tcgetattr(this->fd, &options);
        
    cfsetispeed(&optionsB115200);
        
    cfsetospeed(&optionsB115200);
        
    options.c_cflag &= ~PARENB;
        
    options.c_cflag &= ~CSTOPB;
        
    options.c_cflag &= ~CSIZE;
        
    options.c_cflag |= CS8;

        
    options.c_lflag &= ~(ICANON | ECHO | ECHOE ISIG);

        
    options.c_cflag |= (CLOCAL CREAD);
        
    options.c_iflag &= ~(IXON IXOFF IXANY);
        
    tcflush(this->fdTCIFLUSH);
        
    tcsetattr(this->fdTCSANOW, &options);
    }

    void SerialPort::t_readData(){
        
    int len 1;
        
    char byte[10] = {0};
        
    long long count 0;
        if(
    this->fd == -1) return;
        
    //tcflush(this->fd, TCIFLUSH);

        
    len write(this->fd"\xAA"sizeof(char));
        if(
    len 0){
           
    std::cout << "Error write serial port" << std::endl;
           return;
        }

        
    std::ofstream tmpf("/tmp/data.txt"ios_base::out ios_base::binary);
        
    sleep(1);
        
    std::cout << "Reading" << std::endl;
        while (
    len 0){
            
    len read(this->fdbytesizeof(byte));
            if(
    len 0)
               
    //std::cout << byte << std::endl;
               
    tmpf.write(bytesizeof(byte));
            
    count++;

        }
        
    std::cout << "End Reading" << std::endl;
        
    tmpf.close();
        
    std::cout << count << std::endl;
        
    close(this->fd);

    The adapter is for a nexys2 card, whitch read a start byte (AA hex) and send 32byte of data for 100 times.
    My problem is that the program read a variable number of byte, mostly a sequence of 01 60 (hex)
    And this happens even with the card turned off !!

    On terminal (with the card turn off) if I do

    cat /dev/ttyUSB0

    It starts to print binary symbols...

    Someone know its happens?

    My distro is mint 13 (Maya)

    Thanks

  2. #2
    Just Joined!
    Join Date
    Nov 2012
    Posts
    5
    Hi
    Finally i've a solution:

    I've to use ftdi_sio module instead usbserial to make work Brainboxes adapter !
    Last edited by grumpos; 11-11-2012 at 11:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •