当前位置: 首页>>代码示例>>Python>>正文


Python Target.getSlave方法代码示例

本文整理汇总了Python中target.Target.getSlave方法的典型用法代码示例。如果您正苦于以下问题:Python Target.getSlave方法的具体用法?Python Target.getSlave怎么用?Python Target.getSlave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在target.Target的用法示例。


在下文中一共展示了Target.getSlave方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: server

# 需要导入模块: from target import Target [as 别名]
# 或者: from target.Target import getSlave [as 别名]
class RtaiServer:
    ## @var master
    # The master RTAI-XML server
    
    ## @var slave
    # The slave RTAI-XML server
    
    ## @var protocol
    # The protocol to use to connect to the server (http|https)
    
    ## @var address
    # The address of the server
    
    ## @var port
    # The port to use on the server
    
    ## @var target_name
    # The target name to connect to
    
    ## RtaiServer initializer. If the params are None, they're extracted from self.configurator
    # when the Target is created
    # @param target_name The target name to connect to (TODO: e' lo script name, non il targe name)
    # @param protocol The protocol to use to connect to the server (http|https)
    # @param address The address of the server
    # @param port The port to use on the server
    def __init__(self, target_name = None, protocol = None, address = None, port = None):
        self.master = None
        self.slave = None
        self.protocol = protocol
        self.address = address
        self.port = port
        self.target_name = target_name
    
    ## Creates the target
    # If the first connection, it connects to master, then to the slave.
    # If a slave_target param is passed, it connects to the specified target
    # @param target_name The target to connect to. Can be None to request a standard slave target
    # @param password The master password to catch a running server
    # @return The connected target. False if an error occurs (the error message is printed)
    def getTarget(self, target_name = None, password = None):
        # Override self.target_name if set
        if not target_name:
            target_name = self.target_name
            
        # TODO: Controllare anche che il master sia connesso. Se e' configurato ma non connesso si deve solo connettere. Il problema e' che non c'e' modo di sapere se effettivamente e' connesso
        if not self.master:
            print("Connecting to master")
            # The first parameter as False creates a Master target
            self.master = Target(False, self.protocol, self.address, self.port, target_name)
        
        # TODO: Serve lo stato del master per capire se e' gia' connesso (e quindi ci si riconnette) oppure se serve una nuova connessione
        if self.master.is_connected or self.master.connect(password):
            print("Connected to master")
        else:
            print("Error while connecting to master")
            return False
        
        print("Connecting to slave")

        self.slave = self.master.getSlave(target_name)
    
        if self.slave and (not self.slave.is_connected) and self.slave.connect():
            print("Connected to slave")
        else:
            print("Error while connecting to the slave target")
    
        return self.slave
        
    ## Stops everything
    def halt(self):
        self.slave.halt()
        #self.master.halt() # TODO: Va chiamato anche sul master?
开发者ID:tommyblue,项目名称:pyRTAI,代码行数:74,代码来源:rtai_server.py


注:本文中的target.Target.getSlave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。