aspose file tools*
The moose likes Java in General and the fly likes Building my own hardware/device Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Building my own hardware/device" Watch "Building my own hardware/device" New topic
Author

Building my own hardware/device

S Chan
Ranch Hand

Joined: Jul 25, 2011
Posts: 51
Hello all,

I had background in C/C++ for making my own PC-connecting device through the old and historic serial port, but that's many years ago when the serial/parallel port were used widely for connecting almost any external hardware to your pc.

Moving on to Java and USB... Frankly speaking, I have no idea and experience with communicating through USB with Java before. Can someone be kind to give me an idea or references for how I can make my own hardware/devices with the ability to control it through Java and USB?

Basically my device is just composed of many LEDs, sensors and motors... nothing high-tech. I just hope I can write a Java application with Swing interface and allows users to control how different component parts work through the interface.

Some of the things I am concerned of:
Do I need to write a driver in any other languages apart from C++? Is there any cross-platform/OS solution to this?
Do I need some hardware to multiplex/control data in between my motors and the USB port?
How does Java communicate with the USB port in low level in terms of bits and bytes?
Are there any open source existing libraries which can be helpful to this project of my own?
Is Java a bad language option for doing this kind of hardware communication work?

Other than suggestions and references, some explanations and samples will be helpful too.

Thank you all in advance for saving newbies like me.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10384
    
    8

JSR 80 pertains to Java+USB
Quick googling gave me this article

This topic is too difficult for "beginning java". Moving...


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 318
    
    2

At the Java level there is little difference between a serial port and a USB device.

Get the right library, select the device and they behave the same.


It's not what your program can do, it's what your users do with the program.
Cory Hartford
Ranch Hand

Joined: May 16, 2011
Posts: 82

I haven't had a lot of luck with JSR80 or JUSB; they seem to be OS dependent at least from the time I spent trying to make them work; and even in that experiment you had to have a certain Linux kernel and USB service to make them work properly. Not sure about windows; maybe there is something more stable.
In regard to RS232/serial, I posted this last week. Hopefully you will find something useful.

I use serial devices all the time because the industry I work in still uses the protocol as standard. As i said above, I've dipped my foot into USB and it was akin to hitting myself in the head with a hammer for 3 or 4 days with no results. I have read other languages like Python (C++?) are better at dealing with USB; ie they have built in/approved APIs that allow you to spend your time developing rather than trying to get the API itself working.

My frank opinion :
You are familiar with how RS232 works from your previous work. The Java SE Socket classes are rock solid and all kinds of examples exists to help you when you get stuck. Drop the 99 bucks for a serial to Ethernet server I linked in the post and assign it an IP. Once you do that Java will communicate using a Socket (which its really good at) and your device will communicate via Serial (Rs232, 484 whatever; just make sure you get the correct serial server) which it sounds like your past devices are good at.
In this model, everyone is good at everything, and most importantly your application and device will be portable. Any OS that has a JVM and can communicate via TCP/IP will run your stuff like a champ.

Thats another big drawback from what I have seen (aside from the overhead of getting the API working in the first place). Assuming you get the API working correctly on your chosen OS, USB or a COM library puts you in a position where you absolutely have to use the OS that you used to develop the application on. As an example, I develop in Linux and most of my deployments are on a Windows flavor; I shudder to think of having to try and get everyone to play nice together when deploying using USB or a COM library.

Not saying it can't be done; I am sure if one was persistent enough, USB or a COM library would work in both environments. Whatever path you choose, I wish you luck. It sounds like a fun project!


‎"The greatest of all weaknesses is the fear of appearing weak." - JB Bossuet
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 318
    
    2

I haven't done much but working with USB GPS devices was not as painful as Cory's experience. He may very well have better insight than I do.

All device management is somewhat OS dependent. The library I used had the Linux and Windows native drivers I needed. I can look up which one I used but I can't really recommended it beyond it was the first one I found that worked for me. I did not have any OS issues.

You will certainly need to test and debug the device control part of your application on each OS you plan to deploy but I think you'll still see a good amount of OS independence in the whole application.

S Chan
Ranch Hand

Joined: Jul 25, 2011
Posts: 51
Thank you all for all good advices. They are useful to me.

The OS dependent issue surely is something not so straight forward. I will need to carry out more trail-and-errors tests for that.

Doing it in another language may be quite painful for me, because frankly speaking, I don't know Python and I think I have lost my touch with C/C++ after so many years. I have got used to Java these few years so I thought if it is possible in Java, I would use Java entirely.

Suddenly I feel that I am so new in this USB field and I have a lot to read on.

Thanks, everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Building my own hardware/device