VMx

vmx.im
啥都学一点的填坑人
  1. 首页
  2. crestron
  3. 正文

simpl+与simpl#的交互

2023年5月18日 774点热度 0人点赞 0条评论

翻遍google与百度,真是太难了,共享一些思路。
simpl+ 程序最后也是被编译成 simpl# 程序,可以在程序目录 SPlsWork 中查看转换后的代码。

  • 最简 simpl+
#INCLUDEPATH "E:\\crestron\\simpl\\SIMPLSharpLibrary1\\SIMPLSharpLibrary1\\bin"
/*visual studio 2008 sp1 程序编译的目录,当然你也可以不写,默认是当前目录,你每次修改 simpl# 程序编译后需要复制到此目录。*/
#USER_SIMPLSHARP_LIBRARY "SIMPLSharpLibrary1"
/* simpl # 中的namespace 必须对应*/
DIGITAL_INPUT
PrintEstString; 
// ANALOG_INPUT 
STRING_INPUT
AddSuffix[100]; 
// BUFFER_INPUT 

// DIGITAL_OUTPUT 
// ANALOG_OUTPUT 
STRING_OUTPUT
AddSuffixReturn; 

/*声明 simpl # 中的处理类,调用必须先声明*/
TestClass myClass;

PUSH PrintEstString
{
    myClass.WriteTestString();
}

CHANGE AddSuffix
{
/*调用AddSuffix()方法*/
    AddSuffixReturn=myClass.AddSuffix(AddSuffix);
}

Function Main()
{
    WaitForInitializationComplete();
    /*必须初始化*/
    myClass.Initialize();
}
  • 最简SIMPL#程序,只演示交互,与simpl+ 一起使用。visual studio 新建项目--> Crestron --> SIMPL # Library
using System;
using System.Text;
using Crestron.SimplSharp;  
// For Basic SIMPL# Classes
using Crestron.SimplSharp.Net.Http;

// 与 #USER_SIMPLSHARP_LIBRARY 一致
namespace SIMPLSharpLibrary1
{
// 需要的类,外部要调用的必须 public
    public class TestClass
    {
        public string testString;
        public void Initialize()
        {
            testString = "Initialze";
        }//各类处理程序
        public void WriteTestString()
        { 
            CrestronConsole.PrintLine("testString="+ testString);
        }
        public string AddSuffix(string stringToAdd)
        {
            return testString + stringToAdd;
        }        
    }       
}

另一种交互方法--委托

        // 委托签名就是参数需要一致
        public delegate void CallbackHandler(SimplSharpString data);
        // 定义委托的事件,即回调事件
        // 可以将消息传递给 simpl+
        public CallbackHandler CallbackEvent { set; get; }
        // 定义一个可以 simpl+ 可以触发的调用方法
        public void TestCallback()
        {
            CallbackEvent(testString); // 调用委托事件
        }
  • simpl 程序
    
    PUSH TestCallback
    {
    myClass.TestCallback();/* 调用类中的方法以触发回调*/
    }
    // 注册的委托函数
    CALLBACK FUNCTION CallbackEventHandler(string data)
    {
    rx=data;
    /* data 就是回传的值*/
    }
    Function Main()
    {
    /* 先在 Main中注册委托(myClass-委托的主类,委托的事件-与vs中一致,本程序中的函数)*/
    REGISTERDELEGATE(myClass,CallbackEvent,CallbackEventHandler);
    }
Post Views: 714
标签: crestron simpl+ simplsharp
最后更新:2023年6月26日

huifei

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2021 vmx.im. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang