Ejemplo n.º 1
0
        public void Write()
        {
            if (this.serialPort == null || !this.IsOpen)
            {
                return;
            }

            try
            {
                /*
                 * // 归一化时间
                 * DateTime rightTime = default(DateTime);
                 * if (!this.recordTimePolicy.NowAtRightTime(out rightTime) ||
                 *  this.currentRecordTime == rightTime)
                 * {
                 *  return;
                 * }
                 * this.currentRecordTime = rightTime;
                 * */

                // 记录当前值
                if (this.IsRealDevice)
                {
                    this.serialPort.Write(this.actionSend1, 0, this.actionSend1.Length);
                }

                // 23:59时重置气象探测器,可能会多次发送重置命令
                DateTime currentTime = DateTime.Now;
                if (currentTime.ToString("HH:mm").Equals("23:59"))
                {
                    // 等待1s,再发送重置命令
                    Thread.Sleep(1000);

                    if (this.IsRealDevice)
                    {
                        this.serialPort.Write(this.actionSend2, 0, this.actionSend2.Length);
                    }
                }

                #region Virtual-Device
                else
                {
                    this.OnSendDataToVirtualDevice(this.actionSend1);
                }
                #endregion
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(this, "Write COM Data Error: " + e.Message, RecordType.Error);
            }
        }
