tg39_service.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding:utf-8 -*-
  2. import os, sys, time
  3. from TST.CaptureCard import *
  4. from ssat_sdk.core.ibinder_listener import *
  5. from ssat_sdk.service.service_config import *
  6. from ssat_sdk.utils.serial_TG39BX1 import *
  7. from ssat_sdk.sat_environment import *
  8. from ssat_sdk.device_manage.Model_3116A import C3316A
  9. from ssat_sdk.utils import string_util
  10. class TG39Service():
  11. Service_Name = "tg39"
  12. # 当前选择的ATV码流仪;
  13. ATV_SELECTIVE = getATVSelected()
  14. def __init__(self):
  15. self.serviceConfig = ServiceConfig()
  16. self.status = 0
  17. def selectiveATV(self):
  18. port = getTG39_Port()
  19. if string_util.strcmp(TG39Service.ATV_SELECTIVE,'TG39'):
  20. self.tg39ser = Serial_TG39BX1(port)
  21. try:
  22. self.tg39ser.open()
  23. except Exception, e:
  24. print u"TG初始化失败", e
  25. self.status = 0
  26. return 0, e.message
  27. elif string_util.strcmp(TG39Service.ATV_SELECTIVE,'3116'):
  28. self.atv3116 = C3316A(port)
  29. if self.atv3116.Open() == False:
  30. print u"TG初始化失败", e
  31. self.status = 0
  32. return 0, '打开串口失败'
  33. return 1,'初始成功'
  34. def dealCommand(self, cmdLine):
  35. if string_util.strcmp(TG39Service.ATV_SELECTIVE,'TG39'):
  36. result = self.tg39ser.execmd(cmdLine)
  37. elif string_util.strcmp(TG39Service.ATV_SELECTIVE,'3116'):
  38. result = self.atv3116.sendCmds(cmdLine)
  39. # 返回结果;
  40. return result
  41. def initTG39(self):
  42. print u"初始化TG39设备"
  43. status,message = self.selectiveATV()
  44. if status == 0:
  45. return status,message
  46. ibinder = ListenerBinder(port=30100)
  47. self.listener, port = ibinder.createListener()
  48. self.serviceConfig.setTG39ListenerPort(port)
  49. print u"TG39启动成功,TG39 Port:", port
  50. self.status = 1
  51. while (True):
  52. try:
  53. conn = self.listener.accept()
  54. cmdLine = conn.recv()
  55. except Exception, e:
  56. print u"TG39接收指令失败", e
  57. continue
  58. print u"TG39接收指令:", cmdLine
  59. result = self.dealCommand(cmdLine)
  60. try:
  61. conn.send(result)
  62. except Exception, e:
  63. print e
  64. def getStatus(self):
  65. return self.status