• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java API for hardware interaction

 
Ranch Hand
Posts: 32
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Do we have any java API to interact with hardware like c, c++ ?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JNI (or JNA, the Java wrapper for it) has already been available for quite a long time. With JNI you write native methods in Java, use javah to create headers for it, then implement the functions inside it with C or C++.
 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rite Rob,
But using JNI again we have to write the native code in some native language (like c, c++), but i am asking for some core Java API for such (hardware) things.


Muzza
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It all depends on the hardware involved. For some things there may already be an API (like hard disks), for other there may not be.
 
Ranch Hand
Posts: 32
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mozammil muzza wrote:Hi All,
Do we have any java API to interact with hardware like c, c++ ?



There's three things that come to mind:
1) Most hardware devices will come with a DLL/so/dylib. You can use the beforementioned JNA project to access them. Unless you absolutely require the last bit of performance (which would require you to use JNI), JNA is perfectly suitable for most applications and, as you requested, pure java.
2) Check out rxtx for working with serial/parallel ports. A lot of devices will emulate a serial port and can be accessed with this tool, too.
3) For directly accessing USB devices, take a look at libusbjava.

Other specialized hardware may actually require some C level code though.
reply
    Bookmark Topic Watch Topic
  • New Topic