Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

453
Visualizações
Disconnect and reconnect ttyUSB0 programmatically in Linux

Trying to solve this problem (ttyUSB0 that works properly than stop working after about 1hr)I'm thinking on if disconnecting and reconnecting the usb device could be a good fix.

So, it is possibile to cut down power to the USB device and repower it programmatically (bash)?

# lsusb -t                                        
1-1:1.0: No such file or directory                                              
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M             
    |__ Port 1: Dev 2, If 0, Class=vend., Driver=, 12M                          
    |__ Port 1: Dev 2, If 1, Class=vend., Driver=cp210x, 12M

On am335x, kernel 3.2.0, ubuntu core armhf.

[    1.784332] usb 1-1: cp210x converter now attached to ttyUSB0

At the moment I need a complete power cycle to have ttyUSB0 back.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This is the solution:

  • Find the identity of your usb device.

    # tree /sys/bus/usb/drivers/cp210x/
    /sys/bus/usb/drivers/cp210x/
    |-- 1-1:1.1 -> ../../../../devices/platform/omap/musb-ti81xx/musb-hdrc.1/usb1/1-1/1-1:1.1
    |-- bind
    |-- module -> ../../../../module/cp210x
    |-- remove_id
    |-- uevent
     -- unbind
    

So 1-1:1.1 is the identifier of my ttyUSB0(it can be discovered also via dmesg).

  • Then, disconnect the device (as root):

    # echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/unbind
    
  • reconnect it

    # echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/bind
    

At this point I had the same device but with a different name, it was now ttyUSB1 instead of ttyUSB0. - To avoid this I added a new rule in /etc/udev/rules.d/ by creating a new file named 99-usb-serial.rules with this line:

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", ATTRS{serial}=="002DCFAF", SYMLINK+="sameName", MODE:="0666"

where idVendor, idProduct and serial must be the values of your device. This rule will create a new device called sameName linked to the ttyUSB* device normally generated from the OS.

over 4 years ago · Santiago Trujillo Relatório

0

As @Robert Harvey Said,

You first need to find our driver that will help you 'unplug and plug' the usb. Type: ls /sys/bus/usb/drivers which should print something like this: btusb ftdi_sio hub usb usbfs usbhid usbserial_generic uvcvideo. These, are all the drivers for each usb device. Now, lets say mine is ftdi_sio, which is a device i use to program my arduino (atmega328p chip). I am not sure how Your/other usb devices name themselves there. Like, i dont know which of these is my mouse. Now, you can see the driver's commands using: ls /sys/bus/usb/drivers/ftdi_sio/, which will print something like: 1-4:1.0 bind module uevent unbind, Where 1-4:1.0 is the device's characteristic code, and the bind and unbind command, which are the 'plug' and 'unplug' command respectively.

Now, if i want to unplug programatically the ftdi usb port, i will type: echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind and, to plug it again: echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind

Now, we can combine all the commands together, with a ';':

echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind ; echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda