Make a USB Device, Control It In Java - 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/

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.

How to communicate with a device?

I am a web programmer and I am just wondering how software and hardware can communicate. I have basic knowledge in Java but I am not an expert.
Let's make it simple. I have a device which is just a simple lamp that can get switched on and off and it is connected via USB. My software has only one function - pressing enter.
By pressing enter I want the software to communicate with the USB port and tell it to activate the device. How would that be possible? Where do I have to start and what do I need to learn?
I understand that my question and my example sound silly but I am just trying to understand how it works.
I appreciate any help!
I think that if you using arduino or other prototyping board you might use rxtx serial library.
If I answer simply, then I should tell, you need to have microcontroller to do this by your own.
A microcontroller is a small computer on a single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals. So, there are input, output pins for different operations you want to do with your physical hardware and also a memory to store the commands or program. That means a microcontroller is a third party which keeps communication active between the hardware and software in this case.
In the market, you can find many microcontroller integrated boards for building digital devices and interactive objects that can sense and control objects in the physical world.
To make your work easy as a beginner, I suggest you to buy an arduino board from the market. If you google it and search for arduino tutorials in youtube, you will find how they work. Hope these help you.

How to connect java with plc data

I have a new project about plc (siemens), but I dont know how they work.
What I have to do, is by given some data from the plc I have to handle the data and to display it on a simple GUI.
The PLC (I dont know if there are different types) that I have to use is a "proximity sensor" which only capture if something is infront of it, then it hasto send some data to my program in Java and then I have to display it on the GUI (Basically some red or green circles)
I dont have to handle the behavior of the PLC, I just have to do display a red or green circle by given the data from the PLC
Questions:
I thought of Java because I know that is a powerful language, but is it the best for what I have to do?
Second if Java is the best choice, are there any librarys for working with PLC?
Third... I started to read something about some languages like:
Functional Block Diagram (FBD)
What are they for?
"The PLC(...) that I have to use is a "proximity sensor" which only capture something in front of it."
Do you mean to state here that you are connecting a proximity sensor to a PLC, reading the data from the PLC and back to your UI program OR do you want to read the proximity sensor directly back to your UI program?
If it’s the latter connect your sensor to a microcontroller and then send the data serially to your computer.
If you are using a PLC you will need some interface card (i.e. digital or analogue). Connect your sensor to the applicable card. If you want to read an S7 PLC you will need a library - libnodave is a good one.
If you are using a library like libnodave you will need to use ones of its supported languages - it includes Java but you can also use others e.g. C. You could also use Snap7.
FBD is one of the IEC61131-3 programming languages - see:
http://www.automation.com/pdf_articles/IEC_Programming_Thayer_L.pdf
The PLC should have an RS232/485 interface. All communications happen via serial communications. Java does have the Java Communications API, But before you go down that path, What is the computer that would be interfacing with the PLC device - A low power ARM SBC or a x86 PC ? The downsides of using Java is the footprint related to the JDK. If it were me, I'd stick to C/ Rust or GoLang based on the constraints of the platform.
To communicate with a Siemens plc you could use a few different options based on the exact type of PLC that you use.
A few communication protocols supported by Siemens:
opc: the industry standard for communication between PLC and other devices
libary like Snap7 http://snap7.sourceforge.net/ which has lots of supported programming languages
for the programming language you can use Java but as alternative you could use C# or vb.net in cooperation with Visual Studio for creating a simple GUI.
If you need any further information please let me know.
i had similar problem and this is how i sorted it out:
Communication protocol that most PLCs are using are either modbus, bacnet, lonworks and milion others. In your case , i assume that Siemens uses modbus.
Firstly you neet the Rs485 to usb adapter (arround 20Eur on Amazon)
you have to read registers from modbus - please use easyModbus api
This approach works fine but it is not happening in the real time as the modbus communication could run in separate threads.
This depends on the application that you want to design, if the application is based on the web, it is better to use a easymodbus TCP that sends data through TCP connection, and if you want a desktop application, it is better to use Easy Modbus RTU that Using RS485, this library it's the best.
http://easymodbustcp.net/en/
I Recommended to use this library it's also for future (Smart Phone, Desktop and Web Application using Spring Boot MVC).

