- プロジェクトの作成
- オブジェクトと変数のリファレンス
- プロジェクトの拡張
- チュートリアル
- グラフィックオブジェクト チュートリアル
サブスクライバー NetLogic とインターフェイスを開発する
NetLogic を開発し、インターフェイスと統合します。
- NetLogic を開発する
- [MainWindow (type)]を右クリックし、 を選択します。
- NetLogic にカーソルを合わせ、を選択し、SubscriberLogicと入力します。
- NetLogic をダブルクリックします。外部コード エディターが開きます。
- コード エディターで、既存のコードを次のコードに置き換えます。#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; }
- コードを保存します。
- インターフェイス要素を作成する
- 次のアクションを実行して、メッセージ変数を作成します。
- [プロジェクトビュー]で、[モデル]を右クリックし、 を選択します。
- 変数にカーソルを合わせ、を選択し、Messageと入力します。
- [プロパティ]で[Int32]を選択し、[String]を選択します。
- 次の操作を実行して、購読ラベルを作成します。
- [プロジェクトビュー]で[MainWindow (type)]を右クリックし、 を選択します。
- ラベルにカーソルを合わせてを選択し、SubscribeLabelを入力します。
- [プロパティ]で、[テキスト]と[Message]変数の間にダイナミックリンクを作成します。ダイナミックリンクの詳細については、「ダイナミックリンクを作成する」を参照してください。
- インターフェイス要素を配置する。

ご質問やご意見