MainMachine _IOMonitor.cs 4.3 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        bool MaterialDoorOpen = false;
        void ioMonitor()
        {
            if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW)) {
                Msg.add(crc.GetString(L.not_detect_airpressure, "未检测到气压信号."), MsgLevel.warning);
            }

            if ((StringState >= StringStateE.OutStore) && IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.LOW))
            {
                MaterialDoorOpen = true;
                RequestTakeOutReel = false;
                StringState = StringStateE.None;
            }
            else if (IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.HIGH) && StringMoveInfo.MoveStep == MoveStep.Wait)
            {
                if (!Setting_Init.Device_Disable_AutoLifTingAfterTakeReel)
                    StringMoveInfo.NextMoveStep(MoveStep.StringDown);
                MaterialDoorOpen = false;
            }
            if (!Setting_Init.Device_Disable_AutoLifTingAfterTakeReel)
            {
                if (MaterialDoorOpen && StringMoveInfo.MoveStep == MoveStep.Wait && IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.LOW))
                {
                    if (IOValue(IO_Type.OutCheck).Equals(IO_VALUE.LOW) && !Batch_Axis.IsBusy && !Batch_Axis.IsInPosition(Config.Batch_P2))
                    {
                        Batch_Axis.AbsMove(null, Config.Batch_P2, Config.Batch_P1_speed);
                        //开始检测信号
                        Batch_Axis.BatchAxisStartCheck(IO_Type.OutCheck, IO_VALUE.HIGH);
                    }
                }
            }
            airprocess();
        }
        public double Current_Humidity = 0;
        public double Current_Temperate = 0;
        bool airisopen = false;
        DateTime lastAirprocesstime = DateTime.Now;
        void airprocess()
        {
            if ((DateTime.Now - lastAirprocesstime).TotalSeconds < 5)
                return;
            lastAirprocesstime = DateTime.Now;
            
            //var temp = HumitureController.QueryData();
            var temp = HumitureController.LastData;
            Current_Humidity = temp.Humidity;
            Current_Temperate = temp.Temperate;

            //var tempIsOK = Current_Temperate < ServerCM.Max_Temperature;
            var humiNeedStart = Current_Humidity > ServerCM.Max_Humidity - Setting_Init.Device_HumidityStartOffser;
            var humiNeedStop = Current_Humidity < ServerCM.Max_Humidity - Setting_Init.Device_HumidityEndOffser;

            if (humiNeedStart && !airisopen)
            {
                IOMove(IO_Type.NitrogenValve, IO_VALUE.HIGH);
                airisopen = true;
                LogUtil.info($"开始吹气,当前最大湿度:{Current_Humidity} > {ServerCM.Max_Humidity}-{Setting_Init.Device_HumidityStartOffser}.");
            }
            else if (humiNeedStop && airisopen)
            {
                IOMove(IO_Type.NitrogenValve, IO_VALUE.LOW);
                airisopen = false;
                LogUtil.info($"关闭吹气,当前最大湿度:{Current_Humidity} < {ServerCM.Max_Humidity}-{Setting_Init.Device_HumidityEndOffser}.");
            }
        }
        bool lastTHoutRangeStatus = false;
        DateTime lastTHoutRangeTime = DateTime.MaxValue;
        bool IsTHoutRange()
        {
            if (HumitureController.LastData.Humidity > ServerCM.Max_Humidity// || HumitureController.LastData.Humidity < ServerCM.Min_Humidity
                || HumitureController.LastData.Temperate > ServerCM.Max_Temperature)
            {
                if (!lastTHoutRangeStatus)
                    lastTHoutRangeTime = DateTime.Now;
                lastTHoutRangeStatus = true;
                return true;
            }
            else
            {
                if (lastTHoutRangeStatus)
                    lastTHoutRangeTime = DateTime.MaxValue;
                lastTHoutRangeStatus = false;
                return false;
            }
        }
        bool IsTHoutRangeOver30m() {
            return (DateTime.Now - lastTHoutRangeTime).TotalMinutes > 30;
        }
    }
}