python-canoe远程压力测试

#13.0版本CANoe  PYTHON 模板路径  C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 13.0.155\Programming\Python
# coding: utf-8
"""API for setup/usage of Canoe COM Client interface.
"""
# --------------------------------------------------------------------------
# Standard library imports
import os
import sys
import subprocess
import time
import msvcrt
import serial
import requests #python 控制钉钉专用
import json #python 控制钉钉专用
from win32com.client import *
from win32com.client.connect import *


# Vector Canoe Class
class CANoe:
    def __init__(self):
        self.application = None
        self.application = DispatchEx("CANoe.Application")
        self.ver = self.application.Version
        print('Loaded CANoe version ',
            self.ver.major, '.',
            self.ver.minor, '.',
            self.ver.Build, '...')#, sep,''
        self.Measurement = self.application.Measurement.Running

    def open_cfg(self, cfgname):
        # open CANoe simulation
        if (self.application != None):
            # check for valid file and it is *.cfg file
            if os.path.isfile(cfgname) and (os.path.splitext(cfgname)[1] == ".cfg"):
                self.application.Open(cfgname)
                print("opening..."+cfgname)
            else:
                raise RuntimeError("Can't find CANoe cfg file")
        else:
            raise RuntimeError("CANoe Application is missing,unable to open simulation")

    def close_cfg(self):
        if (self.application != None):
            # self.stop_Measurement()
            self.application.Quit()
            self.application = None

    def start_Measurement(self):
        retry = 0
        retry_counter = 5
        # try to establish measurement within 5s timeout
        while not self.application.Measurement.Running and (retry < retry_counter):
            self.application.Measurement.Start()
            time.sleep(1)
            retry += 1
        if (retry == retry_counter):
            raise RuntimeWarning("CANoe start measuremet failed, Please Check Connection!")
    def stop_Measurement(self):
        if self.application.Measurement.Running:
            self.application.Measurement.Stop()
        else:
            pass



    def get_SigVal(self, channel_num, msg_name, sig_name, bus_type="CAN"):
        """
        @summary Get the value of a raw CAN signal on the CAN simulation bus
        @param channel_num - Integer value to indicate from which channel we will read the signal, usually start from 1,
                             Check with CANoe can channel setup.
        @param msg_name - String value that indicate the message name to which the signal belong. Check DBC setup.
        @param sig_name - String value of the signal to be read
        @param bus_type - String value of the bus type - e.g. "CAN", "LIN" and etc.
        @return The CAN signal value in floating point value.
                Even if the signal is of integer type, we will still return by
                floating point value.
        @exception None
        """
        if (self.application != None):
            result = self.application.GetBus(bus_type).GetSignal(channel_num, msg_name, sig_name)
            return result.Value
        else:
            raise RuntimeError("CANoe is not open,unable to GetVariable")






    def get_EnvVar(self, var):
        if (self.application != None):
            result = self.application.Environment.GetVariable(var)
            return result.Value
        else:
            raise RuntimeError("CANoe is not open,unable to GetVariable")

    def set_EnvVar(self, var, value):
        result = None
        if (self.application != None):
            # set the environment varible
            result = self.application.Environment.GetVariable(var)
            result.Value = value
            checker = self.get_EnvVar(var)
            # check the environment varible is set properly?
            while (checker != value):
                checker = self.get_EnvVar(var)
        else:
            raise RuntimeError("CANoe is not open,unable to SetVariable")

    def get_SysVar(self, ns_name, sysvar_name):
        if (self.application != None):
            systemCAN = self.application.System.Namespaces
            sys_namespace = systemCAN(ns_name)
            sys_value = sys_namespace.Variables(sysvar_name)
            return sys_value.Value
        else:
            raise RuntimeError("CANoe is not open,unable to GetVariable")

    def set_SysVar(self, ns_name, sysvar_name, var):
        if (self.application != None):
            systemCAN = self.application.System.Namespaces
            sys_namespace = systemCAN(ns_name)
            sys_value = sys_namespace.Variables(sysvar_name)
            sys_value.Value = var
        else:
            raise RuntimeError("CANoe is not open,unable to GetVariable")			



    def DoEvents(self):#作用纯粹的阻塞进程
        pythoncom.PumpWaitingMessages()
        time.sleep(1)


"""
portx="COM44"
bps=9600
timex=5
ser=serial.Serial(portx,bps,timeout=timex)
"""
app = CANoe() #定义CANoe为app
app.open_cfg(r"F://台架实验.cfg") #导入某个CANoe congif
time.sleep(5)
app.start_Measurement()#让CANoe 运行起来相当于点下了 闪电标志






#def dingmessage():
# 请求的URL,WebHook地址,,,发现bug时启动发送
#    webhook = "https://oapi.dingtalk.com/robot/send?access_token=2ca480540a81a8013c2be88680bebf560138f9dc93c80c8452d9ca"
#构建请求头部
#    header = {
#        "Content-Type": "application/json",
#        "Charset": "UTF-8"
#}


