Using Java together with C

Asked

Viewed 1,232 times

11

I am working on a micro controller project. My source is all in C however I would like to interact with this program using Java. Would that be possible? For example: The C program executes microcontroller control commands and by a graphical Java interface would like to send commands to the C program.

2 answers

11


If you just want to communicate between two programs, there is no great difficulty if the device provides resources for that. Programs communicate all the time and no matter what languages they are in.

Even if you wanted code in Java to communicate as C code in the same program it would still be possible through JNI. If communication is too difficult to integrate C code into Java it may be an alternative. But I warn you, it is not the easiest task.

I would need to analyze whether the controller has any form of processes communicating efficiently. Eventually, in extreme cases it is necessary to use some C code together with Java to create this form of communication probably accessing memory in a shared way (there are several implications in this if the operating system does not help).

I could also use the TCP protocol to do the communication as long as both are able to do this communication. This depends on appropriate libraries in the two programs or specialized code.

In addition it is possible to use information exchange for files if the controller uses some form of storage.

It would have to analyze the documentation of the controller and/or operating system that runs on it in addition to checking the libraries available to it in both languages. But if none of this is possible, you’d better give up doing this on the controller.

  • Vlw bigown. I will give a search in JNI suddenly can help me.

2

Yes, make sure your microcontroller allows serial communication (USART) and simply deploy the communication using Java.

There is a very good class that can assist you in this process called RXTX.

This is just one of the ways to communicate between embedded systems and other devices such as a PC, for example. However, easy to implement and wide use in the market.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.