aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2021-02-22 16:14:47 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2021-02-25 16:27:08 +0100
commit92bdd5e901a0e590b51af8a0e5807806c09effa6 (patch)
treeaafcd0fe5016451c2985b142c25d3b39b7e1621e
parentc8caec293333c7cfd93f29e9e7fa88f9cc78aa8b (diff)
serial: don't crash if the device does not exist
The most common reason for pySim to crash is when it is executed without commandline parameters. Then pySim will expect a serial reader on /dev/ttyUSB0 since this is the default. Lets check if /dev/ttyUSB0 even exists before trying to open it. Change-Id: I7545c728b531e9a796eee8f80f0b08d4097f8399
-rw-r--r--pySim/transport/serial.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index 61195e0..b841b3e 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -25,6 +25,7 @@ from __future__ import absolute_import
import serial
import time
+import os.path
from pySim.exceptions import NoCardError, ProtocolError
from pySim.transport import LinkBase
@@ -34,6 +35,8 @@ from pySim.utils import h2b, b2h
class SerialSimLink(LinkBase):
def __init__(self, device='/dev/ttyUSB0', baudrate=9600, rst='-rts', debug=False):
+ if not os.path.exists(device):
+ raise ValueError("device file %s does not exist -- abort" % device)
self._sl = serial.Serial(
port = device,
parity = serial.PARITY_EVEN,