Detect current with USB and Java - 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.

Related

How to connect a PC with an RS323C interface?

I want to control a circulator (Thermo Haake DC30/DL30) which has got a RS232c interface. My first problem is that my computer has got only USB connections. Is it possible to use a RS323 to USB adapter and transmit commands and which libraries could you recommend me to use?
Also I don't know which language would be recommended. I am experienced in C# and Java. But I wanted to try out Python. I heard that it is less code to write and it would be a great opportunity to learn Python at the same time.
At the end I want a GUI in which I can set values like temperature, interval, read the current temperature or any fault messages.
I think what a USB to COM adapter does is create a virtual COM-Port on your PC, which you can then use like a regular one. Just make sure to get the right drivers, if you even need them.
I wrote a small app that required barcode scanners via RS232 in Python and I think I used PySerial, it is also definitely possible with C#, I tried that but gave up, since the application was no longer needed.

Reconnect USB device (ACR122U) without unplugging

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

Using DSLR Controller for a Secondary Display

I am trying to create a low latency method to use an android device as a secondary display for a PC. So far all I have found has been either wireless streaming, or a slow usb connection (i.e. using iDisplay).
However, I found a DSLR camera contoller app (https://play.google.com/store/apps/details?id=com.dslr.dashboard/) that is able to stream a live feed of the camera to an android display via USB. Would it be possible to edit the source code of this application so it can read the video output of PC via USB? If so, how would you go about this? Do you think that this would be a low latency alternative?
Thank you!
Lots of fantasy in your question. Have you ever seen a PC outputting data from one of its USB ports to another device? How are you supposed to do that? With a plain male-to-male USB cable, in case you find one? Sorry but things don't go that way. To transfer data (files, or a network) via USB between two computers you'd need some propietary/specific software. Of course, once you have acomplished that is technically possible to transfer files with the screen content. Buy you'd need to develop a software that would capture the computer screen, compress it in real time, and send it through USB with enough low latency to be usable. That's going to be resource intensive.
A better, easier approach would be, maybe, using some sort of remote desktop or VNC on the Android machine, with the computer acting as a server. At least far more feasible than trying to implement a similar protocol by yourself.
Sorry but what you are trying to achieve is flawed from the beginning.

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.

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/

Categories

Resources