サブスクライバー NetLogic とインターフェイスを開発する

サブスクライバー NetLogic とインターフェイスを開発する

NetLogic を開発し、インターフェイスと統合します。
  1. NetLogic を開発する
  2. [MainWindow (type)]
    を右クリックし、
    [新規]
    [ランタイム NetLogic]
    を選択します。
  3. NetLogic にカーソルを合わせ、
    Edit
    を選択し、
    SubscriberLogic
    と入力します。
  4. NetLogic をダブルクリックします。
    外部コード エディターが開きます。
  5. コード エディターで、既存のコードを次のコードに置き換えます。
    #region StandardUsing using System; using FTOptix.CoreBase; using FTOptix.HMIProject; using UAManagedCore; using OpcUa = UAManagedCore.OpcUa; using FTOptix.NetLogic; using FTOptix.UI; using FTOptix.OPCUAServer; #endregion using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt.Messages; public class SubscriberLogic : BaseNetLogic { public override void Start() { var brokerIpAddressVariable = Project.Current.GetVariable("Model/BrokerIpAddress"); // Create a client connecting to the broker (default port is 1883) subscribeClient = new MqttClient(brokerIpAddressVariable.Value); // Connect to the broker subscribeClient.Connect("
    SubscriberClient
    "); // Assign a callback to be executed when a message is received from the broker subscribeClient.MqttMsgPublishReceived += SubscribeClientMqttMsgPublishReceived; // Subscribe to the "my_topic" topic with QoS 2 ushort msgId = subscribeClient.Subscribe(new string[] { "/my_topic" }, // topic new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); // QoS level messageVariable = Project.Current.GetVariable("Model/Message"); } public override void Stop() { subscribeClient.Unsubscribe(new string[] { "/my_topic" }); subscribeClient.Disconnect(); } private void SubscribeClientMqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { messageVariable.Value = "Message received: " + System.Text.Encoding.UTF8.GetString(e.Message); } private MqttClient subscribeClient; private IUAVariable messageVariable; }
  6. コードを保存します。
  7. インターフェイス要素を作成する
  8. 次のアクションを実行して、メッセージ変数を作成します。
    1. [プロジェクトビュー]
      で、
      [モデル]
      を右クリックし、
      [新規]
      [変数]
      を選択します。
    2. 変数にカーソルを合わせ、
      Edit
      を選択し、
      Message
      と入力します。
    3. [プロパティ]
      [Int32]
      を選択し、
      [String]
      を選択します。
  9. 次の操作を実行して、購読ラベルを作成します。
    1. [プロジェクトビュー]
      [MainWindow (type)]
      を右クリックし、
      [新規]
      [ベースコントロール]
      [ラベル]
      を選択します。
    2. ラベルにカーソルを合わせて
      Edit
      を選択し、
      SubscribeLabel
      を入力します。
    3. [プロパティ]
      で、
      [テキスト]
      [Message]
      変数の間にダイナミックリンクを作成します。
      ダイナミックリンクの詳細については、「ダイナミックリンクを作成する」を参照してください。
  10. インターフェイス要素を配置する。
ご質問やご意見
このドキュメントに関するご質問やご意見は、こちらまでお寄せください。 こちらからご意見をお寄せください。
Normal