#构建请求数据
#    tex0 = "远程测试+请注意发现了太网频繁linkdown的bug"
#    tex1 = "远程测试+请注意发现了someip无法建立的的bug"
#    tex2 = "远程测试+请注意发现了DUT不休眠的bug"
#    tex3 = "远程测试+请注意发现了busoff的bug"
#    tex4 = "远程测试+请注意发现了远程控制失败的bug"
#    tex5 = "远程测试+请注意发现了休眠唤醒后DUT起不来的bug"
    #message ={

     #   "msgtype": "text",
     #   "text": {
     #       "content": tex
      #  },
      #  "at": {

      #      "isAtAll": True
       # }

   # }
#对请求的数据进行json封装
    #message_json = json.dumps(message)
#发送请求
    #info = requests.post(url=webhook,data=message_json,headers=header)
#打印返回的结果
    #print(info.text)

#if __name__=="__main__":
#    dingmessage()









# 需要实现如何在CAPL里监测linkdown, someip未建立的情况,本重点任务需要在CAPL里完成


















while not msvcrt.kbhit():
#构建请求数据
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=2ca486e540a81a8013c2be88680bebf560138f9dc93c80c8452d9ca"
    header = {
        "Content-Type": "application/json",
        "Charset": "UTF-8"}
    tex0 = "远程测试+请注意发现了太网频繁linkdown的bug"
    tex1 = "远程测试+请注意发现了someip无法建立的的bug"
    tex2 = "远程测试+请注意发现了DUT不休眠的bug"
    tex3 = "远程测试+请注意发现了busoff的bug"
    tex4 = "远程测试+请注意发现了远程控制失败的bug"
    tex5 = "远程测试+请注意发现了休眠唤醒后DUT起不来的bug"
    tex6 = "远程测试+请注意发现了某一时间点不能上网问题"
    
    TGS_LEVER = app.get_SigVal(channel_num=1, msg_name="FD2", sig_name="TRS_LEVER", bus_type="CAN") #直接获取信号 
    print("代表报警信号数值",TRS_LEVER)
    if TGS_LEVER==1: #发生了频繁linkdown
        tex=tex0
        message ={
            "msgtype": "text",
            "text": {
                "content": tex
            },
            "at": {

                "isAtAll": True
            }

        }

        message_json = json.dumps(message)
        info = requests.post(url=webhook,data=message_json,headers=header)
        



    elif TRS_LEVER==2:#代表发生了Someip 无法建立问题
        tex=tex1
        message ={
            "msgtype": "text",
            "text": {
                "content": tex
            },
            "at": {

                "isAtAll": True
            }

        }
        message_json = json.dumps(message)
        info = requests.post(url=webhook,data=message_json,headers=header)
        TRS_LEVER=0

    elif TRS_LEVER==3:#代表发生了wakeup 后 DUT不工作的问题
        tex=tex5
        message ={
            "msgtype": "text",
            "text": {
                "content": tex
            },
            "at": {

                "isAtAll": True
            }

        }
        message_json = json.dumps(message)
        info = requests.post(url=webhook,data=message_json,headers=header)
        TRS_LEVER=0

    elif TRS_LEVER==4:#代表发生了DUT不休眠的bug
        tex=tex2
        message ={
            "msgtype": "text",
            "text": {
                "content": tex
            },
            "at": {

                "isAtAll": True
            }

        }
        message_json = json.dumps(message)
        info = requests.post(url=webhook,data=message_json,headers=header)
        TRS_LEVER=0


    elif TRS_LEVER==6:#代表发生了DUT不休眠的bug
        tex=tex6
        message ={
            "msgtype": "text",
            "text": {
                "content": tex
            },
            "at": {

                "isAtAll": True
            }

        }
        message_json = json.dumps(message)
        info = requests.post(url=webhook,data=message_json,headers=header)
        TGS_LEVER=0




    """SPowerMode2 = app.get_SigVal(channel_num=1, msg_name="FD6", sig_name="SystemPowerMode", bus_type="CAN") #直接获取信号 
    
    print("车辆电源模式",SPowerMode2)
    if SPowerMode==2:#代表电源模式ON
        RelayOnData=[0x33,0x01,0x12,0x00,0x00,0x00,0x01,0x47]
        result=ser.write(RelayOnData)
    elif SPowerMode==0:#代表电源模式OFF
        RelayOffData=[0x33,0x01,0x11,0x00,0x00,0x00,0x01,0x46]
        result=ser.write(RelayOffData)



    V_DriverDoorSts = app.get_EnvVar("Var_DoorSts")#获取环境变量
    if(V_DriverDoorSts==1):
        app.set_EnvVar("Var_DoorSts",1)#直接处理环境变量


    Network_Switch = app.get_SysVar("huts","NetSwitch")#获取系统变量
    if(Network_Switch==0):
        app.set_SysVar("huts","NetSwitch",0)#直接处理系统变量
	"""
    app.DoEvents()

    

app.close_cfg()


  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倚天仗剑走天涯WGM

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值