Skip to content

Commit af8d2c3

Browse files
committed
Make sure device exists before opening
Without this check, the SPI interface would create the file if it did not already exist (assuming correct permissions) but the ensuing ioctl operations would fail.
1 parent a53218a commit af8d2c3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/spi/spi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import struct
2929
import fcntl
3030
import array
31+
import os.path
3132

3233

3334
def _ioc(direction, number, structure):
@@ -129,6 +130,10 @@ def __init__(self, device, speed=None, bits_per_word=None, phase=None,
129130
if isinstance(device, tuple):
130131
(bus, dev) = device
131132
device = "/dev/spidev{:d}.{:d}".format(bus, dev)
133+
134+
if not os.path.exists(device):
135+
raise IOError("{} does not exist".format(device))
136+
132137
self.handle = open(device, "w+")
133138

134139
if speed is not None:

0 commit comments

Comments
 (0)