/// <summary>
 /// Установка значений в поля размер считывания и начальный адрес
 /// </summary>
 private void SetValues()
 {
     if (_HexAddressCoding)
     {
         if (this._Address == 0)
         {
             this.tbStartAddress.Text = "0x00";
         }
         else
         {
             this.tbStartAddress.Text = "0x" + AppliedMath.DecToHex(this._Address);
         }
     }
     else
     {
         this.tbStartAddress.Text = "" + this._Address;
     }
     if (_HexSizeCoding)
     {
         this.tbReadingSize.Text = "0x" + AppliedMath.DecToHex(this._Size);
     }
     else
     {
         this.tbReadingSize.Text = "" + this._Size;
     }
 }
示例#2
0
 /// <summary>
 /// Выполняет инициализацию полей класса
 /// </summary>
 /// <param name="ModuleNumber">Физический номер модуля</param>
 protected void Init(int ModuleNumber)
 {
     this.ModuleNumber = ModuleNumber;
     this.GenerateVarsNames(this.ModuleNumber);
     this.Req10msDefinition = "0x" + Utils.AddChars('0', AppliedMath.DecToHex(this.ModuleNumber), 4);
     foreach (ModuleVarDescription VarDescription in this.VarNames)
     {
         this.Req10msDefinition += ", (unsigned int)&" + VarDescription.DisplayName;
     }
     this.Req10msDefinition += ", (unsigned int)&E" + this.VarNames[0].DisplayName;
 }
示例#3
0
 /// <summary>
 /// Формирование адреса для отображения
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 private string BuildDisplayAddress(int address)
 {
     return(("0x00000000".Insert("0x00000000".Length - ("" + AppliedMath.DecToHex(address)).Length, "" + AppliedMath.DecToHex(address))).Substring(0, 10));
 }
示例#4
0
        /// <summary>
        /// Событтие при двойном щелчке по дереву не прочитаннх переменных
        /// (формировани запроса на их чтение)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvVars_NodeMouseDoubleClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
        {
            if ((e.Node.Nodes.Count == 0) && ((e.Node.Text.CompareTo("Системные переменные") != 0) && (e.Node.Text.CompareTo("Пользовательские переменные") != 0) && (e.Node.Text.CompareTo("Заводские установки") != 0)))
            {
                Kontel.Relkon.Classes.ControllerVar m_newVar = _solution.Vars.GetVarByName(e.Node.Text);
                if (m_newVar == null)
                {
                    return;
                }

                if (!_vars.ContainsKey(e.Node.Text))
                {
                    _vars.Add(e.Node.Text, m_newVar);

                    //Добавление записи с читаемой переменной


                    Int64 m_Max = 0;
                    Int64 m_Min = 0;
                    if (m_newVar.HasSign)
                    {
                        switch (m_newVar.Size)
                        {
                        case 1: m_Max = sbyte.MaxValue; m_Min = sbyte.MinValue; break;

                        case 2: m_Max = Int16.MaxValue; m_Min = Int16.MinValue; break;

                        case 4: m_Max = Int32.MaxValue; m_Min = Int32.MinValue; break;

                        default: m_Max = sbyte.MaxValue; m_Min = sbyte.MinValue; break;
                        }
                    }
                    else
                    {
                        switch (m_newVar.Size)
                        {
                        case 1: m_Max = Byte.MaxValue; m_Min = Byte.MinValue; break;

                        case 2: m_Max = UInt16.MaxValue; m_Min = UInt16.MinValue; break;

                        case 4: m_Max = UInt32.MaxValue; m_Min = UInt32.MinValue; break;

                        default: m_Max = Byte.MaxValue; m_Min = Byte.MinValue; break;
                        }
                    }

                    DataRow m_row = this.Table.NewRow();
                    m_row[0] = m_newVar.Name;
                    m_row[2] = m_Max;
                    m_row[3] = m_Min;
                    m_row[4] = m_newVar.Size;
                    m_row[5] = m_newVar.Address;
                    m_row[6] = m_newVar.Memory;
                    m_row[7] = ("0x00000000".Insert("0x00000000".Length - ("" + AppliedMath.DecToHex(m_newVar.Address)).Length, "" + AppliedMath.DecToHex(m_newVar.Address))).Substring(0, 10);
                    m_row[8] = new byte[m_newVar.Size];
                    m_row[9] = m_newVar.Real;
                    this.BuildDisplayValue(m_row);

                    this.Table.Rows.Add(m_row);
                    //Запоминаем что читаем эту переменную в параметры отладчика
                    Kontel.Relkon.DebuggerParameters.VarDescription m_VarDescription = new Kontel.Relkon.DebuggerParameters.VarDescription();
                    m_VarDescription.Address    = m_newVar.Address;
                    m_VarDescription.MemoryType = m_newVar.Memory;
                    m_VarDescription.Name       = m_newVar.Name;
                    m_VarDescription.Size       = m_newVar.Size;
                    m_VarDescription.Real       = m_newVar.Real;
                    m_VarDescription.Type       = e.Node.Parent.Index;
                    _engine.Parameters.ReadingVars.Add(m_VarDescription);
                    //Добавление переменной на опрос
                    if (this._IsReading)
                    {
                        for (int i = 0; i < this.Table.Rows.Count; i++)
                        {
                            if (this.Table.Rows[i][0].ToString() == m_newVar.Name)
                            {
                                try { _engine.AddReadItem(m_newVar.Address, m_newVar.Memory, m_newVar.Size, this.Table.Rows[i], null, CallBack); }
                                catch { }
                            }
                        }
                    }
                }
                this.tvVars.Nodes.Remove(e.Node);
            }
        }
