Using Java together with C

11

I'm working on a micro controller project. My source is all in C though I would like to interact with that program using Java. Is this possible? For example: The C program executes microcontroller control commands and through a graphical interface in Java I would like to send commands to the program in C.

    
asked by anonymous 15.01.2015 / 13:52

2 answers

11

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

Even if you wanted Java code to communicate as C code in the same program it would still be possible through JNI . If communication is very difficult to integrate C code into Java it can be an alternative. But I already notice that it is not the easiest task.

Need to analyze whether the controller has some form of processes communicating efficiently. Eventually, in extreme cases it is necessary to use some C code next to 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).

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

In addition, you can use file sharing if the controller uses some form of storage.

You would need to look at the documentation for the driver and / or operating system that runs on it, as well as check the libraries available to it in both languages. But if none of this is possible, it's best to give up doing this on the controller.

    
15.01.2015 / 14:04
2

It is possible, yes, make sure your microcontroller allows serial communication (USART) and simply implements communication using Java.

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

This is just one way to communicate between embedded systems and other devices such as a PC. However, easy to implement and widely used on the market.

    
04.05.2015 / 18:48