int HostIO_CyUSB::OpenEx(CameraID cID) { int numDevs; USHORT VID; USHORT PID; bool bFoundDevice = false; m_log->Write(2, _T("OpenEx name: %s"), cID.SerialToOpen.c_str()); numDevs = cyusb_open(); for (int i = 0; i < (int)numDevs; i++) { h = cyusb_gethandle(i); VID = cyusb_getvendor(h); PID = cyusb_getproduct(h); std::string SerialNum = std::string("None"); GetSerialNumber(SerialNum); std::string SerialToOpen = SerialNum; std::string Desc = std::string("None"); GetDesc(Desc); m_log->Write(2, _T("Dev %d:"), i); m_log->Write(2, _T(" SerialNumber=%s"), SerialNum.c_str()); m_log->Write(2, _T(" Description=%s"), Desc.c_str()); if (VID == QSICyVID && PID == QSICyPID && SerialNum == cID.SerialToOpen ) { m_log->Write(2, _T("USB Open found QSI Cy device at index: %d, Serial: %s, Description: %s"), i, SerialNum.c_str(), Desc.c_str()); bFoundDevice = true; break; } } if (bFoundDevice && cyusb_kernel_driver_active(h, 0) == 0 && cyusb_claim_interface(h, 0) == 0) { SetTimeouts(READ_TIMEOUT, WRITE_TIMEOUT); } else { m_log->Write(2, "No devices matched"); } m_log->Write(2, _T("OpenEx Done.")); return bFoundDevice ? ALL_OK : ERR_USB_OpenFailed; }
int main(int argc, char **argv) { int r; char user_input = 'n'; pthread_t tid1, tid2; program_name = argv[0]; while ( (next_option = getopt_long(argc, argv, short_options, long_options, NULL) ) != -1 ) { switch ( next_option ) { case 'h': /* -h or --help */ print_usage(stdout, 0); case 'v': /* -v or --version */ printf("%s (Ver 1.0)\n",program_name); printf("Copyright (C) 2012 Cypress Semiconductors Inc. / ATR-LABS\n"); exit(0); case 't': /* -t or --timeout */ timeout_provided = 1; timeout = atoi(optarg); break; case '?': /* Invalid option */ print_usage(stdout, 1); default : /* Something else, unexpected */ abort(); } } validate_inputs(); r = cyusb_open(); if ( r < 0 ) { printf("Error opening library\n"); return -1; } else if ( r == 0 ) { printf("No device found\n"); return 0; } if ( r > 1 ) { printf("More than 1 devices of interest found. Disconnect unwanted devices\n"); return 0; } h1 = cyusb_gethandle(0); if ( cyusb_getvendor(h1) != 0x04b4 ) { printf("Cypress chipset not detected\n"); cyusb_close(); return 0; } r = cyusb_kernel_driver_active(h1, 0); if ( r != 0 ) { printf("kernel driver active. Exitting\n"); cyusb_close(); return 0; } r = cyusb_claim_interface(h1, 0); if ( r != 0 ) { printf("Error in claiming interface\n"); cyusb_close(); return 0; } else printf("Successfully claimed interface\n"); r = pthread_create(&tid1, NULL, reader, NULL); r = pthread_create(&tid2, NULL, writer, NULL); while ( 1) { pause(); } cyusb_close(); return 0; }
int main(int argc, char **argv) { int rStatus; libusb_config_descriptor *configDesc; const struct libusb_endpoint_descriptor *endpoint; const struct libusb_interface *interface0 ; int num_bytes, maxPacketSize, numEndpoints, ep_index_out = 0, ep_index_in = 0; unsigned short int temp, ep_in[8], ep_out[8]; if (argc != 2){ printf ("Usage is ./cybulk_reader <num of bytes> \n Ex ./cybulk_reader 1024 \n"); return -1; } rStatus = cyusb_open(); if ( rStatus < 0 ) { printf("Error opening library\n"); cyusb_close(); return -1; } else if ( rStatus == 0 ) { printf("No device found\n"); cyusb_close(); return 0; } num_bytes = atoi (argv[1]); printf ("Number of bytes is %d ", num_bytes); h1 = cyusb_gethandle(0); rStatus = cyusb_kernel_driver_active(h1, 0); if ( rStatus != 0 ) { printf("kernel driver active. Exitting\n"); cyusb_close(); return 0; } rStatus = cyusb_claim_interface(h1, 0); if ( rStatus != 0 ) { printf("Error in claiming interface\n"); cyusb_close(); return 0; } rStatus = cyusb_get_config_descriptor (h1, 0, &configDesc); if (rStatus != 0){ printf ("Could not get Config descriptor \n"); cyusb_close(); return -1; } //Finding the endpoint address interface0 = configDesc->interface; numEndpoints = interface0->altsetting->bNumEndpoints; endpoint = interface0->altsetting->endpoint; while (numEndpoints){ if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN){ ep_in [ep_index_in] = endpoint->bEndpointAddress; ep_index_in++; } else{ ep_out [ep_index_out] = endpoint->bEndpointAddress; ep_index_out++; } numEndpoints --; endpoint = ((endpoint) + 1); } //Choosing 1 endpoint for read and one for write if (ep_in[0] == 0){ printf ("No IN endpoint in the device ... Cannot do bulk write\n"); cyusb_free_config_descriptor (configDesc); cyusb_close(); return -1; } gl_ep_in = ep_in [0]; gl_ep_out = ep_out [0]; printf ("The Endpoint address is 0x%x \n", gl_ep_in); maxPacketSize = cyusb_get_max_packet_size (h1, gl_ep_in); if (((num_bytes % maxPacketSize) + 1) != 1){ printf ("Number of bytes to read should be multiple of %d--The EP max packetsize \n", maxPacketSize); cyusb_free_config_descriptor(configDesc); cyusb_close(); return -1; } bulk_reader (num_bytes); cyusb_free_config_descriptor(configDesc); cyusb_close(); return 0; }