示例#5
0
        /// <summary>
        /// Генерирует h-файл с определениями модулей
        /// </summary>
        private string GenerateModulesHeader()
        {
            int count = 0;


            int[] groupesReqTime = new int[8];

            List <IOModule>[] groupes = new List <IOModule> [8];

            List <IOModule> Req1msMod   = new List <IOModule>();
            List <IOModule> Req5msMod   = new List <IOModule>();
            List <IOModule> Req10msMod  = new List <IOModule>();
            List <IOModule> Req100msMod = new List <IOModule>();

            for (int i = 0; i < 8; i++)
            {
                groupes[i] = new List <IOModule>();
            }


            foreach (IOModule mod in this.codeModel.IOModules.Values)
            {
                switch (mod.Period)
                {
                case 1:
                    Req1msMod.Add(mod);
                    break;

                case 5:
                    Req5msMod.Add(mod);
                    break;

                case 10:
                    Req10msMod.Add(mod);
                    break;

                case 100:
                    Req100msMod.Add(mod);
                    break;
                }
            }

            foreach (IOModule mod in Req1msMod)
            {
                for (int i = 0; i < groupes.Length; i++)
                {
                    groupes[i].Add(mod);
                }
            }

            count = 0;
            foreach (IOModule mod in Req5msMod)
            {
                if (count == 0)
                {
                    for (int i = 0; i < 8; i = i + 2)
                    {
                        groupes[i].Add(mod);
                    }
                }
                else
                {
                    for (int i = 1; i < 8; i = i + 2)
                    {
                        groupes[i].Add(mod);
                    }
                }
                count++;
                if (count == 2)
                {
                    count = 0;
                }
            }

            count = 0;
            foreach (IOModule mod in Req10msMod)
            {
                groupes[count].Add(mod);
                groupes[count + 4].Add(mod);
                count++;
                if (count == 4)
                {
                    count = 0;
                }
            }

            count = 0;
            foreach (IOModule mod in Req100msMod)
            {
                groupes[count].Add(mod);
                count++;
                if (count == 8)
                {
                    count = 0;
                }
            }

            for (int i = 0; i < groupes.Length; i++)
            {
                double totalReqTime = 0.2;
                double totalRepTime = 2;

                foreach (IOModule m in groupes[i])
                {
                    totalReqTime += m.RequestTime;
                    totalRepTime += m.ReplyTime;
                }
                int t1 = totalReqTime > (int)totalReqTime ? ((int)totalReqTime) + 1 : (int)totalReqTime;
                int t2 = totalRepTime > (int)totalRepTime ? ((int)totalRepTime) + 1 : (int)totalRepTime;
                groupesReqTime[i] = t1 + t2;
            }

            int d = MaxValueInArray(groupesReqTime);

            foreach (IOModule mod in Req1msMod)
            {
                mod.RealPeriod = d;
            }

            int[] p = new int[4];

            p[0] = groupesReqTime[0] + groupesReqTime[1];
            p[1] = groupesReqTime[2] + groupesReqTime[3];
            p[2] = groupesReqTime[4] + groupesReqTime[5];
            p[3] = groupesReqTime[6] + groupesReqTime[7];

            d = MaxValueInArray(p);

            foreach (IOModule mod in Req5msMod)
            {
                mod.RealPeriod = d;
            }

            p = new int[2];

            p[0] = groupesReqTime[0] + groupesReqTime[1] + groupesReqTime[2] + groupesReqTime[3];
            p[1] = groupesReqTime[4] + groupesReqTime[5] + groupesReqTime[6] + groupesReqTime[7];

            d = MaxValueInArray(p);

            foreach (IOModule mod in Req10msMod)
            {
                mod.RealPeriod = d;
            }

            d = 0;
            for (int i = 0; i < 8; i++)
            {
                d += groupesReqTime[i];
            }

            foreach (IOModule mod in Req100msMod)
            {
                mod.RealPeriod = d;
            }

            StringBuilder modulesh   = new StringBuilder();
            StringBuilder iodefinesh = new StringBuilder();

            StringBuilder DIODefines = new StringBuilder();
            StringBuilder AIODefines = new StringBuilder();

            foreach (IOModule module in this.codeModel.IOModules.Values)
            {
                if (module is DigitalModule)
                {
                    DIODefines.AppendLine("#define " + module.VarNames[0].DisplayName + " " + module.VarNames[0].SystemName);
                }
                else
                {
                    AnalogModule amodule = (AnalogModule)module;
                    for (int i = 0; i < amodule.VarNames.Length; i++)
                    {
                        AIODefines.AppendLine("#define " + amodule.VarNames[i].DisplayName + " " + amodule.VarNames[i].SystemName);
                        AIODefines.AppendLine("#define " + amodule.SingleByteVarNames[i].DisplayName + " (" + amodule.VarNames[i].SystemName + ">>8)");
                    }
                }
            }

            iodefinesh.AppendLine(DIODefines.ToString());
            iodefinesh.AppendLine(AIODefines.ToString());

            modulesh.AppendLine("const unsigned char mod_table[]={");
            for (int i = 0; i < groupes.Length; i++)
            {
                if (groupes[i].Count != 0)
                {
                    foreach (IOModule mod in groupes[i])
                    {
                        modulesh.Append("0x" + Utils.AddChars('0', AppliedMath.DecToHex(mod.ModuleNumber), 2) + ", ");
                    }
                    modulesh.AppendLine("0x00,");
                }
            }
            modulesh.Append("0x00");
            modulesh.AppendLine("};");

            try
            {
                File.WriteAllText(this.solution.DirectoryName + "\\iodefines.h", iodefinesh.ToString());
            }
            catch (Exception ex)
            {
                this.Errors.Add(new CompilationError(ex.Message, this.codeModel.FileName, -1, false));
            }

            return(modulesh.ToString());
        }
