예제 #1
0
        private void confirmReConnect()
        {
            while (ComfirmMsgErr(COMFIRM_ERR_CONNECT_DEVICE))
            {
                Task.Delay(1000);

                try
                {
                    if (telnetDSF != null)
                    {
                        telnetDSF.Disconnect();
                        telnetDSF = new TelnetInterfaceDsf();
                    }
                    telnetDSF.OnDataReceived += new ClientHandlePacketData(client_OnDataReceived);
                    telnetDSF.ProcessErrors  += client_ProcessErrors;
                    if (telnetDSF.ConnectToServer(Device.IpAddress, Device.Port))
                    {
                        telnetDSF.Start();
                        if (MeasureType == emMeasureType.WalkingTest)
                        {
                            timerWalkingTest.Start();
                        }
                        return;
                    }
                }
                catch
                {
                }
            }

            MeasureEnd(null, null);
        }
예제 #2
0
        private void Disconnect()
        {
            try
            {
                if (telnetDSF == null)
                {
                    return;
                }
                telnetDSF.Disconnect();
                telnetDSF = null;

                if (thread != null)
                {
                    thread.Abort();
                }
                thread = null;
            }
            catch (Exception)
            {
            }
        }
예제 #3
0
        /// <summary>
        /// Measures the start.
        /// </summary>
        public void MeasureStart()
        {
            if (!validate())
            {
                MainForm.BeginInvoke((Action)(() =>
                {
                    if (MeasureType == emMeasureType.AlarmTest)
                    {
                        MainForm.DeviceCallBack(this);
                    }
                    else if (MeasureType == emMeasureType.WalkingTest)
                    {
                        MainForm.ResetWalkingTestMode(false);
                    }
                }));

                return;
            }

            GraphTitle    = MainForm.GetAlarmTestTextValue() + "_" + Device.DeviceName + " : ";
            telnetDSF     = new TelnetInterfaceDsf();
            measureResult = (int)emMeasureResult.Normal;

            if (MeasureType == emMeasureType.WalkingTest)
            {
                measureResult = (int)emMeasureResult.Pass;
                GraphTitle    = MainForm.GetWalkingTestTextValue() + "_" + Device.DeviceName + " : ";
            }

            try
            {
                if (telnetDSF.ConnectToServer(Device.IpAddress, Device.Port))
                {
                    Device.MeasureType = this.MeasureType;

                    telnetDSF.OnDataReceived += new ClientHandlePacketData(client_OnDataReceived);
                    telnetDSF.ProcessErrors  += new ClientHandleWhenHasErrors(client_ProcessErrors);

                    lstMaxValue.Clear();
                    dtsCurrent = new DataSample()
                    {
                        isFrist = true
                    };
                    message              = string.Empty;
                    isMeasureUp          = true;
                    maxKey               = 0;
                    beforeActualDelegate = 0;
                    MainForm.BeginInvoke((Action)(() =>
                    {
                        MainForm.ResetMeasure();
                    }));

                    MainForm.BeginInvoke((Action)(() =>
                    {
                        MainForm.ModeMeasure(Device.DeviceId, true);
                    }));

                    MainForm.BeginInvoke((Action)(() =>
                    {
                        StartDate = DateTime.Now.ToString(cstrDateTimeFomatShow);
                        MainForm.GraphInit(GraphTitle + " " + StartDate, MeasureType,
                                           MeasureType == emMeasureType.WalkingTest ? Device.FailLevel : Device.AlarmValue);
                    }));

                    Response resStart = MainForm.iSetting.MeasureStart(Device, measureResult);
                    _pathFolderData = resStart.PathFolderData;
                    _measureId      = resStart.MeasureId;

                    Device.MeasureId      = _measureId;
                    Device.PathFolderData = _pathFolderData;

                    threadInsert = new Thread(new ThreadStart(CallProcessData));
                    threadInsert.Start();

                    telnetDSF.Start();

                    if (MeasureType == emMeasureType.WalkingTest)
                    {
                        timerWalkingTest.Interval = Math.Abs(Device.Period * 1000);
                        timerWalkingTest.Start();
                    }

                    IsRunning = true;
                }
                else
                {
                    telnetDSF = null;
                    ShowMsg(MessageBoxIcon.Error, string.Format(MSG_ERR_CONNECT, Device.DeviceName));
                }
            }
            catch (Exception e)
            {
                isThreadInsertRunning = false;
                if (threadInsert != null)
                {
                    threadInsert.Abort();
                }
                threadInsert = null;
                telnetDSF    = null;
                ShowMsg(MessageBoxIcon.Error, string.Format(MSG_ERR_CONNECT, Device.DeviceName));
                throw e;
            }
            finally
            {
                MainForm.BeginInvoke((Action)(() =>
                {
                    if (MeasureType == emMeasureType.AlarmTest)
                    {
                        MainForm.DeviceCallBack(this);
                    }
                    else
                    {
                        MainForm.ResetWalkingTestMode(true);
                    }
                }));
            }
        }