#! /usr/env/python #-------------------------------------------------------------------------------- """ Application: Misc_Constants for DAQ_96_Gui application Miscellaneous constants for the Graphical User Interface to the DAQ_96 Control Program """ #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- import string from StringIO import StringIO from Print_Utils import printLine import py_itc #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- # tcp ports presented by the DAQ96 control application tcp_port_for_gui = 52346 # reply timeout gui_reply_timeout_sec = 3 # the DAQ_96_TCC application is expected to acknowledge within 3 sec. #-------------------------------------------------------------------------------- debug_PrintXml = "Off" # "on" = trace XML messages sent and received # this can be changed from the "command file" dialog def IsXmlTracingOn ( ) : global debug_PrintXml return ( debug_PrintXml == "On" ) def SetXmlTracingOn ( ) : global debug_PrintXml debug_PrintXml = "On" printLine ( "XmlTrace", "XML Tracing now ON" ) def SetXmlTracingOff ( ) : global debug_PrintXml debug_PrintXml = "Off" printLine ( "XmlTrace", "XML Tracing now OFF" ) #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- class Itc_Gui_Client : def __init__ ( self, TccNode = 'localhost', PortNum = tcp_port_for_gui ) : printLine ( "GuiCient", "Opening Connection to <%s:%s>" % ( TccNode, PortNum ) ) # create ITC connection to DAQ_96 Control Application # for the simlated for GUI requests self.cmdId = 0 self.gui_client = py_itc.new_client ( PortNum, TccNode ) def quit(self): printLine ( "GuiCient", "Closing Conection" ) py_itc.del_client ( self.gui_client ) #-------------------------------------------------------------------------------- def sendGuiComand ( self, xmlCmdDoc, TimeOut_sec = gui_reply_timeout_sec ): xmlstring = StringIO () xmlCmdDoc.writexml( xmlstring ) self.cmdId = self.cmdId+1 command_str = "[Py_DAQ96_%4.4x] %s" % ( self.cmdId, xmlstring.getvalue() ) status = py_itc.send_message ( self.gui_client, command_str ) if IsXmlTracingOn ( ) : printLine ( "send_cmd", "status = %d" % status ) command_str = string.replace ( command_str, '\n', '' ) command_str = string.replace ( command_str, '<', '\n<' ) printLine ( "send_cmd", command_str ) status, reply = py_itc.get_reply ( self.gui_client, TimeOut_sec ) if IsXmlTracingOn ( ) : printLine ( "get_reply", "status = %d" % status ) reply = string.replace ( reply, '<', '\n<' ) printLine ( "get_reply", reply ) del ( xmlCmdDoc ) return reply #--------------------------------------------------------------------------------