|
@@ -0,0 +1,194 @@
|
|
|
+using SCADA.CommonLib;
|
|
|
+using SCADA.CommonLib.Service;
|
|
|
+using SCADA_DAQ.Customer.Machines;
|
|
|
+using SCADA_DAQ.Customer.Models;
|
|
|
+using SCADA_DAQ.Customer.Models.SortingModel;
|
|
|
+using SCADA_DAQ.Plugin.Machine;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
+
|
|
|
+namespace SCADA_DAQ.Customer.Service
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ [DisplayName("开料分拣服务")]
|
|
|
+ public class SortingService : BaseService
|
|
|
+ {
|
|
|
+ private static SortingService _instance;
|
|
|
+ private SortingServiceConfig _SortingServiceConfig;
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ public override ObservableObject ServiceConfig
|
|
|
+ {
|
|
|
+ get => _SortingServiceConfig;
|
|
|
+ set { _SortingServiceConfig = (SortingServiceConfig)value; }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ public static SortingService Instance { get => _instance ?? (_instance = new SortingService()); }
|
|
|
+
|
|
|
+ private SortMachine plc = MachineServer.GetInstance().GetMachine<SortMachine>("分拣机");
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开料机信息
|
|
|
+ /// </summary>
|
|
|
+ public CuttingMacInfo CuttingMacState
|
|
|
+ {
|
|
|
+ get { return _CuttingMacState; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (value != _CuttingMacState)
|
|
|
+ {
|
|
|
+ _CuttingMacState = value;
|
|
|
+ OnPropertyChanged(nameof(CuttingMacState));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private CuttingMacInfo _CuttingMacState = new CuttingMacInfo();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开料机运行状态
|
|
|
+ /// </summary>
|
|
|
+ public State CuttingMacRunState
|
|
|
+ {
|
|
|
+ get { return _CuttingMacRunState; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (value != _CuttingMacRunState)
|
|
|
+ {
|
|
|
+ _CuttingMacRunState = value;
|
|
|
+ OnPropertyChanged(nameof(CuttingMacRunState));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private State _CuttingMacRunState;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ public override Type ConfigType => typeof(SortingServiceConfig);
|
|
|
+
|
|
|
+
|
|
|
+ private SortingService()
|
|
|
+ {
|
|
|
+ if (_instance == null)
|
|
|
+ {
|
|
|
+ _instance = this;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public override bool Start()
|
|
|
+ {
|
|
|
+ if (IsRunning) { return false; }
|
|
|
+ RpcService.GetInstance().Regiseter(this); //将服务中方法注册到RPC服务器,可以给WebApi调用
|
|
|
+ Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged;
|
|
|
+ return base.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Schedual_DateTimeChanged(object sender, DateTimeChangedArgs e)
|
|
|
+ {
|
|
|
+ if (e.ChangeType.HasFlag(DateTimeChangeType.SecondChanged))
|
|
|
+ {
|
|
|
+ string mainProg;
|
|
|
+ string curProg;
|
|
|
+ int curSeq;
|
|
|
+ string mode;
|
|
|
+ string status;
|
|
|
+ string alarm;
|
|
|
+ string emg;
|
|
|
+ if (plc.CuttingMac.isConnected())
|
|
|
+ {
|
|
|
+ plc.CuttingMac.READ_status(
|
|
|
+ out mainProg, out curProg, out curSeq, out mode, out status, out alarm, out emg);
|
|
|
+ CuttingMacState.MainProg = mainProg;
|
|
|
+ CuttingMacState.CurProg = curProg;
|
|
|
+ CuttingMacState.CurSeq = curSeq;
|
|
|
+ CuttingMacState.Mode = mode;
|
|
|
+ CuttingMacState.Status = status;
|
|
|
+ CuttingMacState.Alarm = alarm;
|
|
|
+ CuttingMacState.EmergencyStop = emg;
|
|
|
+ if (alarm == "ALARM")
|
|
|
+ {
|
|
|
+ CuttingMacRunState = State.Alarm;
|
|
|
+ }
|
|
|
+ else if (status == "START")
|
|
|
+ {
|
|
|
+ CuttingMacRunState = State.Stop;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CuttingMacRunState = State.Stop;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// PDA扫码获取产品信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="barcode"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public object GetData(string barcode)
|
|
|
+ {
|
|
|
+ return new object();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// PDA提交产品信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="model"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public bool SubmitData(object model)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// PDA查询历史提交记录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="count">要获取的数量</param>
|
|
|
+ /// <param name="skip">跳过的数量</param>
|
|
|
+ /// <param name="filter">过滤条件</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public object GetHistoryData(int count, int skip, string filter)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Stop()
|
|
|
+ {
|
|
|
+ Env.Schedual.DateTimeChanged -= Schedual_DateTimeChanged;
|
|
|
+ return base.Stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum State
|
|
|
+ {
|
|
|
+ [EnumDisplay("运行")]
|
|
|
+ Run,
|
|
|
+ [EnumDisplay("停止")]
|
|
|
+ Stop,
|
|
|
+ [EnumDisplay("报警")]
|
|
|
+ Alarm
|
|
|
+ }
|
|
|
+}
|