大华MVP的C#脚本使用

大华MVP的C#脚本使用

// 创建一个新文件,在其中写入指定的字符串,然后关闭文件。 如果目标文件已存在,则覆盖该文件。
System.IO.File.WriteAllText(@"C:\testDir\test1.txt", strTest, Encoding.UTF8);
string readText = File.ReadAllText(path);
string path = @"c:\temp\MyTest.txt";

// This text is added only once to the file.
if (!File.Exists(path))
{
    // Create a file to write to.
    string createText = "Hello and Welcome" + Environment.NewLine;
    File.WriteAllText(path, createText, Encoding.UTF8);
}

// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText, Encoding.UTF8);

Step1:添加输入和输出变量

在这里插入图片描述

Step2:获取输入变量


TryGetInputParam("in_0", out x);  
TryGetInputParam("in_1", out y);
TryGetInputParam("in_2", out a);

Step3:使用输入变量

Step4:赋值输出变量

SetOutputParam("out_Result", Result);
SetOutputParam("out_S3", S3);

实例:

//系统默认引用如下类库,如果需要引用第三方类库请添加MVP根目录下的CSharp3rdDll文件夹中
//System.dll
//System.configuration.dll
//System.Data.dll
//System.Management.dll
//System.Web.dll
//System.Xml.dll
//System.Windows.Forms.dll

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Dahua.Mvp.Script.ParamProtocol.ScriptParamModel;
using System.Drawing;
using System.Drawing.Imaging;

namespace Dahua.Mvp.Script
{
    /// <summary>
    /// 建议 编写脚本请仔细阅读代码下方注释
    /// 获取输入参数 TryGetInputParam("参数名称",out 参数)
    /// 设置输出参数 SetOutputParam("参数名称",参数);
    /// 输出执行日志 WriteLog(string)  日志只能在编译是显示
    /// throw 异常信息 可在MVP算子运行结果显示
    /// </summary>
    public partial class ScriptTemplate : ScriptBase
    {
        /// <summary>
        /// 初始化函数
        /// </summary>
        public override void Init()
        {
            //运行代码日志
            //WriteLog("Init Begin");
           
            //运行代码日志
            //WriteLog("Init End");
        }
        /// <summary>
        /// 处理过程
        /// </summary>
        public override void Process()
        {
        
            double x,y,a=0;
            TryGetInputParam("in_0", out x);  
		TryGetInputParam("in_1", out y);
		TryGetInputParam("in_2", out a);
		
		string strTargetPos = x+","+y+","+a;
		
		System.IO.File.WriteAllText(@"D:\\test1.txt", strTargetPos, Encoding.UTF8);
            
        }
    }
}






示例

计算耗时

     
        string path = @"E:\VTK\MyTest.csv";

	// This text is added only once to the file.
	if (!System.IO.File.Exists(path))
	{
	    // Create a file to write to.
	    string createText = "时间,耗时" + Environment.NewLine;
	    System.IO.File.WriteAllText(path, createText, Encoding.UTF8);
	}
	
	// This text is always added, making the file longer over time
	// if it is not deleted.
		int x = 0;
		TryGetInputParam("in_2", out x);  
	
		string appendText = DateTime.Now.ToString("yyyy:MM:dd:HH:mm:ss:fff")+","+x.ToString()+ Environment.NewLine;
		System.IO.File.AppendAllText(path, appendText, Encoding.UTF8);

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值