Skip to content

Commit a88377c

Browse files
JPEWdevEmantor
authored andcommitted
agents: sysfsgpio: Fix remote GPIO export
Fixes the exception ValueError("can't have unbuffered text I/O") when opening the export sysfs file to export a GPIO using the remote agent. The file should be open in binary mode and the export string encoded to match. Signed-off-by: Joshua Watt <[email protected]>
1 parent a84680b commit a88377c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

labgrid/util/agents/sysfsgpio.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99

1010
class GpioDigitalOutput:
1111
_gpio_sysfs_path_prefix = '/sys/class/gpio'
12-
_buffered_file_access = False
1312

1413
@staticmethod
1514
def _assert_gpio_line_is_exported(index):
1615
gpio_sysfs_path = os.path.join(GpioDigitalOutput._gpio_sysfs_path_prefix,
1716
'gpio{0}'.format(index))
1817
if not os.path.exists(gpio_sysfs_path):
1918
export_sysfs_path = os.path.join(GpioDigitalOutput._gpio_sysfs_path_prefix, 'export')
20-
with open(export_sysfs_path, mode='r+',
21-
buffering=GpioDigitalOutput._buffered_file_access) as export:
22-
export.write(str(index))
19+
with open(export_sysfs_path, mode='wb') as export:
20+
export.write(str(index).encode('utf-8'))
2321
if not os.path.exists(gpio_sysfs_path):
2422
raise ValueError("Device not found")
2523

0 commit comments

Comments
 (0)