Detecting if a mouse is wireless - java

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.

Related

Connect to hardware device attached with USB cross platform

I have hardware a plotter machine. This device doesn't have any kind of driver. When I attached USB cable of this hardware to my machine(windows) it comes under "unspecified device" in control panel -> printers and devices. I want to build an application which can connect to this hardware (plotter without driver) connected via USB. I have checked with usb4java but it din't work. Can you guys please help me. ?
My application must be able to run in any platform, so in any machine I can just attached usb cable and my application must be able to detect the hardware and able to get connection.
Thanks.
You should also try asking the manufacturer for the device's Windows drivers.
If the device doesn't have any Windows drivers, without knowing anything about your device, I would suggest that you use Zadig to attach WinUSB (Microsoft's generic USB device driver) to your printer. Then you can use libusb to write a cross-platform application that detects the machine and talks to it.
However, it might be that your device actually belongs to particular USB device class, such as the CDC ACM class. In that case, it would be better to install the drivers for that particular class. You can get your driver's descriptors using the Linux lsusb utility and examine them to see what class your device is.

Possible to Run a Java GUI on a computer from an Android?

If an Android device were connected to a computer via USB charger, would it be possible to launch a java GUI on the computer from the device (i.e. by pressing a button in an android app)?
Also, would this be a platform dependency nightmare?
Possible yes, not easy though and there may be some platform issues.
You would already need to have something running on the destination computer which detected the message from Android and then launched the GUI.
In fact the simplest way to do that may be to ignore the USB and just do the whole thing over the network.
You can't just run arbitrary code on the computer by plugging the phone in though, if you think about it that would be a massive security hole!

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.

Make a USB Device, Control It In Java

I'm thinking about making a physical controller (device?) with knobs, buttons, and LEDs. I'd like to interact with it using Java (respond to the knobs, light up LEDs, etc). The reason I mention Java is two-fold: first, I know Java well1. Second, I've written the rest of the program I need to interface with in Java (though there are ways to talk to the Java program from another language).
I would like the device to connect via USB and be (computer-)platform independent.
I haven't the slightest idea of where to start, except to start reading the Arduino website. Is this my best/only option? Is there something better suited for communicating with Java?
Note: I know that Arduino has something to do with Java (not sure what), but it seems like code must be written in a subset of C.
How would I get moving on this topic?
1 - No laughter, please.
The Arduino development environment is written in Java.
But the standard language you write a program for the Arduino platform is effectively C++.
The Arduino platform is based on an Atmel AVR chip. There is at least one Java VM for AVR chips. There are other languages available for the AVR such as Forth and BASIC (although I could only find commercial versions, so I'll if you want to find them, search for "AVR BASIC").
The Arduino uses a virtual COM port to communicate between the host computer and it. A virtual COM port emulates an old style serial line but is done with USB. You can use the Java communication API to then have a Java program running on the host computer communicate with your physical device.
For some encoders and buttons, you probably want to implement a USB HID device. If you're going to produce more than a couple of them, you'll want to do a custom board. Check out V-USB, an open-source library for making USB HID devices using Atmel microcontrollers. They have a bunch of examples of projects that use this library.
You could probably make this look like a HID joystick, using the encoders to produce X/Y axis information and having the buttons act like buttons. They you could use standard Java gaming APIs to read the joystick values.
Can you expand on your need for a custom device? It seems to me that designing hardware has a pretty high barrier to entry and that most applications I can think of would be better resolved by repurposing an existing piece of game controller hardware. If you really need new hardware, then i suggest you start by googling 'USB development kit' or
'USB development board' which will get you links like this, this and this.
As for working with USB hardware from Java, I've played around with the JUSB library a bit and it looks promising, but appears to be limited to Linux only because the Windows version of the native library half of the library hasn't been written. Alternatives can by found by googling 'HID java'.
Ok, computer-platform independant? What platforms are you targetting? That would depend on the driver and support for that said platform, what does the usb device do? Is it a mass storage device...You may have to look around and see if you can find a device driver that can talk to the device...
Hope this helps,
Best regards,
Tom.
I know for the serial port there were libraries that existed for interacting with it (rs232 library). Googling for java and USB returned several answers (the first was called jUSB). That would be the first type of thing I would be looking for.
sample for java usb connection to freescale microcontroller:
http://javausbapi.blogspot.com/

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