forked from MakersTeam/Edison
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSBCheckStatus.py
More file actions
44 lines (33 loc) · 1.06 KB
/
USBCheckStatus.py
File metadata and controls
44 lines (33 loc) · 1.06 KB
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
#!/usr/bin/env python
"""
USBCheckStatus.py
This example shows how to check the USB OTG connection status.
This example code is in the public domain.
Revision History
----------------------------------------------------------
Author Date Description
----------------------------------------------------------
Diego Villalobos 02-17-2015 Example created
"""
# Library required
import os
# Connection status flag
status = False
# Runs the command 'dmesg' and save the output for USB OTG related messages
# in the file 'USB_Records.txt'
os.system('dmesg | grep "Notifying OTG driver" > USB_Record.txt')
# Opens the file created, read its content, and then erase it.
USB_Record_file = open('USB_Record.txt', "r")
content = USB_Record_file.readlines()
os.system('rm USB_Record.txt')
# Check the content line by line
for line in content:
if "Detected" in line:
status = True
elif "Removed" in line:
status = False
# Print an output message
if status:
print "The USB OTG cable is connected."
else:
print "The USB OTG cable is unconnected."