123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # -*- coding:utf-8 -*-
- import os, sys, time
- from TST.CaptureCard import *
- from ssat_sdk.core.ibinder_listener import *
- from ssat_sdk.service.service_config import *
- from ssat_sdk.utils.serial_TG39BX1 import *
- from ssat_sdk.sat_environment import *
- from ssat_sdk.device_manage.Model_3116A import C3316A
- from ssat_sdk.utils import string_util
- class TG39Service():
- Service_Name = "tg39"
- # 当前选择的ATV码流仪;
- ATV_SELECTIVE = getATVSelected()
- def __init__(self):
- self.serviceConfig = ServiceConfig()
- self.status = 0
- def selectiveATV(self):
- port = getTG39_Port()
- if string_util.strcmp(TG39Service.ATV_SELECTIVE,'TG39'):
- self.tg39ser = Serial_TG39BX1(port)
- try:
- self.tg39ser.open()
- except Exception, e:
- print u"TG初始化失败", e
- self.status = 0
- return 0, e.message
- elif string_util.strcmp(TG39Service.ATV_SELECTIVE,'3116'):
- self.atv3116 = C3316A(port)
- if self.atv3116.Open() == False:
- print u"TG初始化失败", e
- self.status = 0
- return 0, '打开串口失败'
-
- return 1,'初始成功'
-
- def dealCommand(self, cmdLine):
- if string_util.strcmp(TG39Service.ATV_SELECTIVE,'TG39'):
- result = self.tg39ser.execmd(cmdLine)
- elif string_util.strcmp(TG39Service.ATV_SELECTIVE,'3116'):
- result = self.atv3116.sendCmds(cmdLine)
- # 返回结果;
- return result
- def initTG39(self):
- print u"初始化TG39设备"
- status,message = self.selectiveATV()
- if status == 0:
- return status,message
- ibinder = ListenerBinder(port=30100)
- self.listener, port = ibinder.createListener()
- self.serviceConfig.setTG39ListenerPort(port)
- print u"TG39启动成功,TG39 Port:", port
- self.status = 1
- while (True):
- try:
- conn = self.listener.accept()
- cmdLine = conn.recv()
- except Exception, e:
- print u"TG39接收指令失败", e
- continue
- print u"TG39接收指令:", cmdLine
- result = self.dealCommand(cmdLine)
- try:
- conn.send(result)
- except Exception, e:
- print e
-
- def getStatus(self):
- return self.status
|