- pin_path = os.path.join(channel_path, self._pin_path.format(self._pwmpin))
- if not os.path.isdir(pin_path):
+ try:
+ with open(
+ os.path.join(channel_path, self._unexport_path), "w"
+ ) as f_unexport:
+ f_unexport.write("%d\n" % self._pwmpin)
+ except IOError as e:
+ pass # not unusual, it doesnt already exist
+ try:
+ with open(os.path.join(channel_path, self._export_path), "w") as f_export:
+ f_export.write("%d\n" % self._pwmpin)
+ except IOError as e:
+ raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError
+
+ # Loop until 'period' is writable, because application of udev rules
+ # after the above pin export is asynchronous.
+ # Without this loop, the following properties may not be writable yet.
+ for i in range(PWMOut.PWM_STAT_RETRIES):