예제 #1
0
        private void DoWork()
        {
            StreamWriter writer = null;

            string result = appSettings["Comport"];

            if (string.IsNullOrEmpty(result))
            {
                var frm = new Settings();
                frm.ShowDialog();
                result = appSettings["Comport"];
            }

            TimeSpan ts = new TimeSpan(0, 0, 0, LogInterval / 1000, LogInterval % 1000);


            toWriteTime = DateTime.Now;
            if (!string.IsNullOrEmpty(LogFilename))
            {
                writer = new StreamWriter(LogFilename);
            }

            var vcLib = new Vici8145();

            try
            {
                vcLib.Openport(result);
                DisplayData b = new DisplayData();
                while (true)
                {
                    b = vcLib.GetData(b, RespondingCommands.AnalogeBarValue);
                    if (!DisplData(b, writer, ts))
                    {
                        return;
                    }

                    b = vcLib.GetData(b, RespondingCommands.MainDisplayValue);
                    if (!DisplData(b, writer, ts))
                    {
                        return;
                    }

                    b = vcLib.GetData(b, RespondingCommands.AnalogeBarValue);

                    if (!DisplData(b, writer, ts))
                    {
                        return;
                    }

                    b = vcLib.GetData(b, RespondingCommands.SecondDisplayValue);
                    if (!DisplData(b, writer, ts))
                    {
                        return;
                    }

                    b = vcLib.GetData(b, RespondingCommands.AnalogeBarValue);
                    if (!DisplData(b, writer, ts))
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                writer?.Close();

                if (!ex.Message.Contains("abort"))
                {
                    ErrorMesg mesg = new ErrorMesg {
                        Mesg = ex.Message
                    };
                    mesg.ShowDialog();
                }
            }
        }