Wild guess: the second time, the call to the
openPin
method fails because the pin is already open in exclusive mode (see the
documentation[
^]).
If that is the case then you should make such call just one time (possibly at your application startup).