구독자 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