Porting Android code to BlackBerry naitivly

I am trying to port an Android application to BlackBerry 10 and make it look naitive. I have written all the QML for the app but I cannot seem to get the code to work. Do I need to translate the Java into C++ and if I do, do I have to do it manually or would an automatic one do?
Also my application has many different classes which I am not sure how to integrate with the BlackBerry layout.
I am trying to port the open source messenger Telegram, if that's any use. http://telegram.org/source/
Assuming you want to do a proper port and know C++ and Java, a full rewrite would be best. You can probably copy a lot of code from the Java source, but there's no way an automated converter or direct copy would ever work in C++.
Most of the processes in BlackBerry are the same as in Android, all you'd really need to do is rewrite all the UI code and handlers to fit the BlackBerry Native SDK

Send commands between two computers over the internet

I wish to control my computer (and usb devices attached to the computer) at home with any computer that is connected to the internet. The computer at home must have a program installed that receives commands from any other computer that is connected to the internet. I thought it would be best if I do this with a web interface as it would not be necessary to install software on that computer. For obvious reasons it would require log in details.
Extra details: The main part of the project is actually a device that I will develop that connects to the computer's usb port. Sorry if it was a bit vague in my original question. This device will perform simple functions such as turning lights on etc. At first I will just attempt to switch the lights remotely using the internet. Later on I will add commands that can control certain aspects of the computer such as the music player. I think doing a full remote desktop connection to control my device is therefore not quite necessary. Does anybody know of any open source projects that can perform these functions?
So basically the problem is sending encrypted commands from a web interface to my computer at home. What would be the best method to achieve this and what programming languages should I use? I know Java, Python and C quite well, but have very little experience with web applications, such as Javascript and PHP.
I have looked at web chat examples as it is sort of similar concept to what I wish to achieve, except the text can be replaced with commands. Is this a viable solution or are there better alternatives?
Thank you
VNC
SSH
Remote Desktop (Windows)
You can write a WEB APPLICATION. The encryption part is solved by simple HTTPS usage. On the server side (your home computer with USB devices attached to it) you should use Python (since you're quite experienced with it) and a Python Web Framework you want (I.E. Django).
While it is an interesting programming question, perhaps you should ask it on ServerFault instead? There you can probably get a lot of nice input on web-based administration / control tools.
Unless this is a "for fun" project for you, there are about a jillion things out there that already do this. And if you want to control a computer from a web browser, be prepared to require installing some kind of custom plugin - since browsers can't touch arbitrary files on the local filesystem, execute local applications, or do other things that are flagrant security risks.
I've been using VNC for over a decade - free and easy.
http://en.wikipedia.org/wiki/Virtual_Network_Computing
Well, I think that java can work well, in fact you have to deal with system calls to manage usb devices and things like that (and as far as I know, PHP is not the best language to do this). Also shouldn't be so hard to create a basic server/client program, just use good encryption mechanism to not show commands around web.
I you are looking for solution you could use from any computer anywhere in the worls without the need to install any software on client pc, try logmein.com (http://secure.logmein.com).
It is free, reliable, works in any modern browser, you don't have to remmeber IPs and hope they won't change, ...
Or if this is a "for fun project" why not write a php script, open port 80 in your router so you can access you script from outside, possibly dynamically link some domain to your IP (http://www.dyndns.com/). In the script you would just login and then for example type the orders in textfield in some form in your script. Lets just say you want to do some command prompt stuf, so you will basically remotely construst a *.bat file for example. Then the script stores this a fromtheinternets.bat to a folder on your desktop that is being constantly monitored for changes. And when such a change is found you just activate the bat file.
Insecure? Yes (It could be made secureER)
Fun to write? Definitely
PS: I am new here, hope it's not "illegal" to post link to actual services, instead of wiki lists. This is by no means and advertisement, I am just a happy user. :)

Categories

Resources