-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest_basic_class.py
53 lines (42 loc) · 1.46 KB
/
test_basic_class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
import logging
from test_shared import *
COMPORT_NAME = "com22"
#logging levels
CONSOLE_LOGGER_LEVEL = logging.INFO
LOGGER_LEVEL = logging.INFO
SIM_MODULE_PIN = "1111"
def main():
"""
Tests basic functions of SIM 900 module. Connects and initializes session.
:return: true if everything was OK, otherwise returns false
"""
#adding & initializing port object
port = initializeUartPort(portName=COMPORT_NAME)
#initializing logger
(formatter, logger, consoleLogger,) = initializeLogs(LOGGER_LEVEL, CONSOLE_LOGGER_LEVEL)
#class for general functions
gsm = SimGsm(port, logger)
#opening COM port
logger.info("opening port")
if not gsm.openPort():
logger.error("error opening port: {0}".format(gsm.errorText))
return False
#initializing session with SIM900
logger.info("initializing SIM900 session")
if not gsm.begin(5):
logger.error("error initializing session: {0}".format(gsm.errorText))
return False
logger.debug("checking PIN state")
if gsm.pinState != SimGsmPinRequestState.NOPINNEEDED:
logger.debug("PIN needed, entering")
if gsm.pinState == SimGsmPinRequestState.SIM_PIN:
if not gsm.enterPin(SIM_MODULE_PIN):
logger.error("error entering PIN")
else:
logger.debug("PIN OK")
gsm.closePort()
return True
if __name__ == "__main__":
main()
print("DONE")