示例#6
0
        public override void GeneratePultCode()
        {
            StringBuilder      code   = new StringBuilder();
            IndentedTextWriter writer = new IndentedTextWriter(new StringWriter(code));

            writer.WriteLine("/***********PultDataCI***************/");
            for (int i = 0; i < this.pultModel.Rows.Count; i++)
            {
                writer.WriteLine("const unsigned char str" + (i + 1).ToString() + "[][" + this.pultModel.Type.SymbolsInRow + "] = {");
                writer.Indent++;
                foreach (View view in this.pultModel.Rows[i].Views)
                {
                    if (!view.Enabled)
                    {
                        continue;
                    }
                    writer.WriteLine("\"" + this.ConvertStringToSTM32F107Format(view) + "\",");
                }

                if (this.pultModel.Rows[i].Views.Count > 0)
                {
                    View view = this.pultModel.Rows[i].Views[this.pultModel.Rows[i].Views.Count - 1];
                    writer.WriteLine("\"" + this.ConvertStringToSTM32F107Format(view) + "\"");
                }
                writer.Indent--;
                writer.WriteLine("};");
            }


            writer.WriteLine("void print_var(void)");
            writer.WriteLine("{");
            writer.Indent++;
            for (int i = 1; i < this.pultModel.Rows.Count + 1; i++)
            {
                writer.WriteLine("switch(_Sys.S" + i + ")");
                writer.WriteLine("{");
                writer.Indent++;
                for (int j = 0; j < this.pultModel.Rows[i - 1].EnabledViews.Count; j++)
                {
                    View view = this.pultModel.Rows[i - 1].EnabledViews[j];
                    if (view.Vars.Count == 0)
                    {
                        continue;
                    }
                    view.Vars.Sort(PultVar.CompareByPosition);
                    writer.WriteLine("case " + j + ":");
                    writer.Indent++;
                    foreach (PultVar v in view.Vars)
                    {
                        int afterDot = Math.Min(3, GetNumberOfDigitsAfterDotInMask(v.Mask));
                        int s        = afterDot == 0 ? v.Mask.Length : v.Mask.Length - 1;
                        s = Math.Min(7, s);
                        RelkonCodeVarDefenition var = solution.GetRelkonCodeVarDefenitionByName(v.Name);
                        if (var != null)
                        {
                            if (v.ReadOnly)
                            {
                                if (var.Type == "float")
                                {
                                    writer.WriteLine("print_float(" + v.Name + ", " + i + ", " + (v.Position + 1).ToString() + ", "
                                                     + s + ", " + afterDot + ");");
                                }
                                else
                                {
                                    writer.WriteLine("print_long((long)" + v.Name + ", " + i + ", " + (v.Position + 1).ToString() + ", "
                                                     + s
                                                     + ", " + afterDot + ");");
                                }
                            }
                            else
                            {
                                writer.WriteLine("print_edit((void*)&" + var.Name + ", " + i
                                                 + ", " + ++v.Position + ", "
                                                 + s
                                                 + ", " + afterDot + ", 0x" + AppliedMath.DecToHex(GetTypeCodeOfVar(var, v.HasSign)) + ");");
                            }
                        }
                        else
                        {
                            if (v.Name == "HOUR" ||
                                v.Name == "MIN" ||
                                v.Name == "SEC" ||
                                v.Name == "DATE" ||
                                v.Name == "MONTH" ||
                                v.Name == "YEAR")
                            {
                                if (v.ReadOnly)
                                {
                                    writer.WriteLine("print_long((long)" + "times." + v.Name.ToLower() + ", " + i + ", " + (v.Position + 1).ToString() + ", "
                                                     + s
                                                     + ", " + afterDot + ");");
                                }
                                else
                                {
                                    writer.WriteLine("print_time(" + i + "," + (v.Position + 1).ToString() + "," + v.Name + "_TYPE);");
                                }
                                continue;
                            }
                            Match m = Regex.Match(v.Name, @"\bEE(\d+)");
                            if (m.Success)
                            {
                                if (v.ReadOnly)
                                {
                                    writer.WriteLine("print_long((long)" + v.Name + ", " + i + ", " + (v.Position + 1).ToString() + ", "
                                                     + s
                                                     + ", " + afterDot + ");");
                                }
                                else
                                {
                                    writer.WriteLine("print_edit_ee(" + int.Parse(m.Groups[1].Value) + ", " + i
                                                     + ", " + ++v.Position + ", "
                                                     + s
                                                     + ", " + afterDot + ", 0x" + AppliedMath.DecToHex(GetTypeCodeOfEEVar(v.Name, v.HasSign)) + ");");
                                }
                                continue;
                            }

                            for (int k = 1; k < 9; k++)
                            {
                                v.Name = Regex.Replace(v.Name, @"\bADC" + k + "\b", "_Sys_ADC[" + (k - 1).ToString() + "]");
                                //Match m = Regex.Match(v.Name, );
                                //v.Name = v.Name.Replace("ADC" + k, "_Sys_ADC[" + (k - 1).ToString() + "]");
                            }

                            if (v.ReadOnly)
                            {
                                writer.WriteLine("print_long((long)" + v.Name + ", " + i + ", " + (v.Position + 1).ToString() + ", "
                                                 + (afterDot == 0 ? v.Mask.Length : v.Mask.Length - 1).ToString()
                                                 + ", " + afterDot + ");");
                            }
                            else
                            {
                                if (v.Name.Contains("ADC") || v.Name.Contains("DAC"))
                                {
                                    writer.WriteLine("print_edit((void*)&" + v.Name + ", " + i
                                                     + ", " + ++v.Position + ", "
                                                     + (afterDot == 0 ? v.Mask.Length : v.Mask.Length - 1).ToString()
                                                     + ", " + afterDot + ", 0x02);");
                                }
                                else
                                {
                                    writer.WriteLine("print_edit((void*)&" + v.Name + ", " + i
                                                     + ", " + ++v.Position + ", "
                                                     + (afterDot == 0 ? v.Mask.Length : v.Mask.Length - 1).ToString()
                                                     + ", " + afterDot + ", 0x01);");
                                }
                            }
                        }
                    }
                    writer.WriteLine("break;");
                    writer.Indent--;
                }
                writer.WriteLine("default: break;");
                writer.Indent--;
                writer.WriteLine("}");
            }
            writer.Indent--;
            writer.WriteLine("}");
            writer.WriteLine("");
            writer.Close();
            try
            {
                using (StreamWriter wr = new StreamWriter(this.solution.DirectoryName + "\\fc_u.c", true, Encoding.Default))
                {
                    wr.Write(code.ToString());
                }
            }
            catch (Exception ex)
            {
                this.Errors.Add(new Kontel.Relkon.Classes.CompilationError(ex.Message, this.solution.DirectoryName + "\\fc_u.c", -1, false));
            }
        }