Beispiel #1
0
 private void ConvertDataToIntegers(string[] hexValuesSplit, int startByte)
 {
     for (int i = startByte; (i - startByte < ByteCount) && (i < hexValuesSplit.Length - 1); i += 2)
     {
         MdbusInteger mdbusInt = new MdbusInteger();
         mdbusInt.RawString = hexValuesSplit[i] + ' ' + hexValuesSplit[i + 1];
         mdbusInt.IntString = (hexValuesSplit[i + 0] + hexValuesSplit[i + 1]);
         // Convert hex string to both signed and unsigned 16-bit integer values
         mdbusInt.SignedValue   = Int16.Parse(mdbusInt.IntString, System.Globalization.NumberStyles.AllowHexSpecifier);
         mdbusInt.UnsignedValue = UInt16.Parse(mdbusInt.IntString, System.Globalization.NumberStyles.AllowHexSpecifier);
         IntValues.Add(mdbusInt);
     }
 }
 /// <summary>
 /// Handles setting of a value in the IntValues Dictionary
 /// </summary>
 /// <param name="value">Value to Set</param>
 /// <param name="name">Compiler Generated Name of the Property</param>
 public void SetInt(int value, [CallerMemberName] string name = null)
 {
     if (name == null)
     {
         return;
     }
     if (IntValues.ContainsKey(name))
     {
         IntValues[name] = value;
     }
     else
     {
         IntValues.Add(name, value);
     }
 }
        public void AddValue(Parameter param)
        {
            switch (param.StorageType)
            {
            case StorageType.ElementId:
                ElementId eId = param.AsElementId();
                if (eId != ElementId.InvalidElementId && !ElementIDValues.Contains(eId))
                {
                    ElementIDValues.Add(eId);
                }
                break;

            case StorageType.Double:
                double dbl = param.AsDouble();
                if (!DoubleValues.Contains(dbl))
                {
                    DoubleValues.Add(dbl);
                }
                break;

            case StorageType.Integer:
                int intVal = param.AsInteger();
                if (!IntValues.Contains(intVal))
                {
                    IntValues.Add(intVal);
                }
                break;

            case StorageType.String:
                string str = param.AsString();
                if (!string.IsNullOrEmpty(str) && !StringValues.Contains(str))
                {
                    StringValues.Add(str);
                }
                break;
            }
        }
            public MonitorOption(string valueText)
            {
                if (!String.IsNullOrEmpty(valueText))
                {
                    StrValue = valueText;
                    int iv; if (int.TryParse(valueText, out iv))
                    {
                        IntValue = iv;
                    }
                    float fv; if (float.TryParse(valueText, out fv))
                    {
                        FloatValue = fv;
                    }
                    Color cv; if (TryParseColor(valueText, out cv))
                    {
                        ColorValue = cv;
                    }

                    foreach (var str in valueText.Split('|'))
                    {
                        StrValues.Add(str);
                        if (int.TryParse(str, out iv))
                        {
                            IntValues.Add(iv);
                        }
                        if (float.TryParse(str, out fv))
                        {
                            FloatValues.Add(fv);
                        }
                        if (TryParseColor(str, out cv))
                        {
                            ColorValues.Add(cv);
                        }
                    }
                }
            }
Beispiel #5
0
 private void CreateCollectionVariable(List <string> lst, int type)
 {
     for (int i = 0; i < lst.Count; i++)
     {
         if (type == 0)
         {
             BitVar bv = new BitVar("Klapany");
             bv.VarName = lst[i];
             BitValues.Add(bv);
         }
         if (type == 1)
         {
             BoolVar bov = new BoolVar("Klapany");
             bov.VarName = lst[i];
             BoolValues.Add(bov);
         }
         if (type == 2)
         {
             IntVar iv = new IntVar("Klapany");
             iv.VarName = lst[i];
             IntValues.Add(iv);
         }
         if (type == 3)
         {
             DoubleVar dv = new DoubleVar("Klapany");
             dv.VarName = lst[i];
             DoubleValues.Add(dv);
         }
         if (type == 4)
         {
             BoolVarFMS bvfms = new BoolVarFMS("Klapany");
             bvfms.VarName = lst[i];
             BoolFMSValues.Add(bvfms);
         }
     }
 }
        public ExecutionState LoadData(ByteReader br)
        {
            while (br.Avaliable > 0)
            {
                var Name = br.ReadString();
                if (!Name)
                {
                    return(ExecutionState.Failed());
                }
                var Type = br.ReadByte();
                if (!Type)
                {
                    return(ExecutionState.Failed());
                }
                if (!DataTypeHelper.TryParse(Type.Result, out DataType TypeResult))
                {
                    return(ExecutionState.Failed());
                }
                switch (TypeResult)
                {
                case DataType.type_byte:
                    var ValueByte = br.ReadByte();
                    if (!ValueByte)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ByteValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ByteValues.Add(Name.Result, ValueByte.Result);
                    break;

                case DataType.type_sbyte:
                    var ValueSByte = br.ReadSByte();
                    if (!ValueSByte)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (SByteValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    SByteValues.Add(Name.Result, ValueSByte.Result);
                    break;

                case DataType.type_short:
                    var ValueShort = br.ReadShort();
                    if (!ValueShort)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ShortValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ShortValues.Add(Name.Result, ValueShort.Result);
                    break;

                case DataType.type_ushort:
                    var ValueUShort = br.ReadUShort();
                    if (!ValueUShort)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (UShortValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    UShortValues.Add(Name.Result, ValueUShort.Result);
                    break;

                case DataType.type_int:
                    var ValueInt = br.ReadInt();
                    if (!ValueInt)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (IntValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    IntValues.Add(Name.Result, ValueInt.Result);
                    break;

                case DataType.type_uint:
                    var ValueUInt = br.ReadUInt();
                    if (!ValueUInt)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (UIntValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    UIntValues.Add(Name.Result, ValueUInt.Result);
                    break;

                case DataType.type_long:
                    var ValueLong = br.ReadLong();
                    if (!ValueLong)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (LongValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    LongValues.Add(Name.Result, ValueLong.Result);
                    break;

                case DataType.type_ulong:
                    var ValueULong = br.ReadULong();
                    if (!ValueULong)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ULongValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ULongValues.Add(Name.Result, ValueULong.Result);
                    break;

                case DataType.type_single:
                    var ValueSingle = br.ReadSingle();
                    if (!ValueSingle)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (SingleValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    SingleValues.Add(Name.Result, ValueSingle.Result);
                    break;

                case DataType.type_double:
                    var ValueDobule = br.ReadDouble();
                    if (!ValueDobule)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (DoubleValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    DoubleValues.Add(Name.Result, ValueDobule.Result);
                    break;

                case DataType.type_string:
                    var ValueString = br.ReadString();
                    if (!ValueString)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (StringValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    StringValues.Add(Name.Result, ValueString.Result);
                    break;
                }
            }

            return(ExecutionState.Succeeded());
        }