2

毎日、約 5 ~ 10 回、USB カメラがシステムから消えます。製造元のドライバーが Linux と互換性がないため、初日から発生しています。lsusb最初は正しく表示されdmesgますが、時間が経つと消えてしまうことがあります。それを修正する最善の解決策は、そのカメラの USB インターフェイスをリセットして元に戻すことです。Cソースコードを使用して手動で数回実行しましたが、うまくいきましたが、Bashループで実行していると、何度も失敗しているようです. 何か案が?

両方のプログラムを機能させて、または常に利用できるようにするにはどうすればよい /dev/video0ですか1?2

ステップ 1:次のコードを使用して、Linux で USB バスをリセットします。

/* few times it's resetting but when I use it in a Bash loop it's not doing it */
#include <stdio.h>
#include <usb.h>

int main(int argc, char *argv[]) {
  struct usb_bus *busses;
  usb_init();
  usb_find_busses();
  usb_find_devices();
  busses = usb_get_busses();
  struct usb_bus *bus;
  int c, i, a;
  for (bus = busses; bus; bus = bus->next) {
    struct usb_device *dev;
    int val;
    usb_dev_handle *junk;
    for (dev = bus->devices; dev; dev = dev->next) {
      char buf[1024];
      junk = usb_open ( dev );
      usb_get_string_simple(junk,2,buf,1023);

      switch(argc) {
       case 1:
        if ( junk == NULL ) {
          printf("Can't open %p (%s)\n", dev, buf );
        } else if (strcmp(buf,"HD Pro Webcam C920")==0) {
          val = usb_reset(junk);
          printf( "reset %p %d (%s)\n", dev, val, buf );
        }
        break;

       default:
        if ( junk == NULL ){
          printf("Can't open %p (%s)\n", dev, buf );
        } else {
          val = usb_reset(junk);
          printf( "reset %p %d (%s)\n", dev, val, buf );
        }
      }

      usb_close(junk);
    }
  }
}

ステップ 2:スキャナーとして実行 - ビデオ 0 または 1 または 2 が利用可能であることを確認し、利用できない場合は USB バスをリセットします

#!/bin/bash
j=true
while $j
do
  for i in 0 1 2
  do
    tmp="/dev/video$i"
    if [ -e $tmp ]
    then
      echo "/dev/video$i"
      j=false
    else
      echo "NO - camera found - restarting the USB $i"
      echo ROOT_PASSWORD_TO_EXECUTE | sudo -S /var/tmp/c-restartusb/restartusb
    fi
  done
done
echo "Camera - logic ended, expecting the camera is available now"

ステップ 3:まだ利用できませんか?

NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
NO - camera found - restart the USB 2
NO - camera found - restart the USB 0
NO - camera found - restart the USB 1
4

1 に答える 1