Handler.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
  2. using OPW_VaporRecoveryOnlineWatch_PressureGage.MessageEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml;
  10. using System.Xml.Serialization;
  11. using Timer = System.Timers.Timer;
  12. namespace OPW_VaporRecoveryOnlineWatch_PressureGage
  13. {
  14. public class Handler : IDeviceHandler<byte[], PressureGageBaseMessage>
  15. {
  16. static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("PumpHandler");
  17. protected IContext<byte[], PressureGageBaseMessage> context;
  18. //range from 0 to 3,最终需要看A/D转换器有几路输入
  19. private byte pinIndexOfGageConnectedInADConverter;
  20. //电流到压力的转换乘积因子
  21. private int currentToPaMultiplyFactor;
  22. public Handler(int pinIndexOfGageConnectedInADConverter, int currentToPaMultiplyFactor)
  23. {
  24. this.pinIndexOfGageConnectedInADConverter = (byte)pinIndexOfGageConnectedInADConverter;
  25. this.currentToPaMultiplyFactor = currentToPaMultiplyFactor;
  26. }
  27. public void Init(IContext<byte[], PressureGageBaseMessage> context)
  28. {
  29. this.context = context;
  30. var timeWindowWithActivePollingOutgoing = this.context.Outgoing as TimeWindowWithActivePollingOutgoing<byte[], PressureGageBaseMessage>;
  31. timeWindowWithActivePollingOutgoing.PollingMsgProducer = () => new ReadAnalogDataRequest(this.pinIndexOfGageConnectedInADConverter);
  32. }
  33. public Task Process(IContext<byte[], PressureGageBaseMessage> context)
  34. {
  35. var response = context.Incoming.Message as ReadAnalogDataResponse;
  36. logger.Debug("Pressure Gage on PIN " + this.pinIndexOfGageConnectedInADConverter + " read raw current value: " + response.Data);
  37. //CloudRestClient.Default.UploadDataAsync(
  38. // new DeviceUploadData_V1(this.context.Processor.SerialNumber,
  39. // Common.Cloud.Entity.Local.DataPriorityLevel.Info)
  40. // {
  41. // PressureValue = response.Data
  42. // }, null);
  43. return Task.CompletedTask;
  44. }
  45. }
  46. }