12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- # -*- coding:utf-8 -*-
- import os, sys, time
- import thread
- '''
- 工程师调试的串口客户端
- '''
- from ssat_sdk.utils.serialboard_manager import TCLSerial
- class DebugSerial():
- def __init__(self):
- self.serialTool = TCLSerial()
- self.showLogTag = True
- def __del__(self):
- self.serialTool.close()
- '''
- 在电视端执行串口命令
- :param command:指令
- :return 无
- '''
- def excuteCmd(self, command):
- self.serialTool.sendCommand(command)
- # ret = self.serialTool.readData(1024)
- # print "excuteCmd, return:",ret
- def excuteCmdlog(self, command):
- self.serialTool.sendCommand(command)
- ret = self.serialTool.readData(1024)
- print "excuteCmd, return:",ret
- return ret
- '''
- 另起一个线程,在终端显示日志。
- '''
- def showLogThread(self):
- thread.start_new_thread(self.showLog,())
- def showLog(self):
- self.showLogTag = True
- while self.showLogTag is True:
- ret = self.serialTool.readLine()
- if ret.__len__() > 0:
- print ret
- '''
- 关闭日志,无论终端显示,或者保存到文件
- '''
- def closeLog(self):
- self.showLogTag = False
- '''
- 另起一个线程,保存日志到指定文件
- :param filePath: 日志文件路径
- '''
- def saveLogToFileThread(self, filePath):
- thread.start_new_thread(self.saveLogToFile,(filePath,))
- def saveLogToFile(self, filePath):
- with open(filePath, "w") as logFile:
- while self.showLogTag is True:
- retLine = self.serialTool.readLine()
- logFile.write(retLine)
- logFile.flush()
- logFile.close()
- if __name__ == "__main__":
- serial = DebugSerial()
- serial.showLogThread()
|