Exemplo n.º 1
0
    def ReadAction(self, oAction: cAction) -> None:
        """
        Adds and defaults some common attributes to the action

        :param cAction oAction: Reads an action from the action pars
        """

        oAction.uType = oAction.dActionPars.get(u'type', u'send')
        oAction.uCmd = oAction.dActionPars.get(u'cmd',
                                               u'No cmd action defined')
        oAction.uLocalDestVar = oAction.dActionPars.get(
            u'ldestvar', u'RESULT_' + oAction.uActionName)
        oAction.uGlobalDestVar = oAction.dActionPars.get(
            u'gdestvar', u'RESULT_' + oAction.uActionName)
        oAction.uGetVar = oAction.dActionPars.get(u'getvar', u'')
        oAction.bWaitForResponse = ToBool(
            oAction.dActionPars.get(u'waitforresponse', u'0'))
        oAction.uParseResultOption = oAction.dActionPars.get(
            u'parseoption', self.aIniSettings.uParseResultOption)
        oAction.uParseResultTokenizeString = oAction.dActionPars.get(
            u'parsetoken', self.aIniSettings.uParseResultTokenizeString)
        oAction.uParseResultFlags = oAction.dActionPars.get(
            u'parseflags', self.aIniSettings.uParseResultFlags)
        oAction.uResultEndString = oAction.dActionPars.get(
            u'parseendstring', self.aIniSettings.uResultEndString)

        oAction.dActionPars['interface'] = self.oInterFace.uObjectName
        oAction.dActionPars['configname'] = self.uConfigName

        if oAction.dActionPars.get('varcontext', '') == "codeset":
            oAction.dActionPars["varcontext"] = self.uContext
Exemplo n.º 2
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)
        eRet: eReturnCode = eReturnCode.Error

        if oAction.uCCF_Code:
            # noinspection PyUnresolvedReferences
            oAction.uCmd = CCF2ITach(oAction.uCCF_Code,
                                     ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd: str = ReplaceVars(oAction.uCmd,
                                self.uObjectName + u'/' + oSetting.uConfigName)
        uCmd = ReplaceVars(uCmd)
        self.ShowInfo(uMsg=u'Sending Command: ' + uCmd + u' to ' +
                      oSetting.aIniSettings.uHost + ':' +
                      oSetting.aIniSettings.uPort)

        oSetting.Connect()
        if oSetting.bIsConnected:
            uMsg: str = uCmd + u'\r\n'
            try:
                oSetting.oSocket.sendall(ToBytes(uMsg))
                byResponse = oSetting.oSocket.recv(self.iBufferSize)
                self.ShowDebug(uMsg=u'Response' + ToUnicode(byResponse),
                               uParConfigName=oSetting.uConfigName)
                if 'completeir' in ToUnicode(byResponse):
                    eRet = eReturnCode.Success
                else:
                    eRet = eReturnCode.Error
            except Exception as e:
                self.ShowError(uMsg=u'can\'t Send Message',
                               uParConfigName=u'',
                               oException=e)
                eRet = eReturnCode.Error

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Exemplo n.º 3
0
    def SendCommand(self,oAction:cAction,oSetting:cInterFaceSettings,uRetVar:str,bNoLogOut:bool=False) -> eReturnCode:
        super().SendCommand(oAction=oAction,oSetting=oSetting,uRetVar=uRetVar,bNoLogOut=bNoLogOut)

        eRet:eReturnCode = eReturnCode.Error

        if oAction.uCCF_Code != u"":
            # noinspection PyUnresolvedReferences
            oAction.uCmd=CCfToKeene(oAction.uCCF_Code,ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd:str=ReplaceVars(oAction.uCmd)

        self.ShowInfo(uMsg=u'Sending Command: '+uCmd + u' to '+oSetting.aIniSettings.uHost+':'+oSetting.aIniSettings.uPort)

        oSetting.Connect()
        if oSetting.bIsConnected:
            uMsg=uCmd+u'\r\n'
            try:
                uMsg=ReplaceVars(uMsg,self.uObjectName+'/'+oSetting.uConfigName)
                oSetting.oSocket.sendto(ToBytes(uMsg), (oSetting.aIniSettings.uHost, int(oSetting.aIniSettings.uPort)))
                byResponse, addr =  oSetting.oSocket.recvfrom(self.iBufferSize)
                uResponse = ToUnicode(byResponse)
                self.ShowDebug(uMsg=u'Response'+uResponse,uParConfigName=oSetting.uConfigName)
                if 'ACK' in uResponse:
                    eRet = eReturnCode.Success
                else:
                    eRet = eReturnCode.Error
            except Exception as e:
                if str(e)!="timed out":
                    self.ShowError(uMsg=u'Can\'t send message',uParConfigName=oSetting.uConfigName,oException=e)
                else:
                    self.ShowWarning(uMsg=u'Can\'t send message: time out',uParConfigName=oSetting.uConfigName)

                eRet = eReturnCode.Error

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet