ftdi-rs / libftd2xx

Rust safe wrappers for the libftd2xx drivers
MIT License
32 stars 15 forks source link

Unable to open device visible through list_devices/list_devices_fs #53

Closed cgonyeo closed 2 years ago

cgonyeo commented 2 years ago

I've got this USB device I just bought, that shows up as an FTDI device when I plug it in:

pi@raspberrypi ~/git/dmx> dmesg | tail -n 12
[ 1834.027579] usb 1-1.2: USB disconnect, device number 3
[ 1834.028834] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[ 1834.029116] ftdi_sio 1-1.2:1.0: device disconnected
[ 1835.308933] usb 1-1.2: new full-speed USB device number 4 using xhci_hcd
[ 1835.455269] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[ 1835.455292] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1835.455310] usb 1-1.2: Product: FT232R USB UART
[ 1835.455327] usb 1-1.2: Manufacturer: FTDI
[ 1835.455344] usb 1-1.2: SerialNumber: AQ01FC3R
[ 1835.463973] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[ 1835.464147] usb 1-1.2: Detected FT232RL
[ 1835.468303] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0

I was hoping to use libftd2xx to control this device. It shows up when I call list_devices and list_devices_fs, but the library fails to open it. With the following program:

use libftd2xx::{self as ftdi, FtdiCommon};

fn main() {
    let devices = ftdi::list_devices().expect("failed to list devices");
    println!("list_devices: {:?}", devices);

    let devices = ftdi::list_devices_fs().expect("failed to list devices");
    println!("list_devices_fs: {:?}", devices);

    let mut ft_device = ftdi::Ftdi::new().expect("FTDI device not present");
    let vec: Vec<u8> = vec![255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255];
    ft_device
        .write_all(vec.as_slice())
        .expect("failed to write");
}

I see the following output:

list_devices: [DeviceInfo { port_open: true, speed: Some(FullSpeed), device_type: Unknown, vendor_id: 0x0000, product_id: 0x0000, serial_number: , description:  }]
list_devices_fs: [DeviceInfo { port_open: false, speed: None, device_type: FTAM, vendor_id: 0x0403, product_id: 0x6001, serial_number: AQ01FC3R, description: FT232R USB UART }]
thread 'main' panicked at 'FTDI device not present: DEVICE_NOT_OPENED', src/main.rs:10:43

It's not clear to me why the device fails to open (at the Ftdi::new() line), when it's visible under list_devices. I have no clue if I'm holding the library wrong, if there's a bug in the c library this binds against, or if the device I purchased has a bug.

Also apologies if opening an issue here wasn't the right way to ask for help, I wasn't really able to find any other avenues to reach out through.

newAM commented 2 years ago

That looks like it is bound to the FTDI kernel module, does sudo rmmod ftdi_sio change anything?

cgonyeo commented 2 years ago

Oh excellent, my example program runs successfully with that command. I'll find a way to disable that kernel mod, thanks so much for the help.