JavaFx project using JNI C driver

72 Views Asked by At

I need to develop a desktop application that uses a PCI-e driver to read/write data from a FPGA board. The drivers have already been installed and I can compile the sources of the executables used for I/O due to the fact that they are provided as a Visual Studio project.

The goal is to modify these drivers so that they can be used at the GUI level via an app, which I initially thought of developing in Java (I don't know if this is the best way); in this context the idea is to use JNI but all the guides I have found on generating the .h file from Java and the .dll file from the C file are about files that can be compiled individually from the command line, whereas I am stuck with two projects, one JavaFX and one Visual Studio project.

What might be a better solution than the one I hypothesized for developing such an application?

Thanks in advance

1

There are 1 best solutions below

0
jewelsea On

This is an opinion on an alternative that may or may not apply to your application.

An alternative to a native interface is to use a network interface (e.g. a socket connection or an HTTP rest server). That could be done by modifying the driver code to implement a socket or HTTP server that actions messages it receives.

Then a JavaFX Java client, using an HTTP client or socket client, could connect to the network interface supported by the driver to send requests to it. This would remove tight coupling between the native portions and the UI portions of the application.

I'd recommend using HTTP with REST as a protocol and JSON as a data exchange format (there are many tutorials on how to do that with a variety of technologies). Or WebSocket if you need bidirectional communication, but I would avoid bidirectional communication unless necessary because it is more complex.

Such a setup could also handle remote control of the driver if desired (similar to logging into a router UI to modify router settings, if you are familiar with that kind of process).

With a well-defined protocol, the client UI software is completely decoupled from the server. Therefore you have a choice of technology to use to develop the client UI, for instance, either a standalone JavaFX application or an angular web app usable from a browser would work.

The network interface provided by the driver could be independently tested via curl commands or postman.

The UI and driver projects can be developed independently using the most appropriate tools for the tasks (e.g. JavaFX UI built with SceneBuilder and a Java IDE such as Idea, and the native driver with network server built via Visual Studio). It is possible to develop JavaFX applications using Visual Studio Code if that is your preference.

The drawbacks of such a scheme are:

  1. Communications and processing overhead.
    • It may not be well-suited for exceptionally high data throughput, but if that is not required, then performance is not a concern.
  2. Security concerns for network connections.
    • An authentication scheme may be required.
  3. Technical knowledge required.
    • There are quite a few technologies involved here, so some degree of expertise and experience is required.
    • The project can be split between UI experts and low-level native code and driver experts if you have the luxury to do so.
  4. Network connections require network ports.
    • Ports and connections can be blocked by firewalls or require proxies to reach.
    • Ports can clash with ports from other apps (e.g. a pre-existing HTTP server on the machine).
    • So you need to work out a port management scheme (e.g. choose a port number or port allocation algorithm to use) and ensure the availability to connect to the required ports on your chosen platform.