123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using Edge.Core.Processor;
- using Edge.Core.IndustryStandardInterface.Pump;
- using Edge.Core.IndustryStandardInterface.ATG;
- using Edge.Core.UniversalApi;
- using Microsoft.AspNetCore.Mvc.ApiExplorer;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Logging.Abstractions;
- using ProGauge_StartItaliana_Probe.MessageEntity;
- using ProGauge_StartItaliana_Probe.MessageEntity.Incoming;
- using ProGauge_StartItaliana_Probe.MessageEntity.Outgoing;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Edge.Core.Processor.Dispatcher.Attributes;
- namespace ProGauge_StartItaliana_Probe
- {
- [MetaPartsDescriptor(
- "lang-zh-cn:Pro-gauge 探棒lang-en-us:Pro-gauge Probe",
- "lang-zh-cn:用于驱动基于 Pro-gauge RS485 协议的探棒lang-en-us:Used for driven Probes that use Pro-gauge RS485 probe protocol",
- new[] { "lang-zh-cn:探棒lang-en-us:Probe" })]
- public class Handler : IProbeHandler, IDeviceHandler<byte[], ProGauge_StartItaliana_Probe.MessageEntity.MessageBase>
- {
- private ILogger logger = NullLogger.Instance;
- private int protocolVersion = 2;
- protected IContext<byte[], MessageBase> context;
- protected int pollingInterval;
- public Probe Probe => this.probe;
- private Probe probe = null;
- [UniversalApi]
- public async Task<ProbeReading> GetProbeReadingAsync(ApiData input)
- {
- return await this.GetProbeReadingAsync();
- }
-
-
-
-
- public Handler(int probeHardwareAddress) : this(probeHardwareAddress, 2)
- {
- }
-
-
-
-
-
- public Handler(int probeHardwareAddress, int protocolVersion)
- {
- this.probe = new Probe()
- {
- HardwareIdentity = probeHardwareAddress.ToString(),
- DeviceId = probeHardwareAddress
- };
- this.protocolVersion = protocolVersion;
- }
- public void Init(IContext<byte[], MessageBase> context)
- {
- this.context = context;
-
-
-
-
-
-
-
-
-
-
-
- }
- public async Task<ProbeReading> GetProbeReadingAsync()
- {
- var response = await this.context.Outgoing.WriteAsync(new MeasureRequest(this.probe.DeviceId.ToString()),
- (request, testResponse) => testResponse is MessageBase,
- 5000);
- if (response == null) throw new TimeoutException();
- if (this.protocolVersion == 2)
- {
- var measureResponse = MeasureResponse_AnswerType2.Parse(response.RawContent.ToArray());
- var probeReading = new ProbeReading()
- {
- Height = measureResponse.ProductLevel,
- Water = measureResponse.WaterLevel,
- Temperature = new double[] { measureResponse.Temperature },
- };
- return probeReading;
- }
- else if (this.protocolVersion == 1)
- {
- var measureResponse = MeasureResponse_AnswerType1.Parse(response.RawContent.ToArray());
- var probeReading = new ProbeReading()
- {
- Height = measureResponse.ProductLevel,
- Water = measureResponse.WaterLevel,
- Temperature = new double[] { measureResponse.Temperature },
- };
- return probeReading;
- }
- throw new NotSupportedException("Unexpected ProtocolVersion: " + this.protocolVersion);
- }
- public Task Process(IContext<byte[], MessageBase> context)
- {
- return Task.CompletedTask;
-
- }
- }
- }
|