Skip to content

Commit 23302cb

Browse files
committed
add basic class with uart xfer
1 parent 95f3171 commit 23302cb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

adafruit_rockblock.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,29 @@
4242
4343
"""
4444

45-
# imports
46-
4745
__version__ = "0.0.0-auto.0"
4846
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RockBlock.git"
47+
48+
class RockBlock:
49+
'''Driver for RockBLOCK Iridium satellite modem.'''
50+
51+
def __init__(self, uart, baudrate=19200):
52+
self._uart = uart
53+
self._uart.baudrate = baudrate
54+
55+
def _uart_xfer(self, cmd):
56+
'''Send AT command and return response.'''
57+
# response = ATCMD\r\nRESP\r\n\r\nOK\r\n
58+
# or = ATCMD\r\nERROR\r\n
59+
60+
cmd = str.encode('AT'+cmd)
61+
62+
self._uart.reset_input_buffer()
63+
self._uart.write(cmd+'\r')
64+
65+
resp = None
66+
if self._uart.readline().strip() == cmd:
67+
resp = self._uart.readline().strip().decode()
68+
69+
self._uart.reset_input_buffer()
70+
return resp

0 commit comments

Comments
 (0)