Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout value on reader thread wait in SMS send example #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/sms_handler_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
modem.connect(PIN)
print('Waiting for SMS message...')
try:
modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
modem.rxThread.join() # Main thread essentially blocks indefinitely, but still receives CTRL+C interrupt signal
finally:
modem.close()

Expand Down
4 changes: 2 additions & 2 deletions gsmmodem/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class GsmModem(SerialComms):
CDSI_REGEX = re.compile('\+CDSI:\s*"([^"]+)",(\d+)$')
CDS_REGEX = re.compile('\+CDS:\s*([0-9]+)"$')

def __init__(self, port, baudrate=115200, incomingCallCallbackFunc=None, smsReceivedCallbackFunc=None, smsStatusReportCallback=None, requestDelivery=True, AT_CNMI="", *a, **kw):
super(GsmModem, self).__init__(port, baudrate, notifyCallbackFunc=self._handleModemNotification, *a, **kw)
def __init__(self, port, baudrate=115200, rtscts=True, dsrdtr=True, incomingCallCallbackFunc=None, smsReceivedCallbackFunc=None, smsStatusReportCallback=None, requestDelivery=True, AT_CNMI="", *a, **kw):
super(GsmModem, self).__init__(port, baudrate, rtscts, dsrdtr, notifyCallbackFunc=self._handleModemNotification, *a, **kw)
self.incomingCallCallback = incomingCallCallbackFunc or self._placeholderCallback
self.smsReceivedCallback = smsReceivedCallbackFunc or self._placeholderCallback
self.smsStatusReportCallback = smsStatusReportCallback or self._placeholderCallback
Expand Down
6 changes: 4 additions & 2 deletions gsmmodem/serial_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SerialComms(object):
# Default timeout for serial port reads (in seconds)
timeout = 1

def __init__(self, port, baudrate=115200, notifyCallbackFunc=None, fatalErrorCallbackFunc=None, *args, **kwargs):
def __init__(self, port, baudrate=115200, rtscts=True, dsrdtr=True, notifyCallbackFunc=None, fatalErrorCallbackFunc=None, *args, **kwargs):
""" Constructor

:param fatalErrorCallbackFunc: function to call if a fatal error occurs in the serial device reading thread
Expand All @@ -31,6 +31,8 @@ def __init__(self, port, baudrate=115200, notifyCallbackFunc=None, fatalErrorCal
self.alive = False
self.port = port
self.baudrate = baudrate
self.dsrdtr = dsrdtr
self.rtscts = rtscts

self._responseEvent = None # threading.Event()
self._expectResponseTermSeq = None # expected response terminator sequence
Expand All @@ -47,7 +49,7 @@ def __init__(self, port, baudrate=115200, notifyCallbackFunc=None, fatalErrorCal

def connect(self):
""" Connects to the device and starts the read thread """
self.serial = serial.Serial(dsrdtr=True, rtscts=True, port=self.port, baudrate=self.baudrate,
self.serial = serial.Serial(rtscts=self.rtscts, dsrdtr=self.dsrdtr, port=self.port, baudrate=self.baudrate,
timeout=self.timeout,*self.com_args,**self.com_kwargs)
# Start read thread
self.alive = True
Expand Down