-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_modem.py
55 lines (49 loc) · 1.2 KB
/
find_modem.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
54
55
import os
import serial
import commands
import time
devs = []
ret = []
def iden_port():
raw=commands.getoutput("dmesg | grep 'GSM modem (1-port) converter now attached to'")
mod=raw.splitlines()
if (len(mod) == 0):
commands.getoutput('sudo usb_modeswitch -I -W -c /etc/usb_modeswitch.d/12d1\:1505')
time.sleep(10)
raw=commands.getoutput("dmesg | grep 'GSM modem (1-port) converter now attached to'")
mod=raw.splitlines()
mod_port=mod[-3:]
for i in range(len(mod_port)):
devs.append(mod_port[i][-7:])
else:
mod_port=mod[-3:]
for i in range(len(mod_port)):
devs.append(mod_port[i][-7:])
def main():
def sendCommand(com):
ser.write(com+"\r\n")
time.sleep(2)
while ser.inWaiting() > 0:
msg = ser.readline().strip()
msg = msg.replace("\r","")
msg = msg.replace("\n","")
if msg!="":
ret.append(msg)
print devs
iden_port()
print devs
time.sleep(15)
for i in range(len(devs)):
print devs[i]
ser=serial.Serial('/dev/%s'%devs[i], baudrate=115200, timeout=.1, rtscts=0)
sendCommand("ATi")
#print ret
print ret[0]
if ret[0] == "Manufacturer: +GMI: HUAWEI TECHNOLOGIES CO., LTD":
print ":)"
break
else:
print "ddd"
pass
if __name__ == "__main__":
main()