Mailinglist Archive: opensuse-programming-de (158 mails)

< Previous Next >
Re: USB ansteuern!
  • From: Jan Hendrik Berlin <j.h.berlin@xxxxxxxxxxxxxxx>
  • Date: Fri, 23 May 2003 00:49:31 +0200
  • Message-id: <200305230049.31200.j.h.berlin@xxxxxxxxxxxxxxx>
Am Mittwoch, 21. Mai 2003 19:15 schrieben Sie:
> Jan Hendrik Berlin schrieb:
> >hi!
> >also ISO C++ kennt keine Sau!
> >HAb Lehrer und MItschüler gefragt, aber alle sagen das gleich:"noch nie
> >gehört!"
> >find ich komisch!! aber egal!
> >
> >Mein Problem ist derzeit:
> >
> >_Welches Device muss ich öffnen, und wie finde ich das heraus!_
> >
> >Ja, wenn mir einer die Frage beantworten könnte, wäre das schön!!!
>
> Hallo Jan,
>
> wie ich sehe bist Du nicht viel weiter gekommen mit meiner Info. Ich
> habe Dir mal eine Routine aus
> der libgphoto2 beigelegt. In der sieht man ganz genau wie man ein USB
> Gerät sucht.
> Ich gehe davon aus, daß Du SuSE 8.2 oder ähnlich benutzt.
> Öffne eine console. Am Eingabepromt wechsel in das /proc Verzeichnis
> also : cd /proc
> dann mit cd bus/usb in das usb Verzeichnis wechsel.
> dann sind da zwei Dateien, eine heißt devices und die andere drivers.
> dann entweder more oder besser cat device eingeben.
> (einige Geräte können nur in einem Stream ausgelesen werden)
> Da siehst Du erstmal alle gefundenen Geräte.
> Da müßte Dein Grät auch auftauchen. Mit allen Informationen die usb so
> hergibt,
> da Dein HID ja ein generic Device ist und nicht ein spezial Treiber
> benötigt).
> Nun mußt Du nur noch an die Information im Programm kommen.
> Wie gesagt, es ist nicht so einfach. Du mußt pracktisch in Deinem Programm
> eine Datenstruktur für ein USB Gerät anlegen und diese mit den usb..*
> Routinen
> füttern.
> Wenn ich Zeit hätte, würde ich schon bald selber einen Treiber
> zusammenbauen.
> Schau Dir mal in Ruhe den Quellcode von libgphoto2-2.1.1.tar.gz an.
> Dann müßtet Du
> Dein Treiber erstellen können.(Quelle: www.gphoto.org)
>
> Der Quellauschnitt ist frei von mir aus den original Quellen entnommen
> und dient als
> Demostrationzwecken. Alle Rechte bleiben beim jeweiligen Eigentümer.
>
> Der Quellausschnit ist im Paket libgphoto2 entnommen worden.
> Entpackt im root Verzeichniss mit neu angelegtem gphoto Verzeichniss
> ergibt:
>
> Pfad ist: /gphoto/libgphoto2-2.1.1/libgphoto_port
> Datei ist libusb.c Zeile 375
>
> Diese Routine sucht am usb nach idvendor und idprodukt. Und hier mußt Du
> eben nach Deinem IC suchen. Vorher hat man ja die Datenstrukturen
> angelegt und hat dann bei erfolgreicher Suche den Zugriff mit usb-Routinen
> (siehe /usr/include/usb.h) auf das USB Gerät.
>
> Ich würde dieses Projekt auch in einfachem C programmieren.Wenn das
> erstmal läuft
> kannst Du Deine Hauptanwendung ja mit C++ gestallten. Denn da kann man
> auch auf
> C Routinen zurückgreifen.
>
> mfg Michael
>
> static int
> gp_port_usb_find_device_lib(GPPort *port, int idvendor, int idproduct)
> {
> struct usb_bus *bus;
> struct usb_device *dev;
>
> if (!port)
> return (GP_ERROR_BAD_PARAMETERS);
>
> /*
> * NULL idvendor is not valid.
> * NULL idproduct is ok.
> * Should the USB layer report that ? I don't know.
> * Better to check here.
> */
> if (!idvendor) {
> gp_port_set_error (port, _("The supplied vendor or product
> " "id (0x%x,0x%x) is not valid."),
> idvendor,idproduct);
> return GP_ERROR_BAD_PARAMETERS;
> }
>
> for (bus = usb_busses; bus; bus = bus->next) {
> for (dev = bus->devices; dev; dev = dev->next) {
> if ((dev->descriptor.idVendor == idvendor) &&
> (dev->descriptor.idProduct == idproduct)) {
> int config, interface, altsetting;
>
> port->pl->d = dev;
>
> gp_log (GP_LOG_VERBOSE, "gphoto2-port-usb",
> "Looking for USB device "
> "(vendor 0x%x, product
> 0x%x)...found.",
> idvendor, idproduct);
>
> /* Use the first config, interface and
> altsetting we find */
>
> gp_port_usb_find_first_altsetting(dev,&config, &interface, &altsetting);
>
> /* Set the defaults */
> if (dev->config) {
> port->settings.usb.config =
> dev->config[config].bConfigurationValue;
> port->settings.usb.interface =
> dev->config[config].interface[interface].altsetting[altsetting].bInterfaceN
>umber; port->settings.usb.altsetting =
> dev->config[config].interface[interface].altsetting[altsetting].bAlternateS
>etting;
>
> port->settings.usb.inep =
> gp_port_usb_find_ep(dev, config, interface, altsetting,
> USB_ENDPOINT_IN,USB_ENDPOINT_TYPE_BULK);
> port->settings.usb.outep =
> gp_port_usb_find_ep(dev, config, interface, altsetting,
> USB_ENDPOINT_OUT,USB_ENDPOINT_TYPE_BULK);
> port->settings.usb.intep =
> gp_port_usb_find_ep(dev, config, interface, altsetting,
> USB_ENDPOINT_IN,USB_ENDPOINT_TYPE_INTERRUPT);
> gp_log
> (GP_LOG_VERBOSE,"gphoto2-port-usb",
> "Detected defaults:
> config %d,"
> "interface %d,
> altsetting %d,"
> "inep %02x, outep
> %02x,intep %02x",
> port->settings.usb.config,
>
> port->settings.usb.interface,
>
> port->settings.usb.altsetting,
> port->settings.usb.inep,
> port->settings.usb.outep,
> port->settings.usb.intep
> );
> }
>
> return GP_OK;
> }
> }
> }
>
> gp_port_set_error (port, _("Could not find USB device "
> "(vendor 0x%x, product 0x%x). Make sure this device "
> "is connected to the computer."), idvendor, idproduct);
> return GP_ERROR_IO_USB_FIND;
> }
>
> >Tux007






Sorry, aber der Code ist zu hoch für mich!!!

Tux007

< Previous Next >
Follow Ups