Ejemplo n.º 1
0
        private void SaveChangedData(int id, int subid, CmdDataType type, bool val)
        {
            //1.存文件

            FileStream RecFile;
            DateTime   t       = DateTime.Now;
            int        listkey = id * 10000 + subid * 100 + (int)type;

            bool bv = false;

            for (int i = 0; i < WarnDataTypeList.Length; i++)
            {
                if (type == WarnDataTypeList[i])
                {
                    bv = true;
                }
            }

            //报警系列
            // if (Array.IndexOf<CmdDataType>(WarnDataTypeList, type) >= 0)
            if (bv)
            {
                //else if (type == CmdDataType.cdtid_controledPump)
                //{
                //    RecFile = new FileStream(WarningRecFileName, FileMode.Append);
                //    listkey = -100 - id;
                //}
                if (type == CmdDataType.cdtid_redundantPump ||
                    type == CmdDataType.cdtid_controledPump)
                {
                    //listkey = -200 - id;
                    listkey =
                        id_controledPump * -100 +
                        id_redundantPump * -1;
                }

                RecFile = new FileStream(WarningRecFileName, FileMode.Append);

                if (val)
                {
                    if (!_curwarninglist.ContainsKey(listkey))
                    {
                        _curwarninglist.Add(listkey, t);
                    }
                }
                else
                {
                    if (_curwarninglist.ContainsKey(listkey))
                    {
                        _curwarninglist.Remove(listkey);
                    }
                }
            }
            else//故障系列
            {
                RecFile = new FileStream(ErrorRecFileName, FileMode.Append);

                if (val)
                {
                    if (!_curerrorlist.ContainsKey(listkey))
                    {
                        _curerrorlist.Add(listkey, t);
                    }
                }
                else
                {
                    if (_curerrorlist.ContainsKey(listkey))
                    {
                        _curerrorlist.Remove(listkey);
                    }
                }
            }

            BinaryWriter bw = new BinaryWriter(RecFile);

            try
            {
                bw.Write((int)listkey);       //4
                bw.Write((val) ? 1 : 0);      //4
                bw.Write(DateTime.Now.Ticks); //8
            }
            finally
            {
                bw.Flush();
                bw.Close();
                RecFile.Close();
            }

            //2. 事件通知界面
        }
Ejemplo n.º 2
0
        private bool CheckValue(CmdDataType DataType, double val)
        {
            bool bv = false;

            switch (DataType)
            {
            case CmdDataType.cdtPressureAlarm_Pump:
                bv = true;
                break;

            //截面积范围0.00~99.99dm^2
            //cdtSectionalArea_Value,//油缸截面积 4*8
            case CmdDataType.cdtSectionalArea_Value:
                bv = (val >= 0 && val <= 99.99);
                break;

            //最大压力范围:0.0~800.0bar
            //cdtMAXPressure_Value,//油缸最大压力 4*8
            case CmdDataType.cdtMAXPressure_Value:
                bv = (val >= 0 && val <= 800);
                break;

            //最大位移范围:0.0~999.9mm
            //cdtMAXPosition_Value, //油缸最大位移 4*8
            case CmdDataType.cdtMAXPosition_Value:
                bv = (val >= 0 && val <= 999.9);
                break;

            //泵站压力传感器最大量程 400 0.0~500.0
            //cdtMAXPressure_Pump_Value,//泵站压力传感器最大量程 4
            case CmdDataType.cdtMAXPressure_Pump_Value:
                bv = (val >= 0 && val <= 500.0);
                break;

            //马达最大压力设定:0~400.0bar
            //cdtPumpPressureHighout,          //马达最大压力设定	       4*8
            case CmdDataType.cdtPumpPressureHighout:
                bv = (val >= 0 && val <= 400);
                break;

            //油缸最大行程设定值:0.0~999.9mm
            //cdtPumpPositionHighout,          //油缸最大行程设定值		   4*8
            case CmdDataType.cdtPumpPositionHighout:
                bv = (val >= 0 && val <= 999.9);
                break;

            //油缸当天行程最大设定值:0.0~999.9mm
            //cdtPumpTodayPositionHighout //油缸当天行程最大设定值 4*8
            case CmdDataType.cdtPumpTodayPositionHighout:
                bv = (val >= 0 && val <= 999.9);
                break;

            //油缸最大轴力 3500 0.0~4000.0
            //cdtMAXPressure2_Value//油缸最大轴力 4*8
            case CmdDataType.cdtMAXPressure2_Value:
                bv = (val >= 0 && val <= 4000.0);
                break;

            default:
                bv = true;
                break;
            }

            if (!bv)
            {
                MessageBox.Show("输入数值越界!", "",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
            }

            return(bv);
        }