• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Linux sysfs with Java  RSS feed

 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an industrial application which needs to be able to configure, set and get data with a GPIO device which as an interface exposed through sysfs.

The lines on the GPIO device are configured for input/output through a virtual file named /sys/devices/platform/.../direction, and the line values are read-from and written-to through a virtual file named /sys/devices/platform/.../value.

I am creating one instance of RandomAccessFile for each virtual file, and using that instance for both reading and writing.  Before each read, I am resetting the file-pointer back to zero using RandomAccessFile#seek(0) (writing appears to automatically set the file pointer back to zero).

There is a thread which periodically polls the GPIO input lines looking for changes to a multi-position toggle switch (which are reported back to a register listener in the main application), and also controls the cadencing of LEDs on the output lines.  The input lines can also be read on-demand from the main application thread.

I have synchronized the methods which read-from and write-to the virtual files since RandomAccessFile is not thread safe.

Everything appears to be working fine, but I'm wondering if there is anything that I haven't considered which might cause some grief later-on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!