Explore Public Snippets
Found 3,394 snippets matching: usb
public by cghersi 105512 654 11 10
Java: read from USB using RXTX library
import gnu.io.*; import java.io.*; import java.util.Enumeration; import java.io.IOException; /** * This class provides the utilities to read the data exchanged via USB port. */ public class USBComm implements SerialPortEventListener { /** * Stream for the storage of incoming data */ private InputStream inputStream; /** * Stream for the dispatching of data */ private OutputStream outputStream; /** * Timeout of the USB port */ private final int PORT_TIMEOUT = 2000; /** * Representation of the serial port used for the communication */ private SerialPort serialPort; /** * Buffer that stores the received bytes from the media */ protected LinkedBlockingQueue<Byte> receivedBytes; /** * Builds a new manager for the communication via USB port. * @exception IOException if an error occurred during the opening of the USB port */ public USBComm() throws IOException { receivedBytes = new LinkedBlockingQueue<Byte>(100000); String port = "COM1"; //place the right COM port here, OS dependent //Check that the USB port exists and is recognized: Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers(); boolean portFound = false; CommPortIdentifier portId = null; while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println.info(portId.getName()); if (portId.getName().equals(port)) { System.out.println("Found port: " + port); portFound = true; break; } } } if (!portFound) throw new IOException("port " + port + " not found."); try { System.out.println("USB port opening..."); serialPort = (SerialPort) portId.open("USBCommunicator", PORT_TIMEOUT); System.out.println("USB port opened"); inputStream = serialPort.getInputStream(); outputStream = serialPort.getOutputStream(); serialPort.addEventListener(this); serialPort.notifyOnDataAvailable(true); //#==================================================================# // WARNING! - DO NOT SET THE FOLLOWING PROPERTY WITH RXTX LIBRARY, IT // CAUSES A PROGRAM LOCK: // serialPort.notifyOnOutputEmpty(true); //#==================================================================# //wait for a while to leave the time to javax.comm to //correctly configure the port: Thread.sleep(1000); int baudRate = 115200; //set propertly serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); System.out.println("setted SerialPortParams"); } catch (Exception e) { System.err.println(e.getMessage()); throw new IOException(e.getMessage()); } } public void closeUSB(){ //close the streams for serial port: try { inputStream.close(); outputStream.close(); } catch (IOException e) { System.err.println("Cannot close streams:" + e.getMessage(), e); } } /** * Listener for USB events * * @param event new event occurred on the USB port */ public void serialEvent(SerialPortEvent event){ switch (event.getEventType()) { case SerialPortEvent.BI: case SerialPortEvent.OE: case SerialPortEvent.FE: case SerialPortEvent.PE: case SerialPortEvent.CD: case SerialPortEvent.CTS: case SerialPortEvent.DSR: case SerialPortEvent.RI: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: //nothing to do... break; case SerialPortEvent.DATA_AVAILABLE: byte received = -1; do { try { received = (byte)inputStream.read(); } catch (IOException e) { System.err.println("Error reading USB:" + e.getMessage()); } synchronized (receivedBytes) { try { receivedBytes.add(received); } catch (IllegalStateException ew) { System.err.println(ew.getMessage()); receivedBytes.poll(); receivedBytes.add(received); } } } while(received != -1); break; } } protected void write(byte[] buffer){ try { outputStream.write(buffer); outputStream.flush(); } catch (IOException e) { System.err.println("Cannot write:" + e.getMessage()); } } }
public by mporru 26294 420 11 4
Detect USB removable drive in Java
String driveLetter = ""; FileSystemView fsv = FileSystemView.getFileSystemView(); File[] f = File.listRoots(); for (int i = 0; i < f.length; i++) { String drive = f[i].getPath(); String displayName = fsv.getSystemDisplayName(f[i]); String type = fsv.getSystemTypeDescription(f[i]); boolean isDrive = fsv.isDrive(f[i]); boolean isFloppy = fsv.isFloppyDrive(f[i]); boolean canRead = f[i].canRead(); boolean canWrite = f[i].canWrite(); if (canRead && canWrite && !isFloppy && isDrive && (type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile"))) { log.info("Detected PEN Drive: " + drive + " - "+ displayName); driveLetter = drive; break; } } if (driveLetter.equals("")) { // USB Drive not found // .... } else { // USB drive found: driveLetter // ... }
public by msdn 1949 1 7 0
CreateAsync: Initializes a new instance of the UsbSerialPort class.
using System; using System.Threading.Tasks; using Windows.Devices.Usb; /// <summary> /// Initializes a new instance of the UsbSerialPort class. /// </summary> /// <param name="device"> /// UsbDevice, whose functions should be compatible with CdcControl and CdcData. /// </param> /// <returns> /// The result of Promise contains a new UsbSerialPort instance. It contains null, if failed. /// </returns> public static Windows.Foundation.IAsyncOperation<UsbSerialPort> CreateAsync( Windows.Devices.Usb.UsbDevice device ) { return Task.Run(async () => { var that = new UsbSerialPort(device); var success = await that.TryInitialize(); if (success) { return that; } else { return null; } } ).AsAsyncOperation<UsbSerialPort>(); }
external by tai 127 0 2 0
Sample USB descriptor definition for USB-CDC with Cypress EZ-USB FX2/FX2LP + SDCC
;;; -*- mode: asm; coding: utf-8 -*- ;;; ;;; USB descriptor definition for virtual COM port implementation ;;; with Cypress EZ-USB FX2 (CY7C68013) and FX2LP (CY7C68013A). ;;; ;;; NOTE: ;;; - Works with sdcc, but may need recent version due to use of ;;; assembler macros. ;;; .module DEV_DSCR ;; descriptor types DSCR_DEVICE_TYPE=1 DSCR_CONFIG_TYPE=2 DSCR_STRING_TYPE=3 DSCR_INTERFACE_TYPE=4 DSCR_ENDPOINT_TYPE=5 DSCR_DEVQUAL_TYPE=6 ;; for the repeating interfaces DSCR_INTERFACE_LEN=9 DSCR_ENDPOINT_LEN=7 ;; endpoint types ENDPOINT_TYPE_CONTROL=0 ENDPOINT_TYPE_ISO=1 ENDPOINT_TYPE_BULK=2 ENDPOINT_TYPE_INT=3 ;; ENDPOINT DIRECTION EP_IN = 0x80 EP_OUT = 0x00 ;; EP1 = 1 EP2 = 2 EP3 = 3 EP4 = 4 EP5 = 5 EP6 = 6 EP7 = 7 EP8 = 8 ;; function descriptor CS_INTERFACE = 0x24 CS_ENDPOINT = 0x25 ;; Symbols used in setupdat.c .globl _dev_dscr, _dev_qual_dscr, _highspd_dscr, _fullspd_dscr, _dev_strings, _dev_strings_end ;; Edit makefile to place this area in code memory (SUDPTRH:L requirement) .area DSCR_AREA (CODE) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Device Descriptor ;;; ;;; @see CDC120-20101103-track.pdf in http://www.usb.org/developers/docs/devclass_docs/CDC1.2_WMC1.1_012011.zip ;;; - 5.1.1 Device Descriptor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; _dev_dscr: .db dev_dscr_end - _dev_dscr ; descriptor size .db DSCR_DEVICE_TYPE ; descriptor device type .dw 0x0002 ; USB version (0x02 0x00, LSB-first) .db 0x02 ; device class = Communication Device Class (CDC) .db 0x00 ; subclass = unused .db 0x00 ; protocol = unused .db 64 ; packet size (ep0) .dw 0xB404 ; vendor id .dw 0x4717 ; product id .dw 0x0001 ; version id (1.0 = 0x01 0x00, LSB-first) .db 1 ; manufacturure string index .db 2 ; product string index .db 3 ; serial string index .db 1 ; n configurations dev_dscr_end: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Device Qualifier Descriptor ;;; ;;; A high-speed capable device that has different device information ;;; for full-speed and high-speed must have a Device Qualifier ;;; Descriptor (USB_DEVICE_QUALIFIER_DESCRIPTOR). For example, if ;;; the device is currently operating at full-speed, the Device ;;; Qualifier returns information about how it would operate at ;;; high-speed and vice-versa. ;;; ;;; @see http://www.keil.com/pack/doc/mw/usb/html/_u_s_b__device__qualifier__descriptor.html ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; _dev_qual_dscr: .db dev_qualdscr_end - _dev_qual_dscr .db DSCR_DEVQUAL_TYPE .dw 0x0002 ; USB version (0x02 0x00, LSB-first) .db 0x00 ; device class = 0x00:use interface class .db 0x00 ; device sub-class .db 0x00 ; device sub-sub-class .db 64 ; max packet .db 1 ; n configs .db 0 ; extra reserved byte dev_qualdscr_end: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Configuration for High-Speed mode ;;; ;;; [CDC] 5.1.2 Configuration Descriptor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; _highspd_dscr: .db highspd_dscr_end-_highspd_dscr ; descriptor length .db DSCR_CONFIG_TYPE ; descriptor type ;; NOTE: can't use .dw because byte order is different .db (highspd_dscr_realend-_highspd_dscr) % 256 ; total length of config (LSB) .db (highspd_dscr_realend-_highspd_dscr) / 256 ; total length of config (MSB) .db 2 ; n interfaces .db 1 ; config number .db 4 ; config string index .db 0x80 ; attriubutes (see spec for bit description) .db 50 ; max power = $val * 2[mA] highspd_dscr_end: .macro ifdesc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Interface #0.0 - Communications Class ;;; ;;; @see CDC120-20101103-track.pdf ;;; - 4 Class-Specific Codes ;;; - 5.1.3 Interface Descriptor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .db DSCR_INTERFACE_LEN .db DSCR_INTERFACE_TYPE .db 0 ; interface index .db 0 ; altsetting index .db 1 ; n endpoints .db 0x02 ; interface class = Communication Interface Class .db 0x02 ; interface sub-class = Abstract Control Model .db 0x01 ; interface protocol code class = AT Commands V.250 .db 5 ; interface descriptor string index ;; ;; 5.2.3 Functional Descriptors ;; ;; This is based on a sample functional descriptor described in ;; ;; USB Class Definition for Communication Devices ;; - Table 18: Sample Communications Class Specific Interface Descriptor ;; - http://www.usb.org/developers/docs/devclass_docs/CDC1.2_WMC1.1_012011.zip ;; - CDC120-20101103-track.pdf ;; ;; Header Functional Descriptor .db 0x05 ; size .db CS_INTERFACE .db 0x00 ; subtype = Header FD .dw 0x1001 ; bcdCDC release number (0110h, LSB-first) ;; Abstract Control Model Functional Descriptor ;; @see PSTN120.pdf, Table 4: Abstract Control Management Functional Descriptor .db 0x04 ; size .db CS_INTERFACE .db 0x02 ; subtype = ACM-FD .db 0x02 ; bmCapabilities ;; Union Functional Descriptor .db 0x05 ; size .db CS_INTERFACE .db 0x06 ; subtype = Union FD .db 0 ; bControlInterface (I/F# of Communication Class Interface) .db 1 ; bSubordinateInterface0 (I/F# of Data Class Interface) ;; Call Management Functional Descriptor ;; @see PSTN120.pdf, Table 3: Call Management Functional Descriptor .db 0x05 ; size .db CS_INTERFACE .db 0x01 ; subtype = CM-FD .db 0x00 ; bmCapabilities .db 0x01 ; bDataInterface ;; EP1 .db DSCR_ENDPOINT_LEN .db DSCR_ENDPOINT_TYPE .db EP1 + EP_IN .db ENDPOINT_TYPE_INT .db 0x10 ; max packet size (LSB) .db 0x00 ; max packet size (MSB) .db 0x02 ; polling interval ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Interface #1.0 - Data Class Interface ;;; ;;; [CDC] 4.5 Data Class Interface Codes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .db DSCR_INTERFACE_LEN .db DSCR_INTERFACE_TYPE .db 1 ; interface index .db 0 ; altsetting index .db 2 ; n endpoints .db 0x0A ; interface class = CDC-Data .db 0x00 ; interface sub-class = unused .db 0x00 ; interface protocol code class = None .db 6 ; interface descriptor string index ;; EP1 .db DSCR_ENDPOINT_LEN .db DSCR_ENDPOINT_TYPE .db EP1 + EP_OUT .db ENDPOINT_TYPE_BULK .db 0x40 ; max packet size (LSB) .db 0x00 ; max packet size (MSB) .db 0x00 ; polling interval ;; EP8 .db DSCR_ENDPOINT_LEN .db DSCR_ENDPOINT_TYPE .db EP8 + EP_IN .db ENDPOINT_TYPE_BULK .db 0x00 ; max packet size (LSB) .db 0x02 ; max packet size (MSB) .db 0x00 ; polling interval .endm ifdesc highspd_dscr_realend: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Configuration for Full-Speed mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .even _fullspd_dscr: .db fullspd_dscr_end - _fullspd_dscr ; descriptor size .db DSCR_CONFIG_TYPE ; descriptor type ;; can't use .dw because byte order is different .db (fullspd_dscr_realend - _fullspd_dscr) % 256 ; total length of config (LSB) .db (fullspd_dscr_realend - _fullspd_dscr) / 256 ; total length of config (MSB) .db 2 ; n interfaces .db 1 ; config number .db 4 ; config string index .db 0x80 ; attributes = bus powered, no wakeup .db 50 ; max power = $val * 2[mA] fullspd_dscr_end: ;; use macro to insert same descriptor as high-speed ;; ;; TODO: ;; - Enhance macro, so it can use different EP packet size ifdesc fullspd_dscr_realend: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; String Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .even _dev_strings: .macro usbstring mystr .nchr len, mystr .db 2 + len * 2 .db DSCR_STRING_TYPE .irpc c, mystr .strz ''c'' .endm .endm ;; First entry is a language id, not a string data. ;; @see http://www.usb.org/developers/docs/USB_LANGIDs.pdf .db 4 .db DSCR_STRING_TYPE .db 0x09, 0x04 ; 0x0409: U.S. English ;; Actual string data. ;; NOTE: In decsriptor, string index #0 means "No string to use" str1: usbstring ^!^/Mfg X/! str2: usbstring ^!^/Prd X/! str3: usbstring ^!^/Ser X/! str4: usbstring ^!^/Cfg1/! str5: usbstring ^!^/CommIF/! str6: usbstring ^!^/DataIF/! ;; Last entry is a sentinel to mark END-OF-STRING-TABLE .dw 0x0000 _dev_strings_end:
external by pklaus 57 0 1 0
Plugable USB-BT4LE Bluetooth 4.0 USB Adapter
This is how the bluetooth stick shows up on my computer(s): `dmesg` on Mac OS X 10.8.5: [IOBluetoothHostControllerUSBTransport][ClearFeatureInterruptEndpointHalt] -- ClearPipeStall returned e000404f (kIOUSBPipeStalled) [IOBluetoothHCIController::setConfigState] calling registerService **** [BroadcomBluetoothHostControllerUSBTransport][start] -- Completed -- this = 0xffffff8060d6cc00 **** [IOBluetoothHCIController][staticBluetoothHCIControllerTransportShowsUp] -- Received Bluetooth Controller register service notification -- controller = 0xffffff8060d6cc00 Using bluetooth controller switch policy "default" [IOBluetoothHCIController::setConfigState] calling registerService `dmesg` on Arch Linux with Linux: [49160.101769] usb 3-2: new full-speed USB device number 9 using uhci_hcd [49160.369043] usbcore: registered new interface driver btusb `lsusb`: Bus 003 Device 009: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0 `lsusb -v`: Bus 004 Device 009: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0 Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 255 Vendor Specific Class bDeviceSubClass 1 bDeviceProtocol 1 bMaxPacketSize0 64 idVendor 0x0a5c Broadcom Corp. idProduct 0x21e8 BCM20702A0 Bluetooth 4.0 bcdDevice 1.12 iManufacturer 1 Broadcom Corp iProduct 2 BCM20702A0 iSerial 3 000272CC929C bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 218 bNumInterfaces 4 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xe0 Self Powered Remote Wakeup MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 3 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x02 EP 2 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0000 1x 0 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0000 1x 0 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 1 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0009 1x 9 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0009 1x 9 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 2 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0011 1x 17 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0011 1x 17 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 3 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0019 1x 25 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0019 1x 25 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 4 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0021 1x 33 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0021 1x 33 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 5 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 1 bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0031 1x 49 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x03 EP 3 OUT bmAttributes 1 Transfer Type Isochronous Synch Type None Usage Type Data wMaxPacketSize 0x0031 1x 49 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 255 Vendor Specific Subclass bInterfaceProtocol 255 Vendor Specific Protocol iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x84 EP 4 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0020 1x 32 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x04 EP 4 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0020 1x 32 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 254 Application Specific Interface bInterfaceSubClass 1 Device Firmware Update bInterfaceProtocol 1 iInterface 0 Device Firmware Upgrade Interface Descriptor: bLength 9 bDescriptorType 33 bmAttributes 5 Will Not Detach Manifestation Tolerant Upload Unsupported Download Supported wDetachTimeout 5000 milliseconds wTransferSize 64 bytes bcdDFUVersion 1.10 Device Status: 0x0001 Self Powered `hciconfig -a hci0` hci0: Type: BR/EDR Bus: USB BD Address: 00:02:72:CC:92:9C ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING PSCAN RX bytes:3444 acl:88 sco:0 events:107 errors:0 TX bytes:1356 acl:12 sco:0 commands:72 errors:0 Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH SNIFF Link mode: SLAVE ACCEPT Name: 'owl' Class: 0x000104 Service Classes: Unspecified Device Class: Computer, Desktop workstation HCI Version: 4.0 (0x6) Revision: 0x1000 LMP Version: 4.0 (0x6) Subversion: 0x220e Manufacturer: Broadcom Corporation (15)
external by marksvdev 45 0 1 0
Android Host API: enumerating usb device and finding UsbDevice with appropriate vendor and product id.
UsbManager mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList(); Log.d(TAG, "Enumerating connected devices..."); UsbDevice mUsbDevice; // Getting the CareLink UsbDevice object Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { mUsbDevice = deviceIterator.next(); if (mUsbDevice.getVendorId() == VENDOR_ID && mUsbDevice.getProductId() == PRODUCT_ID) { break; } }
external by moyhig 348 1 3 0
USBH_MIDI_dump.ino modification to transcode output from MIDI instruments to USB HID keyboard via RN-42
--- ../USBH_MIDI/examples/USBH_MIDI_dump/USBH_MIDI_dump.ino 2015-07-07 12:17:13.000000000 +0900 +++ USBH_MIDI_dump.ino 2015-07-07 12:31:51.000000000 +0900 @@ -26,6 +26,22 @@ #include <Usb.h> #include <usbh_midi.h> +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include <spi4teensy3.h> +#include <SPI.h> +#endif + +// for Arduino Leonardo (Serial Debugging is compatible with RN-42) +#ifdef USBCON +//#define DEBUG +#define SERIAL_PORT Serial1 +#else +#define SERIAL_PORT Serial +#endif + +uint8_t pinIsConnected = 7; // GPIO2 (#13) + USB Usb; USBH_MIDI Midi(&Usb); @@ -34,21 +50,35 @@ boolean bFirst; uint16_t pid, vid; +uint8_t i_pressed, i_released; +uint8_t i_x, i_y; +uint8_t i_bank; void setup() { bFirst = true; vid = pid = 0; + i_pressed = i_released = 0; + i_x = i_y = 0; + i_bank = 0; Serial.begin(115200); +#if 0 //Workaround for non UHS2.0 Shield pinMode(7,OUTPUT); digitalWrite(7,HIGH); +#endif + // sense for RN-42 is connected + pinMode(pinIsConnected,INPUT); if (Usb.Init() == -1) { while(1); //halt }//if (Usb.Init() == -1... delay( 200 ); + +#ifdef USBCON + Serial1.begin(115200); +#endif } void loop() @@ -71,13 +101,19 @@ char buf[20]; uint8_t bufMidi[64]; uint16_t rcvd; + uint8_t size; + byte outBuf[3]; if(Midi.vid != vid || Midi.pid != pid){ +#ifdef DEBUG sprintf(buf, "VID:%04X, PID:%04X", Midi.vid, Midi.pid); Serial.println(buf); +#endif vid = Midi.vid; pid = Midi.pid; } + +#if 0 // MIDI dump if(Midi.RecvData( &rcvd, bufMidi) == 0 ){ sprintf(buf, "%08X:", millis()); Serial.print(buf); @@ -87,8 +123,197 @@ } Serial.println(""); } +#endif + if ((size = Midi.RecvData(outBuf)) > 0 ) { +#ifdef DEBUG + Serial.print(size); + Serial.print(":"); + for(int i=0; i<size; i++) { + sprintf(buf, " %02X", outBuf[i]); + Serial.print(buf); + } +#endif + if ((outBuf[0] >> 4) == 0x8) { + if (outBuf[1] < 0x24) { + i_pressed = i_released = 0; + i_x = i_y = 0; + switch (outBuf[1]) { + case 0x19: + sendMultimediaKeyCodesBySerial(0x1, 0x0); // Home Button + delay(10); + sendMultimediaKeyCodesBySerial(0, 0); + break; + case 0x18: + sendKeyCodesBySerial(0x5, 0, 0, 0, 0, 0, 0); + delay(10); + sendKeyCodesBySerial(0x5, 0x16, 0, 0, 0, 0, 0); // VO + S + delay(10); + sendKeyCodesBySerial(0x5, 0, 0, 0, 0, 0, 0); + delay(10); + sendKeyCodesBySerial(0, 0, 0, 0, 0, 0, 0); + break; + case 0x17: + if (digitalRead(pinIsConnected) == HIGH) { +#ifdef DEBUG + Serial.print(":BT is connected:"); +#endif + } else { +#ifdef DEBUG + Serial.print(":BT is not connected:"); +#endif + if (millis() < 30000) { + SERIAL_PORT.print("$$$"); // Bluetooth CMD-mode + delay(100); + //SERIAL_PORT.println("C,783A849BBC7E"); // Bluetooth re-connect + SERIAL_PORT.println("CFI"); // Bluetooth re-connect + } + } + break; + case 0x16: + sendMultimediaKeyCodesBySerial(0x10, 0x0); // Volume Up + delay(100); + sendMultimediaKeyCodesBySerial(0, 0); + break; + case 0x15: + sendMultimediaKeyCodesBySerial(0x40, 0x0); // Mute + delay(100); + sendMultimediaKeyCodesBySerial(0, 0); + break; + case 0x14: + sendMultimediaKeyCodesBySerial(0x20, 0x0); // Volume Down + delay(100); + sendMultimediaKeyCodesBySerial(0, 0); + break; + case 0x03: + case 0x02: + case 0x01: + case 0x00: + i_bank = outBuf[1]; + break; + } + } else /* if (outBuf[1] >= 24) */ { + i_released++; + + if (i_pressed <= i_released) { + uint8_t p_x = i_x * 30 / 25 / i_pressed; + uint8_t p_y = i_y * 30 / 25 / i_pressed; + uint8_t modifier = 0; +#ifdef DEBUG + Serial.print(" "); + Serial.print("released:"); + Serial.print(p_x); + Serial.print(":"); + Serial.print(p_y); +#endif + if (i_bank == 0) { + sendMultimediaKeyCodesBySerial(0x80, 0x0); // Play/Pause + delay(100); + sendMultimediaKeyCodesBySerial(0, 0); + } else { + if (i_bank == 2 /* 1 */) + modifier = 0x1; + else if (i_bank == 3 /* 2 */) + modifier = 0x4; + else if (i_bank == 4 /* 3 */) + modifier = 0x5; + + if (modifier) { + sendKeyCodesBySerial(modifier, 0, 0, 0, 0, 0, 0); + delay(10); + } + if (p_x == 0) { + sendKeyCodesBySerial(modifier, 0x50, 0, 0, 0, 0, 0); // Left Arrow + } else if (p_x == 3) { + sendKeyCodesBySerial(modifier, 0x4F, 0, 0, 0, 0, 0); // Right Arrow + } else if (p_y == 0) { + sendKeyCodesBySerial(modifier, 0x51, 0, 0, 0, 0, 0); // Down Arrow + } else if (p_y == 3) { + sendKeyCodesBySerial(modifier, 0x52, 0, 0, 0, 0, 0); // Up Arrow + } else { + sendKeyCodesBySerial(modifier, 0x51, 0, 0, 0, 0, 0); + delay(10); + sendKeyCodesBySerial(modifier, 0x52, 0, 0, 0, 0, 0); // Down+Up Arrow + delay(10); + sendKeyCodesBySerial(modifier, 0x51, 0, 0, 0, 0, 0); + } + delay(10); + if (modifier) { + sendKeyCodesBySerial(modifier, 0, 0, 0, 0, 0, 0); + delay(10); + } + sendKeyCodesBySerial(0, 0, 0, 0, 0, 0, 0); + } + + i_pressed = i_released = 0; + i_x = i_y = 0; + } + } + } else if ((outBuf[0] >> 4) == 0x9) { + if (outBuf[1] >= 0x24) { + i_pressed++; + { + uint8_t button = outBuf[1] - 0x24; +#ifdef DEBUG + Serial.println(""); + Serial.print(i_pressed); + Serial.print(":"); + Serial.print(i_released); + Serial.print(":"); + Serial.print(button, BIN); + Serial.print(":"); + Serial.print((button >> 2) & 3); + Serial.print(":"); + Serial.print(button & 3); +#endif + i_x += button & 3; + i_y += (button >> 2) & 3; + } + } + } +#ifdef DEBUG + Serial.println(""); +#endif + } +} + +void sendKeyCodesBySerial(uint8_t modifiers, + uint8_t keycode0, + uint8_t keycode1, + uint8_t keycode2, + uint8_t keycode3, + uint8_t keycode4, + uint8_t keycode5) +{ + SERIAL_PORT.write(0xFD); // Raw Report Mode + SERIAL_PORT.write(0x09); // Length + SERIAL_PORT.write(0x01); // Descriptor 0x01=Keyboard + + /* send key codes(8 bytes all) */ + SERIAL_PORT.write(modifiers); // modifier keys + SERIAL_PORT.write((uint8_t)0x00); // reserved + SERIAL_PORT.write(keycode0); // keycode0 + SERIAL_PORT.write(keycode1); // keycode1 + SERIAL_PORT.write(keycode2); // keycode2 + SERIAL_PORT.write(keycode3); // keycode3 + SERIAL_PORT.write(keycode4); // keycode4 + SERIAL_PORT.write(keycode5); // keycode5 + delay(5); +} + +void sendMultimediaKeyCodesBySerial(uint8_t keycode0, + uint8_t keycode1) +{ + SERIAL_PORT.write(0xFD); // Raw Report Mode + SERIAL_PORT.write(0x03); // Length + SERIAL_PORT.write(0x03); // Descriptor 0x01=Keyboard + + /* send key codes(8 bytes all) */ + SERIAL_PORT.write(keycode0); // keycode0 + SERIAL_PORT.write(keycode1); // keycode1 + delay(5); } +#if 0 // Delay time (max 16383 us) void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) { @@ -104,3 +329,4 @@ delayMicroseconds(delayTime - t3); } } +#endif
external by Guitsou 314 0 3 0
Authentification avec le PAM USB : se connecter avec une clé USB, et verrouiller la session automatiquement... Tutorial Ubuntu 13.04 / LXDE Sources : http://doc.ubuntu-fr.org/tutoriel/pam-usb /
## Installation des paquets ```bash sudo apt-get update && sudo apt-get install libpam-usb pamusb-tools ``` _Il est possible de compiler le paquet pour les distributions n'ayant pas de paquet..._ ## Ajout de clés et utilisateurs ### Ajouter une nouvelle clé USB Insérer la clé USB désirée (fonctionne avec une carte de type SD). Vérifier : - qu'il n'y a pas d'autres clés (évite les confusions !) - que cette clé est bien accessible (/media...) ```bash sudo pamusb-conf --add-device nom_de_ma_clé ``` _avec nom_de_ma_clé correspond à un nom descriptif... PamUSB propose les clés dispo_ ```bash Please select the device you wish to add. * Using "SanDisk Corp. Cruzer Titanium (SNDKXXXXXXXXXXXXXXXX)" (only option) Which volume would you like to use for storing data ? * Using "/dev/sda1 (UUID: <6F6B-42FC>)" (only option) Name : MyDevice Vendor : SanDisk Corp. Model : Cruzer Titanium Serial : SNDKXXXXXXXXXXXXXXXX Volume UUID : 6F6B-42FC (/dev/sda1) Save to /etc/pamusb.conf ? [Y/n] y Done. ``` Valider en tapant "y" si c'est bien le bon périphérique... ### Ajouter un utilisateur Choisir le compte système à associer et taper : ```bash sudo pamusb-conf --add-user nom_d_utilisateur ``` _On obtient_ ```bash Which device would you like to use for authentication ? * Using "MyDevice" (only option) User : nom_d_utilisateur Device : MyDevice Save to /etc/pamusb.conf ? [Y/n] ``` Saisir Y. ### Vérification Pour vérifier que le processus mis en place fonctionne (association clé usb / user) : ```bash $ pamusb-check nom_d_utilisateur * Authentication request for user "nom_d_utilisateur" (sudo) * Device "MyDevice" is connected (good). * Performing one time pad verification... * Access granted. ``` ### Troubleshoot Si à ce stade ça ne marche pas, faire un truc du genre : ```bash sudo apt-get remove --purge libpam-usb pamusb-tools && sudo apt-get autoremove && sudo apt-get install libpam-usb pamusb-tools ``` _Oui, je sais que c'est pas original et que ce n'est pas du troubleshoot !_ Maintenant qu'on a déclaré une clé et un user, on configure PAM... ## Et PAM le chien... Sauvegarder l'ancienne conf (si si, quand même !!!) ```bash sudo cp /etc/pam.d/common-auth /etc/pam.d/common-auth.back ``` et éditer le fichier common-auth... Deux modes : soit clé nécessaire (clé + mot de passe) soit clé suffisante (clé ou mot de passe). Rechercher donc la ligne contenant auth *** pam_usb.so et remplacer soit par : ```bash auth required pam_usb.so ``` soit ```bash auth sufficient pam_usb.so ``` A ce stade, on peut déjà tester le login avec la clé : - Fermer la session - Mettre la clé USB et cliquer sur le user défini plus tôt : il ne demandera plus de mot de passe mais vous loggera directement... _Etape suivante : le verrouillage / déverrouillage de session automatique..._ ### Mise en place du PamUSB-agent Le PamUSB-agent scrute en permanence le plug-deplug des périphériques pour appliquer si nécessaire des actions. #### Configuration Editer /etc/pamusb.conf. Sous la section de votre utilisateur rajouter : ```bash <agent event="lock">gnome-screensaver-command --lock</agent> <agent event="unlock">gnome-screensaver-command --deactivate</agent> ``` _Remplacer gnome-screensaver-command par votre économiseur préféré !_ La section ressemblera à quelque-chose comme : ```bash ... <user id="vincent"> <device> transcend_vincent </device> <agent event="lock">gnome-screensaver-command --lock</agent> <agent event="unlock">gnome-screensaver-command --deactivate</agent> </user> ... ``` #### Lancement au démarrage du PamUSB-agent Sous LXDE, le plus propre c'est de créer un fichier .desktop dans ~/.config/autostart. Voici le mien : pamusb-agent.desktop ```bash [Desktop Entry] Type=Application Exec=/usr/bin/pamusb-agent --daemon Hidden=true NoDisplay=false X-GNOME-Autostart-enabled=true Name[fr_FR]=DpB Name=PamUSB-Agent Comment[fr_FR]= Comment= ``` <center>== Fin de la procédure ==</center>
external by Jeffrey Carpenter 20090 1 3 0
AppleUSBXHCIPCI kext patch for removing the USB 3 Cap of 15 ports
<!-- SOURCE: http://www.insanelymac.com/forum/topic/308325-guide-1011-full-speed-usb-series-89-keeping-vanilla-sle/page-23#entry2210241 --> <dict> <key>Comment</key> <string>Remove USB limit</string> <key>Find</key> <data> g72M/v//EA== </data> <key>Name</key> <string>AppleUSBXHCIPCI</string> <key>Replace</key> <data> g72M/v//Fg== </data> </dict>
external by Alex Gray 172 0 2 0
Example code to get USB device properties for a given instance of ORSSerialPort. Will only work for USB-to-serial adapters, not internal serial ports. Based on https://gist.github.com/rhwood/4124251.
#import <Foundation/Foundation.h> #import <IOKit/usb/USBSpec.h> #import "ORSSerialPort.h" @interface ORSSerialPort (Attributes) @property (nonatomic, readonly) NSDictionary *ioDeviceAttributes; @property (nonatomic, readonly) NSNumber *vendorID; @property (nonatomic, readonly) NSNumber *productID; @end @implementation ORSSerialPort (Attributes) - (NSDictionary *)ioDeviceAttributes { NSDictionary *result = nil; io_iterator_t iterator = 0; if (IORegistryEntryCreateIterator(self.IOKitDevice, kIOServicePlane, kIORegistryIterateRecursively + kIORegistryIterateParents, &iterator) != KERN_SUCCESS) return nil; io_object_t device = 0; while ((device = IOIteratorNext(iterator)) && result == nil) { CFMutableDictionaryRef usbProperties = 0; if (IORegistryEntryCreateCFProperties(device, &usbProperties, kCFAllocatorDefault, kNilOptions) != KERN_SUCCESS) { IOObjectRelease(device); continue; } NSDictionary *properties = CFBridgingRelease(usbProperties); NSNumber *vendorID = properties[(__bridge NSString *)CFSTR(kUSBVendorID)]; NSNumber *productID = properties[(__bridge NSString *)CFSTR(kUSBProductID)]; if (!vendorID || !productID) { IOObjectRelease(device); continue; } // not a USB device result = properties; IOObjectRelease(device); } IOObjectRelease(iterator); return result; } - (NSNumber *)vendorID; { return [self ioDeviceAttributes][(__bridge NSString *)CFSTR(kUSBVendorID)]; } - (NSNumber *)productID; { return [self ioDeviceAttributes][(__bridge NSString *)CFSTR(kUSBProductID)]; } @end