Sun Feb 08, 2015 10:03 pm
notro wrote:FTrevorGowen wrote:
1) Is it O.K. to re-request a pin to be exported that hasn't been unexported previously (as opposed to one that's never been exported)?
2) If not, is there a "robust" or "preferred" way of testing whether a pin has previously been exported (and still is)?
Re-requesting returns an error, because the pin is in use.
Check for the /sys/class/gpio/gpioNN directory to see if the pin has been exported to userspace.
Code: Select all
$ sudo -i
# cd /sys/class/gpio/
# echo 4 > export
# ls -l gpio4
lrwxrwxrwx 1 root gpio 0 Feb 8 20:14 gpio4 -> ../../devices/soc/3f200000.gpio/gpio/gpio4
# echo 4 > export
bash: echo: write error: Device or resource busy
#
# echo 4 > unexport
# ls -l gpio4
ls: cannot access gpio4: No such file or directory
#
Hmmm... I had a "nasty suspicion" that it'd be something like that. I'll have to check exactly how gordon (drogon) does the export etc. in his wiringPi 'C' library, since, in practice, I currently perform a 'C' system call to his
gpio program from that.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm