OpcUaDemo.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using ProjectBase.Data.Logs;
  2. using SIMDP.Device;
  3. using ProjectBase.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. using SIMDP.Model;
  12. namespace SIMDP.Project
  13. {
  14. /// <summary>
  15. /// 仅用于代码测试
  16. /// </summary>
  17. class OpcUaDemo : PlcOpcUA
  18. {
  19. #region 数据定义
  20. #endregion
  21. #region 重写父类函数
  22. public override void actionStart() { }
  23. public override void actionStop() { }
  24. public override void actionConnected() { }
  25. public override void actionTimer()
  26. {
  27. try
  28. {
  29. // 轮询监控节点
  30. foreach (var p in monitorPoints)
  31. {
  32. object value;
  33. if (!Read(p, out value)) continue;
  34. if (!value.Equals(p.value))
  35. {
  36. p.value = value;
  37. if (p.proc != null)
  38. p.proc.Invoke(this, new object[] { value });
  39. }
  40. }
  41. redis.Publish<string>(SysEnvironment.OpcDataChannel, "");
  42. // 处理无线按钮呼叫信号
  43. //DealWirelessButtonCall();
  44. }
  45. catch (Exception ex)
  46. {
  47. LogHelper.log.Error("读取PLC(" + m_OpcUaClient.OpcUaName + ")信号(" + ")发生异常:" + ex.Message);
  48. m_OpcUaClient.Disconnect();
  49. SetRedisPlcDisConnect();
  50. }
  51. }
  52. #endregion
  53. }
  54. }