Esempio n. 1
0
        /// <summary>
        ///     Send usage data specified mail address
        /// </summary>
        public static void SendUsageData()
        {
            if (DataSender == null)
            {
                throw new InvalidOperationException("DataSender must be set before sending data");
            }

            lock (OperationLock)
            {
                DataSender.SendData(CurrentData.ToString(SaveOptions.DisableFormatting));
            }
        }
Esempio n. 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            long CurrentFileLength;

            using (BinaryReader dataFile = new BinaryReader(File.Open(BinPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                CurrentFileLength = dataFile.BaseStream.Length;
            }

            #region Zero Signals
            if (!ZeroSignalDisplayed && SysInfo.NeedCalculateZero && GIBgotov && (CurrentFileLength - StartPosForZeroSignal > SysInfo.ZeroSignalCount))
            {
                ZeroSignalDisplayed = true;

                Thread thread = new Thread(ZeroSignalDisplay_Thread); //Создаем новый объект потока (Thread)
                thread.Start();                                       //запускаем поток
            }
            #endregion

            if (CurrentFileLength < SysInfo.CountOfPack * SysInfo.WordsInPack * 2)
            {
                return;
            }

            ushort tempZPR;
            int    k;

            #region Binary Reader
            using (BinaryReader dataFile = new BinaryReader(File.Open(BinPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                dataFile.BaseStream.Position = CurrentFileLength - 2;

                while (dataFile.ReadUInt16() != 0x5555)
                {
                    dataFile.BaseStream.Position -= 4;
                }

                if (SysInfo.OtherWords != 0)
                {
                    if (!GIBgotov)
                    {
                        StartPosForZeroSignal = dataFile.BaseStream.Position;
                    }

                    dataFile.BaseStream.Position -= SysInfo.WordsInPack * 2;

                    k = 0;

                    if (SysInfo.YCXuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.YCYuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.YCZuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.PXuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.PYuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.PZuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }
                    if (SysInfo.VRKuse)
                    {
                        LastData_OtherWords[k++] = dataFile.ReadUInt16();
                    }

                    while (dataFile.ReadUInt16() != 0x5555)
                    {
                    }
                }

                dataFile.BaseStream.Position -= 4;
                tempZPR = dataFile.ReadUInt16();
                dataFile.BaseStream.Position += 2;

                if (SysInfo.TempWords != 0)
                {
                    dataFile.BaseStream.Position -= SysInfo.CountOfPack * SysInfo.WordsInPack * 2;

                    for (int i = 0; i < LastData_TempWords.Length; i++)
                    {
                        dataFile.BaseStream.Position += SysInfo.OtherWords * 2;
                        LastData_TempWords[i]         = dataFile.ReadUInt16();
                        while (dataFile.ReadUInt16() != 0x5555)
                        {
                        }
                    }
                }
            }
            #endregion


            k = 0;
            int CurrentData;

            #region YC
            if (SysInfo.YCXuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00);      //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF;    //если положительное значение -> как есть
                }
                YCXtext.Text = CurrentData.ToString();    //УСХ

                if (SysInfo.RKVuse)
                {
                    if ((Math.Abs(CurrentData) <= SysInfo.ScaleM1) && Scale_YCX_M2)
                    {
                        Scale_YCX_M2      = false;
                        YCXtext.BackColor = Color.GreenYellow; //масштаб УСХ
                        Scale_changed     = true;
                    }
                    else if ((Math.Abs(CurrentData) >= SysInfo.ScaleM2) && !Scale_YCX_M2)
                    {
                        Scale_YCX_M2      = true;
                        YCXtext.BackColor = Color.OrangeRed; //масштаб УСХ
                        Scale_changed     = true;
                    }
                }
            }
            if (SysInfo.YCYuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00);      //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF;    //если положительное значение -> как есть
                }
                YCYtext.Text = CurrentData.ToString();    //УСY

                if (SysInfo.RKVuse)
                {
                    if ((Math.Abs(CurrentData) <= SysInfo.ScaleM1) && Scale_YCY_M2)
                    {
                        Scale_YCY_M2      = false;
                        YCYtext.BackColor = Color.GreenYellow; //масштаб УСY
                        Scale_changed     = true;
                    }
                    else if ((Math.Abs(CurrentData) >= SysInfo.ScaleM2) && !Scale_YCY_M2)
                    {
                        Scale_YCY_M2      = true;
                        YCYtext.BackColor = Color.OrangeRed; //масштаб УСY
                        Scale_changed     = true;
                    }
                }
            }
            if (SysInfo.YCZuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00); //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF; //если положительное значение -> как есть
                }
                YCZtext.Text = CurrentData.ToString(); //УСZ

                if (SysInfo.RKVuse)
                {
                    if ((Math.Abs(CurrentData) <= SysInfo.ScaleM1) && Scale_YCZ_M2)
                    {
                        Scale_YCZ_M2      = false;
                        YCZtext.BackColor = Color.GreenYellow; //масштаб УСZ
                        Scale_changed     = true;
                    }
                    else if ((Math.Abs(CurrentData) >= SysInfo.ScaleM2) && !Scale_YCZ_M2)
                    {
                        Scale_YCZ_M2      = true;
                        YCZtext.BackColor = Color.OrangeRed; //масштаб УСZ
                        Scale_changed     = true;
                    }
                }
            }
            #endregion
            #region Scale
            if (SysInfo.RKVuse)
            {
                if (Scale_changed)
                {
                    byte temp = 0x00;

                    temp = Scale_YCX_M2 ? (byte)(temp | 0x01) : (byte)(temp & 0xFE);
                    temp = Scale_YCY_M2 ? (byte)(temp | 0x02) : (byte)(temp & 0xFD);
                    temp = Scale_YCZ_M2 ? (byte)(temp | 0x04) : (byte)(temp & 0xFB);

                    byte[] Command = { 0x4E, SysInfo.RKVadrByte[0], SysInfo.RKVadrByte[1], temp, 0xFF };
                    RS422_Port.Write(Command, 0, Command.Length);

                    Scale_changed = false;
                }
            }
            #endregion
            #region P
            if (SysInfo.PXuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00);      //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF;    //если положительное значение -> как есть
                }
                PXtext.Text = CurrentData.ToString();     //PХ
            }
            if (SysInfo.PYuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00);      //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF;    //если положительное значение -> как есть
                }
                PYtext.Text = CurrentData.ToString();     //PХ
            }
            if (SysInfo.PZuse)
            {
                CurrentData = LastData_OtherWords[k++];
                if ((CurrentData & 0x200) == 0x200)
                {
                    CurrentData = (int)((CurrentData & 0x1FF) | 0xFFFFFE00);      //если отрицательное значение -> в доп.код
                }
                else
                {
                    CurrentData = CurrentData & 0x1FF;    //если положительное значение -> как есть
                }
                PZtext.Text = CurrentData.ToString();     //PХ
            }
            #endregion
            #region Status
            if (SysInfo.VRKuse)
            {
                bool LastStatus = Statustext.Enabled;

                Statustext.Enabled = (LastData_OtherWords[k++] & 0x0001) != 0;    //гиб готов

                if (!GIBgotov && Statustext.Enabled)
                {
                    GIBgotov = true;
                    SysInfo.CountOfPackagesForZeroSignal = 100000000 / tempZPR;
                    SysInfo.ZeroSignalCount = SysInfo.WordsInPack * 2 * SysInfo.CountOfPackagesForZeroSignal;
                }

                if (LastStatus != Statustext.Enabled)
                {
                    if (SysInfo.K1use)
                    {
                        K1_button.Enabled = Statustext.Enabled;
                    }
                    if (SysInfo.K2use)
                    {
                        K2_button.Enabled = Statustext.Enabled;
                    }
                    if (SysInfo.ResetKuse)
                    {
                        ResetK_button.Enabled = Statustext.Enabled;
                    }
                }
            }
            #endregion
            #region Temperature
            if (SysInfo.TempWords != 0)
            {
                foreach (int temper in LastData_TempWords)
                {
                    CurrentData = temper;
                    int prizn_temp = CurrentData & 0x7;

                    double temperature = ((CurrentData >> 7) & 0x1FF) * SysInfo.TempKoef - 60;

                    if (prizn_temp == SysInfo.TYCXprizn)
                    {
                        TYCXtext.Text = temperature.ToString("F1");
                    }
                    else if (prizn_temp == SysInfo.TYCYZprizn)
                    {
                        TYCYZtext.Text = temperature.ToString("F1");
                    }
                    else if (prizn_temp == SysInfo.TPXprizn)
                    {
                        TPXtext.Text = temperature.ToString("F1");
                    }
                    else if (prizn_temp == SysInfo.TPYprizn)
                    {
                        TPYtext.Text = temperature.ToString("F1");
                    }
                    else if (prizn_temp == SysInfo.TPZprizn)
                    {
                        TPZtext.Text = temperature.ToString("F1");
                    }
                    else if (prizn_temp == SysInfo.TGIBprizn)
                    {
                        TGIBtext.Text = temperature.ToString("F1");
                    }
                }
            }
            #endregion
            #region tzpr
            ZPRtext.Text = ((double)tempZPR / 10).ToString("F1");
            #endregion
        }