使用pyriott来自动化测试VI的一些细节

  • 如果创建一个新的virtual enviroment需要安装哪些packages?安装命令是?
pip install pyriott -i http://ni-pypi --trusted-host ni-pypi

除了pyriott,还需要安装:

mobilize
machinations
pytest
pytest_origin_reporter
pyyaml
  • 一个范例
# Python standard libraries
import os
import sys
import argparse

from labview_automation.labview.utilities import start_labview_server
from labview_automation.client import LabVIEWClient
from pyriott.deploy_and_run import DeployAndRun
from pyriott.project_manipulation import ProjectManipulation

#file name
LabVIEW_Project_Name = 'test.lvproj'
Test_VI_name = 'Backup NVMEM to File.vi'

#file path
Current_File_Path = __file__
Example_VI_Relative_Path = r'\examples\SLSC\NVMEM and Register'
Pharlap_Bin_File_Path = r'c:\ni-rt\raw.bin'
Linux_Bin_File_Path = r'/c/ni-rt'

def _get_parser_options(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--target_ip', dest='target_ip', required=True)
    parser.add_argument('--target_type', dest='target_type', choices=['cRIO-9068', 'cRIO-9030', 'cRIO-9081'], required=True)
    parser.add_argument('--module_name', dest='module_name', required=True)
    parser.add_argument('--labview_version', dest='labview_version', default='2016', required=True)
    parser.add_argument('--labview_path', dest='labview_path', default=r'C:\Program Files (x86)\National Instruments\LabVIEW 2016', required=True)
    return parser.parse_args(args)

class BackupNVOnRT(object):
    def __init__(self, target_ip, target_type, module_name, labview_version, labview_path):
        self.target_ip = target_ip
        self.target_type = target_type
        self.module_name = module_name
        self.labview_version = labview_version
        self.labview_path = labview_path

    def run(self):
        project_path = os.path.join(os.getcwd(), LabVIEW_Project_Name)
        test_vi_path = self.labview_path + Example_VI_Relative_Path + '\\' + Test_VI_name
        print(test_vi_path)
        start_labview_server(self.labview_version, True, True, 900)
        output_file_path = ''
        if self.target_type == 'cRIO-9068' or self.target_type == 'cRIO-9030':
            output_file_path = Linux_Bin_File_Path
        else:
            output_file_path = Pharlap_Bin_File_Path
        with LabVIEWClient("localhost") as client:
            lv_project = ProjectManipulation(
                client,
                project_path,
                open_vis=False)
            lv_project.create()
            target_name = lv_project.create_controller(self.target_type, self.target_ip)
            lv_project.add_vi_to_target(target_name, test_vi_path)
            lv_project.open()
            controls = {
                'NVMEM area': self.module_name + '/raw',
                'Output File': output_file_path
            }
            try:
                DeployAndRun(client).deploy_and_run_vi(
                    project_path,
                    target_name,
                    test_vi_path,
                    target_name,
                    controls,
                    {},
                    timeout=-1)
            except Exception as e:
                print(e)
                exit(1)
            lv_project.close()

if __name__ == '__main__':
    options = _get_parser_options(sys.argv[1:])
    backup_nv_test = BackupNVOnRT(
        target_ip = options.target_ip,
        target_type = options.target_type,
        module_name = options.module_name,
        labview_version = options.labview_version,
        labview_path = options.labview_path)

    backup_nv_test.run()

对应的执行命令:

python ExampleVIsOnRT.py --target_ip 10.144.160.229 --target_type cRIO-9081 --module_name SLSC-12001-030898C6-Mod1 --labview_version 2016

python ExampleVIsOnRT.py --target_ip 10.144.160.229 --target_type cRIO-9081 --module_name SLSC-12001-030898C6-Mod1 --labview_version 2016 --labview_path "C:\Program Files (x86)\National Instruments\LabVIEW 2016"

如果出现invoke noed error1,有可能是target上RT的版本和主机上不一致造成的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值