Reconnect USB device (ACR122U) without unplugging - java

I'm working on a NFC project and sometimes my reader is get messed up and i can't reconnect to it. If i re-plug the USB cable everything is fine. Can you do this in Java to without a physical re-plug?
If it can't, is there maybe an other way to do this?

The USB protocol does have a thing called a Reset signal, but actually using it depends heavily on what operating system you are using and what drivers the OS is using for your device.
You might try using libusb and running libusb_reset_device, which is documented here:
http://libusb.sourceforge.net/api-1.0/group__dev.html#ga7321bd8dc28e9a20b411bf18e6d0e9aa

you need to ask yourself why it's happend
maybe it's not a good idea to use on libusb_reset_device
you need first get the libusb_device_handle

Related

Sending data via bluetooth between Android phone and laptop running OS X

It seems like a relatively mundane task to make an app that can send data via bluetooth but I've been banging my head on this for the past few days so I'm looking for any ideas. I'm running OS X 10.10 and using a Nexus 5 Android device. Here's what I've tried so far:
I need a server program running on my laptop and I need a client-side android app running on my phone. However, (correct me if I'm wrong) the server program running on my computer needs to be able to access the Android Bluetooth API because I need to use the BluetoothServerSocket (based on the server-side code provided in Google's Android Bluetooth tutorial).
Since it's server-side code, I need to run it on a server so I built a Java Servlet which I ran from inside Eclipse but I didn't know how to access the Android API from inside a dynamic web application.
So I started following this approach where the Bluecove library made that possible: http://luugiathuy.com/2011/02/android-java-bluetooth/
I tried getting Bluecove to work with OS X but there are a whole host of issues involved with that. I found some workarounds and then got an error dealing with the IOBluetoothLocalDeviceReadSupportedFeatures device that Apple removed in its later OS versions (but Bluecove depended on it).
I found a fix here that installed the old IOBluetooth library and changed the DYLD_LIBRARY_PATH to point to it. Unfortunately, this had no effect (I don't know if I changed the library path properly...I followed the instructions from Solution 1 in the answer from this post).
In any event, I feel like I'm overcomplicating this task and am looking for any guidance - in terms of overall approach or a specific thing I missed. The primary issue is accessing the Android Bluetooth API inside the server program intended to run on my laptop.
I eventually ended up using WiFi to send data since there was better software support for that.
But if someone wants to pursue the Bluetooth path, one possibility is to run OS X Lion (which had the IOBluetooth library) as a VM and run the server-side Bluecove code on the VM. This would require a separate Bluetooth USB dongle to be attached because the VM can't access the bluetooth hardware of its host machine - there may be a way but by default it can't access the in-built bluetooth hardware.
Not an ideal solution but I don't know if there is much choice until Bluecove releases a version that is supported on recent OS versions.

Detecting if a mouse is wireless

I am trying to detect whether a wireless mouse is present on a computer. I would like my program to run in the background. I would prefer to do this in Java however if this goes beyond Java's capabilities I can use another language.
Can someone please get me started?
(This seems like a Google-able question but I cannot find anything)
This is beyond Java and is highly OS-specific. You have to query the appropriate device drivers for the operating system; for example, on Linux this would mean looking up information in the evdev system. Note that the particular "type" of wireless will matter a lot, and you may not be able to tell in any reliable way. For example, a Bluetooth mouse is always wireless, but some wireless devices connect with a USB dongle and may not be distinguishable from a wired USB device.

Detect current with USB and Java

To check if a 'switch' is open or closed and detecting that in Java, I have the following plan: I won't use the data pins, just the USB 5V current, and if the switch is closed there is a current, which I should detect in Java, and so it will be processed by my program.
Would there be a simple solution for this or do I need to find and try out a whole Java usb library for it, of which I would use just a tiny little bit?
Thanks in advance
This will not work in the way you describe it. Have you ever connected a gadget like USB lamp or USB fan? Then you would know that the Software/OS does not even know about them.
The USB spec says you can draw up to 100mA from a port without telling anyone about it, and 500mA when declared in the USB protocol. Most USB HDDs draw quite some more than the allowed 500mA maximum USB2 current.
To make your application work, you absolutely need a device which can talk over USB. This could be an USB=>RS232 adapter (which your application can talk to using RXTX) or a HID device like a USB Joystick. Joysticks can have buttons and switches.
You could try RXTX. This is a library written for serial communication with Java. http://users.frii.com/jarvi/rxtx/. You will have to use native libraries, and I don't know if it would be able to detect if there is a current or not on the USB.

Networking with ios

I have an application that was written in Java and runs on the users machine. I now want to build an application on the iPhone which will communicate with my java app.
Can somebody point me in the right direction on how I can send and receive TCP packets with the iPhone, I want to of course be able to do that using wifi and 3G.
Thanks,
You use the NSStream classes. I've found it pretty easy to use.
See the SimpleNetworkStreams for an example.
One problem I found is that the iphone sdk does not include the NSStream method getStreamsToHost:port:inputStream:outputStream: which is what Mac OS examples use to open a NStream connection but there are lots of places that show you how to create your own like here.

SWT: Getting notified of a system device change (USB device connection / disconnection)

I'm writing an SWT application which needs to sit in the system tray and pop up automatically whenever the user connects some USB device (the application serves as its control panel).
The way to do this in the native environment (win32 in this case, but I should be platform-independent ultimately) is to listen to the WM_DEVICECHANGE event, then checking if my device has been disconnected.
Googling the subject, it seems like SWT does not in fact handle this type of event. Does anyone have any idea as to how to achieve this? My fallback solution would be sampling the USB port every n seconds, looking for the device, but this is a no-no solution as far as I'm concerned...
Thanks and cheers
Shai
EDIT: J-16 SDiZ reported that the API exists for Windows too
Here is a very good article about Access USB devices from Java applications
The described jUSB module contains a USBListener object.
Interface implemented by objects that want to monitor USB structure. The order in which these changes are reported is not necessarily going to be the order in which the changes were seen in the real world, and delays also occur.
Youre SWt object can implement this listener and do something, when the method
deviceAdded(Device dev)
is fired
Java does not provide direct interaction with the devices and with USB. There are several third-party libraries for Java that provide USB-related features (read/write from USB port). For example: http://www.icaste.com/ (commercial)
Your comment for Zorglub suggests that you have some (presumably) JNI/JNA code to call the 3rd party DLL you mentioned. I assume you could also write a JNI wrapper to the Windows API where you can register to be notified for the _WM_DEVICECHANGE_ event you mentioned.
There is a jUSB port for windows at http://www.steelbrothers.ch/jusb/

Categories

Resources