-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRead_Barcode.py
More file actions
62 lines (44 loc) · 1.33 KB
/
Copy pathRead_Barcode.py
File metadata and controls
62 lines (44 loc) · 1.33 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import re
from subprocess import Popen, PIPE
import time
def If_Barcode(output):
pattern = re.compile(r"(CODE-128)|(EAN-13)|(EAN-8)|(EAN-2)|(EAN-5)|(UPC-A)|(UPC-E)|(ISBN-10)|(ISBN-13):[0-9]+")
matches = re.match(pattern, output)
if matches:
return True
else:
return False
def excute_command(command):
system = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
system_info = system.communicate()
if system_info[0]:
stdout = system_info[0].strip('\n')
return stdout
if system_info[1]:
stderr = system_info[1]
return stderr
return False
def get_Barcode():
GetBarcode = "ssh pi@192.168.43.127 python barcodereader.py"
timeout = time.time() + 60*5 # 5 minutes from now
while True:
system = Popen(GetBarcode, shell=True, stdout=PIPE, stderr=PIPE)
system_info = system.communicate()
print(system_info[0])
print(system_info[1])
output = system_info[0].strip('\n')
if If_Barcode(output):
Barcode = output
return Barcode
break;
if time.time() > timeout:
print('Failed to read barcode for 5 minutes')
exit(1)
def Main():
output = excute_command("ssh pi@192.168.43.127 uname -a")
print(output)
Barcode = get_Barcode()
print(Barcode)
if __name__ == '__main__':
Main()