- 프로젝트 만들기
- 개체 및 변수 참조
- 프로젝트 확장
구독자 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변수 간에 동적 링크를 만듭니다.동적 링크에 대한 자세한 내용은 동적 링크 만들기 항목을 참조하십시오.
- 인터페이스 요소 정렬.

의견을 작성 부탁드립니다.