-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialNumberTest.py
More file actions
138 lines (108 loc) · 3.39 KB
/
SerialNumberTest.py
File metadata and controls
138 lines (108 loc) · 3.39 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# test if barcode in correct production run and passed testing
# tell with how many boards found total and by user
import os
import sys
import traceback
import string
import subprocess
import psycopg2
from colorama import init
from termcolor import colored, cprint
import winsound
import pyttsx3
# terminal init for windows
init()
goodfrequency = 2500
goodduration = 1000
say = pyttsx3.init()
say.setProperty('rate', 250)
print ("Test serial for run")
directory = os.path.split(os.path.realpath(__file__))[0]
print ("Connecting to database...")
dbfile = open(directory+'/postgres_info.txt', 'r')
postgresInfo = dbfile.read()
dbfile.close()
try:
testStorage = psycopg2.connect(postgresInfo)
print ("Connect success.")
except:
print ("Could not connect!")
sys.exit(0)
state = "testing"
runId = '-1'
tstuser= '-1'
# get user name from terminal
while tstuser == '-1':
print ("\nEnter User ID : ")
tstuser = input()
if tstuser == 'exit':
sys.exit(0)
# get runId number from terminal
while runId == '-1':
print ("\nEnter Run ID : ")
runId = input()
if runId == 'exit':
sys.exit(0)
while (state == 'testing'):
#setup database
conn = psycopg2.connect(postgresInfo)
cur = conn.cursor()
#output run quantity
cur.execute("""SELECT COUNT(*) FROM tempserialtest WHERE runid = %s""",(runId,))
cnt = cur.fetchone()
countint = cnt[0]
count = str(countint)
print("Count " + count + " - Run: " + runId + " - User: " + tstuser)
# print("Count " + count)
tens = count[-2:]
if tens[-1:] == "0":
if tens == "00":
say.say(count)
else:
say.say(tens)
say.runAndWait()
conn.commit()
# get serial number from terminal
print ("\nEnter serial number : ")
serialNumber = input()
if serialNumber == 'exit':
sys.exit(0)
# get count of matching serial numbers from test database
cur.execute("""SELECT serial FROM testdata WHERE productionrunid = %s AND testresults LIKE 'Passed' AND serial = %s""",(runId,serialNumber))
rows = cur.fetchall()
runcount = len(rows)
# print results
if runcount > 0:
# check for found in already found boards
cur.execute("""SELECT time FROM tempserialtest WHERE serialnumber = %s""",(serialNumber,))
rows = cur.fetchall()
foundcount = len(rows)
if foundcount > 0:
# board already in added to this shipment
print (colored("Error! " + serialNumber + " Already Found and in shipment table!!!!",'white','on_yellow'))
winsound.Beep(500, 1500)
winsound.Beep(800, 1000)
for row in rows:
print(str(row[0]))
conn.commit()
cur.close()
else:
# write found board serial number to temp table
insertquery = """INSERT INTO tempserialtest (serialnumber, tstuser,runid) VALUES (%s, %s, %s)"""
cur.execute(insertquery,(serialNumber,tstuser,runId))
conn.commit()
cur.close()
print (colored("Found "+ serialNumber,'white','on_green'))
newcount = countint + 1
if str(newcount)[-1:] == "0":
winsound.Beep(3000, 800)
else:
winsound.Beep(2100, 800)
# No test results found
else:
print (colored("Not Found!!!! "+ serialNumber,'white','on_red'))
winsound.Beep(800, 1500)
winsound.Beep(500, 1000)
conn.commit()
cur.close()