28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
import time
|
|
from device.DeviceSerial import DeviceSerial
|
|
from device.LaminaAdapter import ParamMap_LaminaAdapter
|
|
|
|
|
|
def test_communication(device: DeviceSerial, time_out=2):
|
|
""" 通信成功率测试 """
|
|
time_start = time.time()
|
|
param_saved = device.flag_print, device.retry, device.time_out
|
|
device.flag_print = False
|
|
device.retry = 1
|
|
try:
|
|
while True:
|
|
device.frame_read(0x0C, 0x20)
|
|
print(f"Time Stamp: {time.ctime()}")
|
|
print(f"Success Frame: {device.log['read']}")
|
|
print(f"Failed Frame: {device.log['send'] - device.log['read']}")
|
|
print(f"Max Series Failed Frame: {device.log['keep-fail']}")
|
|
time.sleep(time_out)
|
|
finally:
|
|
time_end = time.time()
|
|
print("Test Result: ")
|
|
print(f"Time Start: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_start))}, \tTime End: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_end))}")
|
|
print(f"Time Elapsed: {time_end - time_start}")
|
|
print(f"Success Rate: {device.log['read'] / device.log['send'] * 100}%")
|
|
device.flag_print, device.retry, device.time_out = param_saved
|
|
|