12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import sys
- import os
- from os import path, access, R_OK
- import subprocess
- from subprocess import CalledProcessError
- import time
- from ssat_sdk.service.service_config import *
- from ssat_sdk.sat_environment import *
- class RedRatService():
-
- Service_Name = "redrat"
- HubCmd_exe = sys.prefix + r"/Tools/RedHatHub/RedRatHubCmd.exe"
- cmdline = ""
- child = None
- def __init__(self):
- self.status = 0
- self.serviceConfig = ServiceConfig()
- rcuDevice = getRCUDeviceSelected()
- if (rcuDevice.lower() == "redrat3"):
- RedRatService.HubCmd_exe = sys.prefix + r"/Tools/RedHatHub/RedRatHubCmd.exe"
- elif(rcuDevice.lower() == "redrat4"):
- RedRatService.HubCmd_exe = sys.prefix + r"/Tools/RedRatHub-V4.28/RedRatHubCmd.exe"
- if path.exists(RedRatService.HubCmd_exe) and path.isfile(RedRatService.HubCmd_exe) and access(
- RedRatService.HubCmd_exe, R_OK):
- print r"RedRatHubCmd.exe : exists and is readable"
- else:
- print r"RedRatHubCmd.exe : file is missing or is not readable, please check if Python27\Tools\RedRat\RedRatHubCmd.exe is exists"
-
- self.taskkill()
- print "RedRatHubCmd Start!"
- def taskkill(self):
-
- try:
- command = 'taskkill /F /IM RedRatHubCmd.exe'
- os.system(command)
- except Exception, e:
- print u"没有杀死RedRatHubCmd进程:", e
- def isRunning(self, signalxml, port, conns):
- if RedRatService.child is not None and RedRatService.child.poll() is None:
- return True
- else:
- return False
- def interrupt(self):
- if RedRatService.child is not None and RedRatService.child.poll() is None:
- RedRatService.child.kill()
- def getChild(self):
- return RedRatService.child
- def initRedRat(self):
- print u"初始化红老鼠设备"
- self.interrupt()
-
- signalxml = getRCUSelectedFilePath()
- port = self.serviceConfig.getRedRatHubPort()
- print 'port:', port
- if signalxml is None:
- print u"初始化红老鼠失败,默认信号文件未填"
- self.status = 0
- return 0, u"初始化红老鼠失败,默认信号文件未填"
- if path.exists(RedRatService.HubCmd_exe) and path.isfile(RedRatService.HubCmd_exe) and access(
- RedRatService.HubCmd_exe, R_OK):
-
- RedRatService.cmdline = '"' + RedRatService.HubCmd_exe + '" "' + signalxml + '" --port=' + str(port)
- print 'RedRatService.cmdline :', RedRatService.cmdline
- RedRatService.child = subprocess.Popen(RedRatService.cmdline, stdout=subprocess.PIPE)
- self.status = 1
- return 1, ''
-
-
-
-
-
-
-
-
- else:
- self.status = 0
- return 0, 'RedRatHubCmd.exe文件不存在'
- def help(self):
- output = subprocess.check_output(RedRatService.HubCmd_exe + " " + "-?")
- print "\n*******RedRatService CMD help**********" + output
- def getStatus(self):
- return self.status
|