Ejemplo n.º 2
0
        public bool Connect(string portName)
        {
            try
            {
                this.serialPort = new SerialPort(portName);

                this.serialPort.BaudRate = this.baudRate;

                this.serialPort.Parity      = this.parity;   //Parity none
                this.serialPort.StopBits    = this.stopBits; //(StopBits)this.stopBits;    //StopBits 1
                this.serialPort.DataBits    = this.dataBits; // this.dataBits;   // DataBits 8bit
                this.serialPort.ReadTimeout = 10000;         // this.readTimeout;

                this.serialPort.RtsEnable     = true;
                this.serialPort.NewLine       = "/r/n";         //?
                this.serialPort.DataReceived += this.SerialPortDataReceived;

                // Real Devie begins here.
                if (this.IsRealDevice)
                {
                    this.serialPort.Open();

                    if (this.actionInterval > 0)
                    {
                        this.StartSenderTimer(this.actionInterval);
                    }

                    // Set status of starting.
                    PostStartStatus();
                }
                else
                {
                    RecordManager.DoSystemEventRecord(this, "Notice, Virtual Device Started");
                    this.StartVirtualDevice();
                }
            }
            catch (IOException e)
            {
                string message = "IO: " + e.Message;
                RecordManager.DoSystemEventRecord(this, message);
                return(false);
            }
            catch (Exception e)
            {
                string message = "Other: " + e.Message;
                RecordManager.DoSystemEventRecord(this, message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private string GetText(IntPtr hWnd, int nCtrlId)
        {
            sb.Length = 0;
            IntPtr edit = GetDlgItem(hWnd, nCtrlId);

            if (edit == IntPtr.Zero)
            {
                string wrongEditId = string.Format("Wrong Edit Id: {0}", nCtrlId);
                RecordManager.DoSystemEventRecord(this, wrongEditId);
            }
            IntPtr result = IntPtr.Zero;

            SendMessageTimeout(edit, WM_GETTEXT, BufferLength, sb, 0, 1000, out result);
            return(sb.ToString());
        }
Ejemplo n.º 4
0
        public void Connect()
        {
            try
            {
                string connectionString = new DBConnectionString().ToString();
                this.conn = new MySqlConnection(connectionString);
                this.conn.Open();
                this.cmd = this.conn.CreateCommand();
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(Device.Main, e.Message, RecordType.Error);

                // disable RetryConnection      by Kaikai
                //this.RetryConnection(e);
            }
        }
Ejemplo n.º 5
0
        public bool AddRecordData(string commandText, DeviceData data)
        {
            try
            {
                if (this.cmd != null)
                {
                    this.cmd.CommandText = commandText;
                    var items = data.Data;
                    for (int i = 0; i < items.Length; ++i)
                    {
                        string at = string.Format("@{0}", i + 1);
                        this.cmd.Parameters.AddWithValue(at, items[i]);
                    }

                    int num = this.cmd.ExecuteNonQuery();
                    if (num != 1)
                    {
                        this.cmd.Parameters.Clear();
                        return(false);
                    }
                    // If exception, the params would NOT clear.
                    // cmd.Parameters.Clear();
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(data.Device, string.Format("{0} => {1}", commandText, e.Message), RecordType.Error);
                //this.RetryConnection(e);
                cmd.Parameters.Clear();
                return(false);
            }
            finally
            {
                if (this.cmd != null)
                {
                    this.cmd.Parameters.Clear();
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        private static void WriteDataToLog(Device device, string content, RecordType recordType, bool flush = false)
        {
            // To Log File
            DateTime      now        = DateTime.Now;
            StreamWriter  fileWriter = RecordManager.GetLogFileStream(device, now);
            string        time       = string.Format("[{0:HH:mm:ss}] ", now);
            StringBuilder sb         = new StringBuilder(time);

            sb.Append(string.Format(" <{0}> ", recordType.ToString()));
            sb.Append(content);
            string line = sb.ToString();

            fileWriter.WriteLine(line);

            // Flush Control.
#if DEBUG
            fileWriter.Flush();
#else
            if (flush)
            {
                fileWriter.Flush();
            }
#endif

            if (flushCtrlCount % 10 == 0)
            {
                fileWriter.Flush();
            }
            flushCtrlCount = (flushCtrlCount + 1) % 5;

            // To Log Console
            if (ExistLoggerConsoleProc())
            {
                string deviceKey = device.Id.ToLower();
                if (LoggerClient.Contains(deviceKey))
                {
                    logger.Send(deviceKey, line);
                }
            }
        }
Ejemplo n.º 7
0
        //////////////////////////////////////////////////////////////////////

        private byte[] ReadData()
        {
            if (this.IsRealDevice)
            {
                // important, sleep 400ms to wait all the data come to system buffer, Kaikai
                Thread.Sleep(this.bufferSleep);

                int n = this.serialPort.BytesToRead;
                if (n == 0)
                {
                    return(null);
                }
                else
                {
                    byte[] buffer = new byte[n];

                    int r = this.serialPort.Read(buffer, 0, n);
                    if (r != n)
                    {
                        RecordManager.DoSystemEventRecord(this, "SerialPort Read Error");

                        return(null);
                    }

                    return(buffer);
                }
            }
            else             // Virtual Device~!
            {
                if (this.actionInterval > 1)
                {
                    // 假设: 应答式的数据,都是完整的帧.
                    return(this.GetExampleLine());
                }
                else
                {
                    return(this.GetExampleLine());
                }
            }
        }
Ejemplo n.º 8
0
        private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs evt)
        {
            Debug.Assert(this.DataReceived != null);
            try
            {
                handled = false;
                byte[] buffer = this.ReadData();

                byte[] line = this.dataParser.GetLineBytes(buffer);
                if (line == null || line.Length == 0)
                {
                    return;
                }

                /*
                 * if (this.sensitive)
                 * {
                 *  DeviceData sdd;
                 *  if (this.GetSensitiveData(line, out sdd))
                 *  {
                 *      this.SynchronizationContext.Post(this.DataReceived, sdd);
                 *  }
                 * }
                 * */

                if (this.OnReceiveData(line))
                {
                    this.RecordData(line);
                }
            }
            catch (InvalidOperationException e)
            {
                RecordManager.DoSystemEventRecord(this, e.Message);
            }
            finally
            {
                handled = true;
            }
        }
Ejemplo n.º 9
0
        private bool AutoMode(string[] data)
        {
            //RecordManager.DoSystemEventRecord(this, "进入自动模式", RecordType.Event);

            // 24小时模式
            if (data[14] == "1" && data[13] == "0" && data[12] == "0" && data[11] == "0")
            {
                LoopMode = 0;
                return(Mode24(data));
            }

            // 8小时模式
            if (data[14] == "0" && data[13] == "1" && data[12] == "0" && data[11] == "0")
            {
                LoopMode = 1;
                return(Mode8(data));
            }

            // 6小时模式
            if (data[14] == "0" && data[13] == "0" && data[12] == "1" && data[11] == "0")
            {
                LoopMode = 2;
                return(Mode6(data));
            }

            // 1小时模式
            if (data[14] == "0" && data[13] == "0" && data[12] == "0" && data[11] == "1")
            {
                LoopMode = 3;
                return(Mode1(data));
            }

            else
            {
                RecordManager.DoSystemEventRecord(this, "Unknown mode");
                return(false);
            }
        }
Ejemplo n.º 10
0
        protected bool GetDeviceData(byte[] line, DateTime time, out DeviceData dd)
        {
            dd = default(DeviceData);

            if (time == default(DateTime))
            {
                time = DateTime.Now;
            }
            string[] data = null;
            try
            {
                data          = this.dataParser.Search(line, this.lastLine);
                this.lastLine = line;

                if (data == null || data.Length == 0)
                {
                    RecordManager.DoSystemEventRecord(this, string.Format("GetDeviceData() Error, Data={0}", Encoding.ASCII.GetString(line)));
                    return(false);
                }

                dd.Time = time;
                object[] fields = Device.GetFieldsData(data, time, this.fieldsConfig);
                dd = new DeviceData(this, fields);
                dd.InsertIntoCommand = this.insertIntoCommand;
            }
            catch (Exception e)
            {
                string strLine  = Encoding.ASCII.GetString(line);
                string errorMsg = string.Format("GetDeviceData() Exception, Data={0}", strLine) + e.Message;
                RecordManager.DoSystemEventRecord(this, errorMsg);

                return(false);
            }

            // deviceData.FieldsConfig = this.fieldsConfig;
            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="o"></param>
        private void TimerCallback(object o)
        {
            if (!File.Exists(strSidPath))
            {
                RecordManager.DoSystemEventRecord(this, "no SID exsiting!", RecordType.Error);
                return;
            }

            this.SID = File.ReadAllText(strSidPath).Trim();
            if (this.SID == "")
            {
                RecordManager.DoSystemEventRecord(this, "no date in SID file!", RecordType.Error);
                return;
            }

            string DES = strFileCopy2Path + "\\" + this.SID + "\\";

            if (Directory.Exists(DES) == false)
            {
                Directory.CreateDirectory(DES);
            }

            string originPath = strFileMonitoringPath + "\\";

            if (Directory.Exists(originPath) == false)
            {
                Directory.CreateDirectory(originPath);
            }

            foreach (string vFile in Directory.GetFiles(originPath))
            {
                string filename = Path.GetFileName(vFile);
                filename = filename.ToLower();
                if (File.GetLastWriteTime(vFile) >= DateTime.Now.AddSeconds(-150000)) // 如果文件是在150秒内修改
                {
                    if (filename.Contains("qaspectra.spe"))
                    {
                        string NewSpecName = "qaspectra" + DateTime.Now.ToString("_yyyy_MM_ddTHH_mm_ss") + ".spe";
                        File.Move(vFile, DES + "!" + NewSpecName);

                        this.Record(NewSpecName);
                    }
                    else if (filename.Contains("qareport.rpt"))
                    {
                        string NewReportName = "qareport" + DateTime.Now.ToString("_yyyy_MM_ddTHH_mm_ss") + ".spe";
                        File.Move(vFile, DES + "!" + NewReportName);

                        this.Record(NewReportName);
                    }
                    else if (filename.Contains("samplespectra2-"))
                    {
                        int    index        = filename.LastIndexOf(".");
                        string newfilenameA = filename.Substring(0, index) + DateTime.Now.ToString("_yyyy_MM_ddTHH_mm_ss") + ".spe";
                        File.Move(vFile, DES + "!" + newfilenameA);

                        this.Record(newfilenameA);
                    }
                    else if (filename.Contains("samplespectra24.spe"))
                    {
                        string newfilenameB = "samplespectra24" + DateTime.Now.ToString("_yyyy_MM_ddTHH_mm_ss") + ".spe";
                        File.Move(vFile, DES + "!" + newfilenameB);

                        this.Record(newfilenameB);
                    }
                    else if (filename.Contains("samplereport24.rpt"))
                    {
                        if (!this.ExistSampleReportFile(DES))
                        {
                            string newfilenameC = "samplereport24" + DateTime.Now.ToString("_yyyy_MM_ddTHH_mm_ss") + ".rpt";
                            File.Copy(vFile, DES + "!" + newfilenameC, true);

                            this.Record(newfilenameC);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
 public static void DoSystemEventRecord(Device device, string systemEvent, RecordType recordType = RecordType.Event, bool flush = false)
 {
     RecordManager.WriteDataToLog(device, systemEvent, recordType, flush);
 }
Ejemplo n.º 13
0
        private bool Mode24(string[] data)
        {
            //RecordManager.DoSystemEventRecord(this, "进入24小时模式", RecordType.Event);

            // 状态 = 00110
            if (data[23] == "0" && data[7] == "0" && data[3] == "1" && data[2] == "1" && data[1] == "0")
            {
                Running_Process = (int)Mode24_Process.Mode24_Process_SampleMeasure;

                RecordManager.DoSystemEventRecord(this, "初始状态/样品测量", RecordType.Event);
                return(true);
            }

            // 状态 = 10110
            if (data[23] == "1" && data[7] == "0" && data[3] == "1" && data[2] == "1" && data[1] == "0")
            {
                // 判断是否原有状态之一,避免状态重复出现
                if (Running_Process == (int)Mode24_Process.Mode24_Process_ChangeStart ||
                    Running_Process == (int)Mode24_Process.Mode24_Process_Cutting ||
                    Running_Process == (int)Mode24_Process.Mode24_Process_LeadClose)
                {
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_SampleMeasure)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_ChangeStart;

                    RecordManager.DoSystemEventRecord(this, "机械臂开始移动", RecordType.Event);
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_MovingPlate)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_Cutting;

                    RecordManager.DoSystemEventRecord(this, "滤纸夹就位,开始切割", RecordType.Event);
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_MovingLead_AfterQAFinish)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_LeadClose;

                    RecordManager.DoSystemEventRecord(this, "铅室盖完全关闭,准备开始样品测量", RecordType.Event);

                    // to do sample measurement
                    ExecSample24HourMeasure();

                    return(true);
                }

                else
                {
                    RecordManager.DoSystemEventRecord(this, "未知状态,状态号10110", RecordType.Event);
                    return(false);
                }
            }

            // 状态 = 10010
            if (data[23] == "1" && data[7] == "0" && data[3] == "0" && data[2] == "1" && data[1] == "0")
            {
                // 判断是否原有状态之一,避免状态重复出现
                if (Running_Process == (int)Mode24_Process.Mode24_Process_MovingPlate)
                {
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_ChangeStart)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_MovingPlate;

                    RecordManager.DoSystemEventRecord(this, "开始移动滤纸夹", RecordType.Event);
                    return(true);
                }

                else
                {
                    RecordManager.DoSystemEventRecord(this, "未知状态,状态号10010", RecordType.Event);
                    return(false);
                }
            }

            // 状态 = 10100
            if (data[23] == "1" && data[7] == "0" && data[3] == "1" && data[2] == "0" && data[1] == "0")
            {
                // 判断是否原有状态之一,避免状态重复出现
                if (Running_Process == (int)Mode24_Process.Mode24_Process_MovingLead_AfterCutting ||
                    Running_Process == (int)Mode24_Process.Mode24_Process_MovingLead_AfterQAFinish)
                {
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_Cutting)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_MovingLead_AfterCutting;

                    RecordManager.DoSystemEventRecord(this, "切割完毕,打开铅室盖中", RecordType.Event);
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_QAFinish)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_MovingLead_AfterQAFinish;

                    RecordManager.DoSystemEventRecord(this, "QA测量结束,关闭铅室盖中", RecordType.Event);
                    return(true);
                }

                else
                {
                    RecordManager.DoSystemEventRecord(this, "未知状态,状态号10100", RecordType.Event);
                    return(false);
                }
            }

            // 状态 = 10101
            if (data[23] == "1" && data[7] == "0" && data[3] == "1" && data[2] == "0" && data[1] == "1")
            {
                // 判断是否原有状态之一,避免状态重复出现
                if (Running_Process == (int)Mode24_Process.Mode24_Process_LeadOpen_AfterCutting ||
                    Running_Process == (int)Mode24_Process.Mode24_Process_QAFinish)
                {
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_MovingLead_AfterCutting)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_LeadOpen_AfterCutting;

                    RecordManager.DoSystemEventRecord(this, "切割结束,铅室盖打开完毕", RecordType.Event);
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_StartQA)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_QAFinish;

                    RecordManager.DoSystemEventRecord(this, "QA测量结束", RecordType.Event);
                    return(true);
                }

                else
                {
                    RecordManager.DoSystemEventRecord(this, "未知状态,状态号10101", RecordType.Event);
                    return(false);
                }
            }

            // 状态 = 11101
            if (data[23] == "1" && data[7] == "1" && data[3] == "1" && data[2] == "0" && data[1] == "1")
            {
                // 判断是否原有状态之一,避免状态重复出现
                if (Running_Process == (int)Mode24_Process.Mode24_Process_StartQA)
                {
                    return(true);
                }

                if (Running_Process == (int)Mode24_Process.Mode24_Process_LeadOpen_AfterCutting)
                {
                    Running_Process = (int)Mode24_Process.Mode24_Process_StartQA;

                    RecordManager.DoSystemEventRecord(this, "开始QA测量", RecordType.Event);

                    // to do QA Measurement
                    ExecQAMeasure();
                    return(true);
                }

                else
                {
                    RecordManager.DoSystemEventRecord(this, "未知状态,状态号11101", RecordType.Event);
                    return(false);
                }
            }

            else
            {
                RecordManager.DoSystemEventRecord(this, "未知状态,24小时模式", RecordType.Event);
                return(false);
            }
        }
Ejemplo n.º 14
0
 private bool Mode1(string[] data)
 {
     RecordManager.DoSystemEventRecord(this, "进入1小时模式", RecordType.Event);
     return(true);
 }
Ejemplo n.º 15
0
        public void Write()
        {
            if (this.serialPort == null || !this.IsOpen)
            {
                return;
            }

            try
            {
                // 每次重启时,重置探测器
                if (!this.initStatus)
                {
                    if (this.IsRealDevice)
                    {
                        this.serialPort.Write(this.actionSend2, 0, this.actionSend2.Length);
                        this.initStatus = true;

                        RecordManager.DoSystemEventRecord(this, "Reset weather station - Initial", RecordType.Event);
                    }
                    return;
                }

                // 归一化时间
                DateTime rightTime = default(DateTime);
                if (!this.recordTimePolicy.NowAtRightTime(out rightTime) ||
                    this.currentRecordTime == rightTime)
                {
                    return;
                }
                this.currentRecordTime = rightTime;

                // 记录当前值
                if (this.IsRealDevice)
                {
                    this.serialPort.Write(this.actionSend1, 0, this.actionSend1.Length);
                }

                // 23:59:30时重置气象探测器
                if (this.currentRecordTime.ToString("HH:mm:ss").Equals("23:59:30"))
                {
                    // 等待2s,再发送重置命令
                    Thread.Sleep(2000);

                    if (this.IsRealDevice)
                    {
                        this.serialPort.Write(this.actionSend2, 0, this.actionSend2.Length);
                    }
                }

                #region Virtual-Device
                else
                {
                    this.OnSendDataToVirtualDevice(this.actionSend1);
                }
                #endregion
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(this, "Write COM Data Error: " + e.Message, RecordType.Error);
            }
        }
Ejemplo n.º 16
0
        //////////////////////////////////////////////////////////////////////

        private byte[] ReadData()
        {
            // 真实设备
            if (this.IsRealDevice)
            {
                // important, sleep 400ms to wait all the data come to system buffer, Kaikai
                Thread.Sleep(this.bufferSleep);

                int n = this.serialPort.BytesToRead;
                if (n == 0)
                {
                    return(null);
                }
                else
                {
                    byte[] buffer = new byte[n];
                    int    r      = this.serialPort.Read(buffer, 0, n);
                    if (r != n)
                    {
                        RecordManager.DoSystemEventRecord(this, "SerialPort Read Error");

                        return(null);
                    }

                    return(buffer);
                }
            }
            else             // Virtual Device~!
            {
                if (this.actionInterval > 1)
                {
                    // 假设: 应答式的数据,都是完整的帧.
                    return(this.GetExampleLine());
                }
                else
                {
                    if (this.actionSendInHex)
                    {
                        return(this.GetExampleLine());
                    }
                    // 不完整帧模拟
                    byte[] bytes = this.GetExampleLine();
                    int    len   = bytes.Length;
                    foreach (byte b in bytes)
                    {
                        exampleBuffer.Add(b);
                    }

                    int    c     = new Random().Next(len - 5, len + 5);
                    int    count = Math.Min(c, len);
                    byte[] ret   = new byte[count];

                    for (int i = 0; i < count; ++i)
                    {
                        ret[i] = exampleBuffer[i];
                    }
                    exampleBuffer.RemoveRange(0, count);

                    return(ret);
                }
            }
        }
Ejemplo n.º 17
0
 private void Reconnect()
 {
     RecordManager.DoSystemEventRecord(Device.Main, "Reconnecting to MySQL DB", RecordType.Notice);
     this.Connect();
 }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="o"></param>
        private void TimerCallback(object o)
        {
            // The temp file name is fixed.
            DateTime now      = DateTime.Now;
            string   tempFile = this.DeviceConfigPath + "\\temp_download_file.xml";
            string   filePath = string.Empty;

            if (this.IsVirtual)
            {
                filePath = this.DeviceConfigPath + "/sara0231_2012-09-01T03_50_00Z-5min.n42";

                File.Copy(filePath, tempFile, true);
            }
            else
            {
                // Start download ...
                string fileName1 = GetFileNameOnDevice(now);
                // 判断NaI谱文件是否已经成功下载
                if (fileName1 == LastDownLoadFileName)
                {
                    return;
                }

                string fileName2 = GetFileName(now);
                string datePath  = LogPath.GetDeviceLogFilePath(this.Id, now) + "\\" + now.Day.ToString();
                this.DoFolderPolicy(datePath);

                if (!Directory.Exists(datePath))
                {
                    Directory.CreateDirectory(datePath);
                }
                filePath = datePath + "\\" + fileName2;
                if (File.Exists(filePath))
                {
                    return;
                }

                // Download the file.
                string address = this.addr + fileName1;

                using (WebClient client = new WebClient())
                {
                    try
                    {
                        client.Credentials = new NetworkCredential("root", "root");
                        // DO NOT USE the FOLLOWING LINE
                        // client.UseDefaultCredentials = true;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        client.DownloadFile(address, tempFile);
                    }
                    catch (Exception e)
                    {
                        RecordManager.DoSystemEventRecord(this, string.Format("{0} Try to download {1}: Failed.", now, address));
                        RecordManager.DoSystemEventRecord(this, e.Message);

                        return;
                    }
                }

                // 下载成功之后记录,防止多次下载
                LastDownLoadFileName = fileName1;
            }

            Thread.Sleep(1000);
            if (File.Exists(tempFile))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempFile);

                    // XmlElement root = doc.DocumentElement;
                    var nsmgr = new XmlNamespaceManager(doc.NameTable);
                    nsmgr.AddNamespace("a", "http://physics.nist.gov/Divisions/Div846/Gp4/ANSIN4242/2005/ANSIN4242");
                    nsmgr.AddNamespace("s", "http://www.technidata.com/ENVINET/SARA");
                    nsmgr.AddNamespace("e", "http://www.technidata.com/ENVINET");

                    NuclideDataSet set = this.ParseData(doc, nsmgr);
                    this.Record(set, now);

                    File.Move(tempFile, filePath);
                }
                catch (IOException e)
                {
                    RecordManager.DoSystemEventRecord(this, e.Message);
                }
                catch (Exception e)
                {
                    RecordManager.DoSystemEventRecord(this, e.Message);
                }
                finally
                {
                    // TODO: Gzip the file, put it into the Date-folder, then delete this xml file.
                }
            }
        }
Ejemplo n.º 19
0
        private bool SearchBitStatus(string[] data)
        {
            // 触发后玻璃门开
            if (data[22] == "0" && Status_BackPlexDoor == false)
            {
                Status_BackPlexDoor = true;
                RecordManager.DoSystemEventRecord(this, "后侧玻璃门打开", RecordType.Event);
            }
            //触发后玻璃门关
            if (data[22] == "1" && Status_BackPlexDoor == true)
            {
                Status_BackPlexDoor = false;
                RecordManager.DoSystemEventRecord(this, "后侧玻璃门关闭", RecordType.Event);
            }

            //触发流量低报警
            if (data[21] == "1" && Status_Flow == false)
            {
                Status_Flow = true;
                RecordManager.DoSystemEventRecord(this, "流量低", RecordType.Event);
            }
            if (data[21] == "0" && Status_Flow == true)
            {
                Status_Flow = false;
                RecordManager.DoSystemEventRecord(this, "流量正常", RecordType.Event);
            }

            //新滤纸夹舱空报警
            if (data[19] == "1" && Status_NewCatridge == false)
            {
                Status_NewCatridge = true;
                RecordManager.DoSystemEventRecord(this, "新滤纸夹舱空", RecordType.Event);
            }
            if (data[19] == "0" && Status_NewCatridge == true)
            {
                Status_NewCatridge = false;
                RecordManager.DoSystemEventRecord(this, "新滤纸夹舱正常", RecordType.Event);
            }

            //切割位置未找到滤纸夹具
            if (data[18] == "1" && Status_CuttingPosition == false)
            {
                Status_CuttingPosition = true;
                RecordManager.DoSystemEventRecord(this, "切割位置未找到滤纸夹具", RecordType.Event);
            }
            if (data[18] == "0" && Status_CuttingPosition == true)
            {
                Status_CuttingPosition = false;
                RecordManager.DoSystemEventRecord(this, "切割位置正常", RecordType.Event);
            }

            //旧滤纸夹舱满报警
            if (data[17] == "1" && Status_OldCatridge == false)
            {
                Status_OldCatridge = true;
                RecordManager.DoSystemEventRecord(this, "旧滤纸夹舱满报警", RecordType.Event);
            }
            if (data[17] == "0" && Status_OldCatridge == true)
            {
                Status_OldCatridge = false;
                RecordManager.DoSystemEventRecord(this, "旧滤纸夹舱正常", RecordType.Event);
            }

            //滤纸方向放反了
            if (data[10] == "1" && Status_CatridgeDirection == false)
            {
                Status_CatridgeDirection = true;
                RecordManager.DoSystemEventRecord(this, "滤纸夹方向错误", RecordType.Event);
            }
            if (data[10] == "0" && Status_CatridgeDirection == true)
            {
                Status_CatridgeDirection = false;
                RecordManager.DoSystemEventRecord(this, "滤纸夹方向正常", RecordType.Event);
            }

            //抽屉空了
            if (data[9] == "0" && Status_BeakerHolder == false)
            {
                Status_BeakerHolder = true;
                RecordManager.DoSystemEventRecord(this, "抽屉被抽出", RecordType.Event);
            }
            if (data[9] == "1" && Status_BeakerHolder == true)
            {
                Status_BeakerHolder = false;
                RecordManager.DoSystemEventRecord(this, "抽屉正常", RecordType.Event);
            }

            //前玻璃门打开
            if (data[8] == "0" && Status_FrontPlexDoor == false)
            {
                Status_FrontPlexDoor = true;
                RecordManager.DoSystemEventRecord(this, "前侧玻璃门打开", RecordType.Event);
            }
            if (data[8] == "1" && Status_FrontPlexDoor == true)
            {
                Status_FrontPlexDoor = false;
                RecordManager.DoSystemEventRecord(this, "前侧玻璃门关闭", RecordType.Event);
            }

            //新滤纸盒空了
            if (data[6] == "1" && Status_Beaker == false)
            {
                Status_Beaker = true;
                RecordManager.DoSystemEventRecord(this, "新滤纸盒位置空", RecordType.Event);
            }
            if (data[6] == "0" && Status_Beaker == true)
            {
                Status_Beaker = false;
                RecordManager.DoSystemEventRecord(this, "新滤纸盒位置正常", RecordType.Event);
            }

            //旧滤纸夹具舱门打开
            if (data[5] == "0" && Status_OldCatridgeDoor == false)
            {
                Status_OldCatridgeDoor = true;
                RecordManager.DoSystemEventRecord(this, "旧滤纸夹具舱门打开", RecordType.Event);
            }
            if (data[5] == "1" && Status_OldCatridgeDoor == true)
            {
                Status_OldCatridgeDoor = false;
                RecordManager.DoSystemEventRecord(this, "旧滤纸夹具舱门关闭", RecordType.Event);
            }

            //新滤纸夹具舱门打开
            if (data[4] == "0" && Status_NewCatridgeDoor == false)
            {
                Status_NewCatridgeDoor = true;
                RecordManager.DoSystemEventRecord(this, "新滤纸夹具舱门打开", RecordType.Event);
            }
            if (data[4] == "1" && Status_NewCatridgeDoor == true)
            {
                Status_NewCatridgeDoor = false;
                RecordManager.DoSystemEventRecord(this, "新滤纸夹具舱门关闭", RecordType.Event);
            }

            //应急报警
            if (data[0] == "1" && Status_Emergency == false)
            {
                Status_Emergency = true;
                RecordManager.DoSystemEventRecord(this, "紧急开关报警", RecordType.Event);
            }
            if (data[0] == "0" && Status_Emergency == true)
            {
                Status_Emergency = false;
                RecordManager.DoSystemEventRecord(this, "紧急开关正常", RecordType.Event);
            }

            return(true);
        }