1

I saw this question on SO:

Is there epoll equivalent in Java?

I conducted some research trying to figure out how to create something that watches for changes in a file descriptor using nio selectors and channels but I haven't made any progress. AsynchronousFileChannel does not implement SelectableChannel. I can't use a FileWatcher since the file descriptors I care about, GPIO pins, do not use inotify. What sort of channel do I need to create here and how?

Edit:

I'm aware of pi4j and Libbulldog, these use native modules to achieve gpio access. pi4j doesn't work with the BeagleBone and Libbulldog is a dead project. I was hoping for a pure Java answer. Why would epoll be implemented in SelectorProvider if not for this sort of thing?

Bjorn
  • 69,215
  • 39
  • 136
  • 164
  • Have you tried something like http://pi4j.com/example/control.html or https://docs.oracle.com/javame/config/cldc/opt-pkgs/api/daapi-3.3/com/oracle/deviceaccess/gpio/package-summary.html ? – Piotr Praszmo Dec 20 '15 at 22:28
  • XY problem. You don't need epoll(), you need a way to read GPIO pins. – user207421 Dec 20 '15 at 23:39
  • I can already read GPIO pins, but if I attach a sensor, like a light sensor for example, I need to get high speed updates as the sensor value changes. FileWatcher doesn't work, GPIO uses file descriptors but it's all in memory, they're not files. It's not about reading, it's about polling. The Linux kernel provides the epoll API for this. The non-java versions I've encountered for reading GPIO pins use epoll. I'm quite sure Java ME also uses epoll, but I can't use Java ME. It's not open source. – Bjorn Dec 20 '15 at 23:48
  • @Banthar pi4j uses [native modules](https://github.com/Pi4J/pi4j/tree/0fc50a992009779803a9ec02ea9d0a5f00f7f5e9/pi4j-native/src/main/native) to do this. I was hoping there was a pure Java answer. Why would SelectorProvider be using `epoll` if this wasn't possible? I'm using a BeagleBone so I can't use pi4j. – Bjorn Dec 21 '15 at 00:02
  • @Bjorn was any progress made here? I have a nearly identical problem, using pure java to read 4 different GPIO pins on the rising edge. Also using a beaglebone in this case. Was hoping to use a selector. Sorry to be 5 years late... – macmeyers50 Apr 22 '21 at 18:37

0 Answers0