19
19
20
20
21
21
class TC :
22
- def __init__ (self ):
23
- self .report = Report (ReportName )
22
+ def __init__ (self , file_path ):
23
+ self .report = Report (file_path , ReportName )
24
24
self .serail = SerialDriver ()
25
25
self .test_result = []
26
26
@@ -31,53 +31,20 @@ def write_csv(self):
31
31
"""
32
32
self .report .write_row (self .test_result )
33
33
34
- def init_report (self ):
35
- """
36
- init csv
37
- :return:
38
- """
39
-
40
- head1 = ["Test: Barcode Scan" , "Test: Get System Info" , "Test: Get System Info" , "Test: Get Board HW Revision" ,
41
- "Test: UI LED Test" , "Test: Front Button LED" , "Test: Seal Retracted Switch Test" ,
42
- "Test: Seal Retracted Switch Test" ,
43
- "Test: Plate Lift Test" , "Test: Lid Open Switch Test" , "Test: Lid Open Switch Test" ,
44
- "Test: Front Button Press" , "Test: Front Button Press" , "Test: Close Lid Extend Seal Switch Test" ,
45
- "Test: Close Lid Extend Seal Switch Test" ,
46
- "Test: Lid Thermistor Test" , "Test: Lid Thermistor Test" , "Test: Plate Thermistor Test" ,
47
- "Test: Plate Thermistor Test" ,
48
- "Test: Heatsink Fan Test" , "Test: Heatsink Fan Test" , "Test: Lid Heater Test" , "Test: Lid Heater Test" ,
49
- "Test: Cold Peltier Test" , "Test: Cold Peltier Test" , "Test: Hot Peltier Test" ,
50
- "Test: Hot Peltier Test" ]
51
-
52
- head2 = ["Unit Barcode Number" , "Unit Firmware Serial Number" , "Unit Firmware Revision" ,
53
- "Unit Board HW Revision" ,
54
- "RESULT" , "RESULT" , "M901.D Response" , "RESULT" , "RESULT" , "M901.D Response" , "RESULT" ,
55
- "M901.D Response" , "RESULT" , "M901.D Response" , "RESULT" , "Lid Thermistor M141 Response" , "RESULT" ,
56
- "Plate Thermistor M105.D Response" , "RESULT" , "Heatsink Fan M103.D Response" , "RESULT" ,
57
- "M141 Response" ,
58
- "RESULT" , "Cold Peltier Test M105.D Response" , "RESULT" , "Hot Peltier Test M105.D Response" , "RESULT"
59
- ]
60
- csv = ReportName + "-" + time .strftime ("%Y%m%d" ) + '.csv'
61
- if os .path .exists (csv ):
62
- pass
63
- else :
64
- self .report .write_row (head1 )
65
- self .report .write_row (head2 )
66
-
67
34
def init_serial (self ):
68
35
"""
69
36
init serial port connect
70
37
:return:
71
38
"""
72
39
self .serail .init ()
73
40
74
- def load_test_specification (self ):
41
+ def load_test_specification (self , test_config = None ):
75
42
"""
76
43
load test guide
77
44
:return:
78
45
"""
79
46
import json
80
- with open ("tc_test_specificaition .json" , "r" , encoding = 'utf-8' ) as f :
47
+ with open ("../../source/modules/tc_test_specification .json" , "r" , encoding = 'utf-8' ) as f :
81
48
dict_res = json .load (f )
82
49
f .close ()
83
50
return dict_res
@@ -365,13 +332,13 @@ def flash_sn(self):
365
332
else :
366
333
print ("PASS" )
367
334
368
- def test_unit (self ):
335
+ def test_unit (self , test_config ):
369
336
"""
370
337
v-for test unit and write csv
371
338
:return:
372
339
"""
373
340
self .repair_to_start ()
374
- specification_dict : dict = self .load_test_specification ()
341
+ specification_dict : dict = self .load_test_specification (test_config = test_config )
375
342
self .get_barcode_number ()
376
343
result = ""
377
344
for k , v in specification_dict .items ():
@@ -455,29 +422,99 @@ def test_unit(self):
455
422
self .lift_plate ()
456
423
457
424
self .serail .close ()
458
- self .write_csv ()
459
425
426
+ def get_plate_tem (self ):
427
+ responds = self .serail .write_and_get_buffer ("M105" , delay = 3 )
428
+ try :
429
+ idx = responds .index ('C:' )
430
+ temp = responds [idx + 2 :idx + 6 ]
431
+ temp = float (temp )
432
+ return temp
433
+ except Exception as e :
434
+ print (e )
460
435
461
- if __name__ == '__main__' :
436
+ def test_light_status (self , ):
437
+ """
438
+ pass
439
+ """
440
+
441
+ def get_tem_and_break (target_tem , time_out = 3 * 60 ):
442
+ """
443
+ 获得温度然后退出
444
+ """
445
+ for i in range (time_out ):
446
+ time .sleep (1 )
447
+ temp = self .get_plate_tem ()
448
+ if abs (temp - target_tem ) < 0.1 :
449
+ return True
450
+ return False
451
+
452
+ def show_responds ():
453
+ ret = self .serail .write_and_get_buffer ("M105" , delay = 3 )
454
+ print (f"Responds: { ret } " )
455
+
456
+ # 降温到4
457
+ print ("开始降温 -> 4C" )
458
+ self .serail .write_and_get_buffer ("M104 S4" , delay = 3 )
459
+ ret = get_tem_and_break (4 )
460
+ assert ret , 'set temperature timeout'
461
+
462
+ input ("Plate Temperature & Light 开始测试..." )
463
+ # 升温到23
464
+ self .serail .write_and_get_buffer ("M104 S23" , delay = 3 )
465
+ get_tem_and_break (23 )
466
+ show_responds ()
467
+ ret = input ('是否亮蓝色灯条(Y/N)?' )
468
+ if ret .strip ().upper () == 'Y' :
469
+ print ('TEST PASS' )
470
+ self .test_result .append ('Pass' )
471
+ else :
472
+ self .test_result .append ('Fail' )
473
+ # 升温到95
474
+ self .serail .write_and_get_buffer ("M104 S95" , delay = 3 )
475
+ get_tem_and_break (95 )
476
+ show_responds ()
477
+ ret = input ('是否亮红色灯条(Y/N)?' )
478
+ if ret .strip ().upper () == 'Y' :
479
+ print ('TEST PASS' )
480
+ self .test_result .append ('Pass' )
481
+ else :
482
+ print ('TEST FAIL' )
483
+ self .test_result .append ('Fail' )
484
+
485
+ self .serail .write_and_get_buffer ("M104 S23" , delay = 3 )
486
+ get_tem_and_break (23 )
487
+ print ("结束测试失能..." )
488
+ self .serail .write_and_get_buffer ("M18" , delay = 3 )
489
+
490
+
491
+ def run_tc (project_path ):
462
492
while True :
463
493
get_type = input ("=====================\n "
464
494
"TC Diagnostic Test\n \n "
465
495
"type 1 to start(输入1开始测试)\n "
466
496
"type 2 to lift plate(输入2取96孔板)\n "
467
497
"type 3 to flash serial number(输入3开始烧录条码)\n "
468
- "type 4 to get error message(输入4查看当前错误信息)\n " )
498
+ "type 4 to get error message(输入4查看当前错误信息)\n "
499
+ "type 5 to test plat temperature&light(输入5测试灯条颜色)\n " )
469
500
start_time = time .time ()
470
- tc = TC ()
501
+ data_path = os .path .join (project_path , 'testing_data' )
502
+ config = os .path .join (project_path , 'source' , 'modules' , 'tc_test_specification.json' )
503
+ tc = TC (data_path )
471
504
tc .init_serial ()
472
505
if str (get_type ) == "1" :
473
- tc .init_report ()
474
- tc .test_unit ()
506
+ tc .report .init_report ()
507
+ tc .test_unit (config )
508
+ tc .test_light_status ()
509
+ tc .write_csv ()
475
510
elif str (get_type ) == "2" :
476
511
tc .lift_plate ()
477
512
elif str (get_type ) == "3" :
478
513
tc .flash_sn ()
479
514
elif str (get_type ) == "4" :
480
515
tc .get_error_message ()
516
+ elif str (get_type ) == "5" :
517
+ tc .test_light_status ()
481
518
else :
482
519
pass
483
520
end_time = time .time ()
@@ -486,3 +523,7 @@ def test_unit(self):
486
523
get_input = input ("Test Complete, type 'q' to exit, others to continue...(测试结束, 输入‘q’退出,其它键继续...)" )
487
524
if get_input .strip ().lower () == 'q' :
488
525
break
526
+
527
+
528
+ if __name__ == '__main__' :
529
+ pass
0 commit comments