Date: Thu, 12 Apr 2007 10:29:54 +0400 From: "Z3tbl4 []" <z3tbl4@gmail.com> To: freebsd-usb@freebsd.org Subject: FBSD 6.0 UGEN Message-ID: <437e81e00704112329h634c0b22y782f32214054b4f@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Greetings everyone! Could someone ,please, advice me a solution to solve such problem- i have an usb device, which is present in my FBSD 6.0 as /dev/ugen0 and /dev/ugen0.1 i need to send to this device 5 bytes and read from it 3 bytes but i'm not good in usb protocol and i don't get a right result . here is my test code in C. Thank you. #include <fcntl.h> #include <sys/uio.h> #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <sys/param.h> #include <errno.h> #include <unistd.h> #include <termios.h> #include <sys/ioctl.h> #include <dev/usb/usb.h> #define RBUF 3 #define WBUF 5 char *pidfile = "/var/run/pgs.pid"; char *u = 0; /* device file */ unsigned char txb[WBUF] = {0x06, 0x00, 0x00, 0x00, 0x00}; unsigned char rxb[RBUF]; unsigned char *ufd_dat; extern char *optarg; int i = 0, n , c, ret; int fd , fp; unsigned char rbuf[RBUF], wbuf[WBUF] = {0x06, 0x00, 0x00, 0x00, 0x00}; open_devs(void) { if ((fd = open(u, O_RDWR)) < 0) err(1, "cannot open %s", u); }; close_devs(void) { close(fd); }; save_pid() { fp = fopen(pidfile, "w"); if (fp != 0) { fprintf(fp, "%d\n", getpid()); fclose(fp); }; }; int main(int argc, char *argv[]) { while ((c = getopt(argc, argv, ":?hd:i:")) != -1) { switch (c) { case 'd': u = optarg; printf("Input device set to %s\n", optarg); break; case 'i': pidfile = optarg; printf("Using pid file %s\n", optarg); break; case ':': case '?': case 'h': default: break; } } if (argc < 1) { printf("Wrong number of options!\n\n"); }; save_pid(); open_devs(); ////////////////////////GET_DEVICEINFO ////////////////////////// struct usb_device_info di; ret = ioctl(fd, USB_GET_DEVICEINFO, &di); printf("ret=%d\n", ret); printf("product %s\n", di.udi_product); printf("vendor %s\n", di.udi_vendor); printf("release %s\n", di.udi_release); printf("devnames %s\n", di.udi_devnames); printf("ports %02X\n", di.udi_ports); printf("address %02X\n", di.udi_addr); //////////////////////////////////////////////////////////////// //////////////////////USB_GET_DEVICE_DESC ////////////////////// usb_device_descriptor_t udd; if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) == -1) { err(2, "%s", u); } printf("idVendor=%02X\n", UGETW(udd.idVendor)); printf("idProduct=%02X\n", UGETW(udd.idProduct)); //////////////////////////////////////////////////////////////// //////////////////////WRITE WBUF //////////////////////////////// struct usb_ctl_request dr; dr.ucr_addr = di.udi_addr; dr.ucr_data = txb; dr.ucr_request.bmRequestType = UT_WRITE_VENDOR_ENDPOINT; dr.ucr_request.bRequest = 0; USETW(dr.ucr_request.wValue, 0); USETW(dr.ucr_request.wIndex, 0); USETW(dr.ucr_request.wLength, WBUF); if (ioctl(fd, USB_DO_REQUEST, &dr) == 0) printf("write successfull!\n"); else printf("Write FAILED!\n"); printf("%2X %2X %2X %2X %2X\n", txb[0], txb[1], txb[2], txb[3], txb[4]); /////////////////////////////////////////////////////////////// /////////////////////READ RBUF ///////////////////////////////// struct usb_ctl_request rdr; rdr.ucr_addr = di.udi_addr; rdr.ucr_data = rxb; rdr.ucr_request.bmRequestType = UT_READ_VENDOR_ENDPOINT; rdr.ucr_request.bRequest = 0; USETW(rdr.ucr_request.wValue, 0); USETW(rdr.ucr_request.wIndex, 0); USETW(rdr.ucr_request.wLength, 0); if (ioctl(fd, USB_DO_REQUEST, &rdr) != 0) printf("READ FAILED!\n"); else printf("READ: %2X %2X %2X\n", rxb[0], rxb[1], rxb[2]); /////////////////////////////////////////////////////////////// close_devs(); exit(0); } ./Ugen_test -d /dev/ugen0 Input device set to /dev/ugen0 ret=0 product SOBAKA 2.2 ( WDT + DS + Amp ) vendor PGS release 0.02 devnames ugen0 ports BFBFEA84 address 02 idVendor=777 idProduct=FF77 write successfull! 6 0 0 0 0 READ: 0 0 0
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?437e81e00704112329h634c0b22y782f32214054b4f>