How to connect an OutputStream to an UsbDeviceConnection in Android? - usb

I need to connect an Android device to a thermal printer (DDP-250) thru an USB cable.
The Android device has USB Host capabilities.
The thermal printer has an USB interface.
So far, I'm already able to create an UsbDeviceConnection to the printer.
The tricky part is that the printer's SDK works based on an OutputStream to send data to the device.
From the javadoc:
Printer(java.io.OutputStream out)
Constructs a new instance of this class from a given OutputStream.
This means that sending data using UsbDeviceConnection.bulkTransfer is not an option.
I need to, somehow, get an OutputStream that streams data to the UsbDeviceConnection.
I even thought about using UsbDeviceConnection.getFileDescriptor to create a FileOutputStream, but UsbDeviceConnection.getFileDescriptor just returns an integer.
Oh, just to be clear, i know this printer has a bluetooth interface. But while using it, i was having wifi instability problems. And i need to have access to both, wifi internet and the printer, at the same time. I also tried to connect the android device to the internet using an usb/ethernet adapter (in this case the thermal printer would stay connected thru Bluetooth), but this android device does not have ethernet capabilities.
Any ideas? Anything at all. I'll take anything, even the recommendation of another thermal printer.
Thanks!

file descriptor (FD) is an abstract indicator for accessing a file.
so I think following statement will work.
public FileOutputStream (FileDescriptor fd);
Constructs a new FileOutputStream that writes to fd.

Related

USB packet and data buffer capture

I need a software or application with API support to capture USB packet and data buffer. I would like to analyse the captured data using LabVIEW.
Suggest applications for usb packet and data capture with API support, so that I can access them using LabVIEW.
Or
Alternate methods to capture and analyse usb data using LabVIEW
I had tried a approach using logman.exe . But that doesn't log all the USB packets. Has anyone tried logman to capture the usb packets?
you can consider using VISA functions.
A few examples are shipped with Labview (open example finder and look for USB).
Here is a starting point giving instructions about how to give VISA access to the device.
You need find out some windows dll's and use it in labview. the examples provided for NI USB devices.

Understanding "driverless" USB HID

I'm at the beginning of trying to develop a USB HID bootloader for a Kinetis processor, and getting no help from that department. I have made some modifications to Kinetis firmware designed for a similar processor(I'm using the KL26Z, the original code is for KL25Z), and I do now see the beginning of the USB enumeration(on a PC running W7). However, the PC asks for driver software, and I don't understand why, as I thought the whole point of going the HID route was that one didn't need to install drivers. So the device shows up under device manager, but as a non-working problem device. My problem is that I don't really know what should happen. Any insights would be welcome.
Here's what should happen: the computer will ask your device for its USB descriptors when it detects your device. The descriptors must have certain fields like bDeviceClass set properly to indicate that it is an HID. If the computer sees those fields, it will attach the HID driver to your device.
In the Device Manager, you should look at the "Compatible Ids" of your device. Do you see USB\Class_03 in that list? If so, that should match the driver input.inf that comes with Windows, so the INF file will be applied to your device, and you device will show up as "USB Input Device" in the Device Manager. If you don't see USB\Class_03 in your list then there is probably some problem with your device's USB descriptors or its USB stack.

Read Data Across USB Port

I'm playing around with an old Trackball I purchased from Sparkfun. My trackball powers on, but it doesn't actually work. All the lights flash, and it indicates that I've left and right clicked, but the mouse on my screen does nothing.
I want to monitor the input values of the trackball across a USB port so I can track down the problem. I've looked for code I can run on Netbeans, but came up empty handed.
Please advise
You didn't specified what OS are you using. You need dedicated driver for this device. In case of Linux you would need to write your own driver for the kernel. But first you need to have specification of protocol which this device is using over usb and also usb protocol itself. It is quite sophisticated task to do...
In case of Windows there are some programs for dumping transmission between usb host (PC) and device (trackball), but at the moment I can't give you any name of such program. In case of Linux you can dump the transmission using tcpdump or wireshark commands.

USB device design for an embedded MCU

I am working on a product with an LPC1788 which needs the following USB features:
Firmware download (from host PC to device, not through a USB
key).
File upload (from device to host).
Ideally we'd also be able to get some information from the device like serial number etc.
The device should only work with a custom Windows application, so simply using a mass-storage device as-is will not do. There are quite a lot of data to upload (200MB +), so using USB bulk transfers seem necessary to me.
What is the best way to approach this? I imagine I would need to create some sort of USB composite device(?). However, I was hoping to use nxpUSBlib or winUSB so I don't have to go through the Windows driver validation process.... What are my options? Perhaps there some way to make the mass-storage device invisible for Windows?
Thanks!
Dirk
I think you'll definitely want to go with a vendor specific bulk device and you can easily use WinUSB for all of this. This should be sufficient for everything you've specified here.
For your firmware loader I'd recommend looking at the DFU (device firmware update) specification. You'll probably want make some command for your device that when sent will cause it to reenumerate itself in to DFU mode for update (rather than a composite device that is always exposed - this restricts the issue of the other interface being in use while you're flashing your device). Then you can flash it and reset it so it will reenumerate as your vendor specific bulk device again.
I wouldn't recommend mucking with mass storage, from your requirements it will be better to implement your own protocol and create some application or DLL that consumes the WinUSB API to communicate with your device, including the firmware update.

Access SmartCards from Windows 8 Store App (WinRT)

In a Windows 8 Store App I would like to read Data from a SmartCard. After installing the SmartCard reader (USB Device) I can read its device path and connection state via the Windows.Devices.Enumeration namespace. Even the device interface id is retrievable (50dd5230-ba8a-11d1-bf5d-0000f805f530) and I put this as a required capability in the App's manifest file.
For the interaction with the device I use a C++ Component calling the CreateDeviceAccessInstance Method. But this call always results in an ACCESS_DENIED exception.
Further research taught me, that interacting with a custom hardware device (everything that is not a printer, microphone, mouse, ...) would need several adjustments in the device driver published to the windows 8 driver store.
I'd be glad to do so, but I am no IHV and would like to use the generic driver and the generic interface.
Could anyone give me a hint how to proceed from here and use the generic interface for USB SmartCard devices?
This is not a real answer, but I have the same problem and I have spent quite some time looking for the hard-to-find bits of information on this subject around the internet, and I'd like to share my results.
Windows 8.1 has some specific APIs for (virtual) SmartCards (API reference, sample), but it seems like they can only be used for authentication and there is no way to send APDU commands to a card at the moment (see this comment by Himanshu Soni). I guess one could use the new USB APIs to talk to the reader directly, but then you'd have to implement the whole protocol yourself.