示例#1
0
        protected override OpTypeFloat VisitTypeFloat(TypeFloat node)
        {
            var visitTypeFloat = base.VisitTypeFloat(node);

            visitTypeFloat.Width = node.Width;
            return(Register(visitTypeFloat, _typeInstructions));
        }
示例#2
0
 public void Visit(TypeFloat type)
 {
     if (id >= 0)
     {
         sw.WriteLine(prefix + "_os_.WriteInt(Zeze.ByteBuffer.FLOAT | " + id + " << Zeze.ByteBuffer.TAG_SHIFT);");
     }
     sw.WriteLine(prefix + "_os_.WriteFloat(" + varname + ");");
 }
示例#3
0
 void Visitor.Visit(TypeFloat type)
 {
     if (id >= 0)
     {
         sw.WriteLine(prefix + "case (Zeze.ByteBuffer.FLOAT | " + id + " << Zeze.ByteBuffer.TAG_SHIFT): ");
         sw.WriteLine(prefix + "    " + varname + " = " + bufname + ".ReadFloat();");
         sw.WriteLine(prefix + "    break;");
     }
     else
     {
         sw.WriteLine(prefix + varname + " = " + bufname + ".ReadFloat();");
     }
 }
示例#4
0
 public static IType TypeMap(Func <int, TypeVar, IType> onVar, int c, IType t)
 {
     IType Walk(int c, IType t)
     {
         return(t switch
         {
             TypeVar v => onVar(c, v),
             TypeId i => i,
             TypeString ts => ts,
             TypeUnit u => u,
             TypeRecord r => new TypeRecord(r.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))),
             TypeFloat f => f,
             TypeBool b => b,
             TypeNat n => n,
             TypeArrow a => new TypeArrow(Walk(c, a.From), Walk(c, a.To)),
             TypeVariant tv => new TypeVariant(tv.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))),
             _ => throw new InvalidOperationException()
         });
     }
        protected virtual bool WriteFloatField(string fieldName, uint byteOffset, TypeFloat floatType)
        {
            string actualName = null;

            switch (floatType.Width)
            {
            case 32:
                actualName = "float";
                break;

            case 64:
                actualName = "double";
                break;
            }

            if (actualName != null)
            {
                WriteLine($"    [FieldOffset({byteOffset})]");
                WriteLine($"    public {actualName} {fieldName};");
                return(true);
            }

            return(false);
        }
示例#6
0
文件: Tostring.cs 项目: e2wugui/zeze
 void Visitor.Visit(TypeFloat type)
 {
     sw.WriteLine(prefix + $"sb.Append(new string(' ', level * 4)).Append(\"{var}\").Append(\"=\").Append({var}).Append(\"{sep}\").Append(Environment.NewLine);");
 }
示例#7
0
文件: Define.cs 项目: e2wugui/zeze
 public void Visit(TypeFloat type)
 {
     DefineStack(type);
 }
示例#8
0
 public void Visit(TypeFloat type)
 {
     name = "number";
 }
示例#9
0
        public Dictionary <string, object> ReadAll()
        {
            if (MyModFieldStore == null || MyModFieldStore.TheValues.Count == 0)
            {
                return(null);
            }
            var timestamp = DateTimeOffset.Now;
            var dict      = new Dictionary <string, object>();

            dict["Timestamp"] = timestamp;

            // Read configured data items via Modbus
            int tMainOffset   = (int)TheThing.GetSafePropertyNumber(MyBaseThing, "Offset");
            int tSlaveAddress = (int)TheThing.GetSafePropertyNumber(MyBaseThing, "SlaveAddress");
            int tReadWay      = (int)TheThing.GetSafePropertyNumber(MyBaseThing, "ConnectionType");

            foreach (var field in MyModFieldStore.TheValues)
            {
                try
                {
                    int address = field.SourceOffset + tMainOffset;

                    ushort[] data = null;

                    float scale = field.ScaleFactor;
                    if (scale == 0)
                    {
                        scale = 1.0f;
                    }

                    switch (tReadWay)
                    {
                    case 1:
                    {
                        bool[] datab = MyModMaster.ReadCoils((ushort)address, (ushort)field.SourceSize);
                        for (int i = 0; i < field.SourceSize && i < datab.Length; i++)
                        {
                            dict[$"{field.PropertyName}_{i}"] = datab[i];
                        }
                        field.Value = dict[$"{field.PropertyName}_0"];
                    }
                        continue;

                    case 2:
                    {
                        bool[] datab = MyModMaster.ReadInputs((ushort)address, (ushort)field.SourceSize);
                        for (int i = 0; i < field.SourceSize && i < datab.Length; i++)
                        {
                            dict[$"{field.PropertyName}_{i}"] = datab[i];
                        }
                        field.Value = dict[$"{field.PropertyName}_0"];
                    }
                        continue;

                    case 4:
                        data = MyModMaster.ReadInputRegisters((byte)tSlaveAddress, (ushort)address, (ushort)field.SourceSize);
                        break;

                    default:
                        data = MyModMaster.ReadHoldingRegisters((byte)tSlaveAddress, (ushort)address, (ushort)field.SourceSize);
                        break;
                    }
                    if (data == null)
                    {
                        continue;
                    }
                    if (field.SourceType == "float")
                    {
                        var value1 = TypeFloat.Convert(data, TypeFloat.ByteOrder.CDAB);
                        dict[field.PropertyName] = value1 / scale;
                    }
                    else if (field.SourceType == "float-abcd")
                    {
                        var value1 = TypeFloat.Convert(data, TypeFloat.ByteOrder.ABCD);
                        dict[field.PropertyName] = value1 / scale;
                    }
                    else if (field.SourceType == "double")
                    {
                        var value1 = TypeDouble.Convert(data, TypeDouble.ByteOrder.ABCD);
                        dict[field.PropertyName] = value1 / scale;
                    }
                    else if (field.SourceType == "double-cdab")
                    {
                        var value1 = TypeDouble.Convert(data, TypeDouble.ByteOrder.CDAB);
                        dict[field.PropertyName] = value1 / scale;
                    }
                    else if (field.SourceType == "int32")
                    {
                        var value    = TypeInt32.Convert(data);
                        var dblValue = Convert.ToDouble(value);
                        dict[field.PropertyName] = dblValue / scale;
                    }
                    else if (field.SourceType == "int64")
                    {
                        var value    = TypeInt64.Convert(data);
                        var dblValue = Convert.ToDouble(value);
                        dict[field.PropertyName] = dblValue / scale;
                    }
                    else if (field.SourceType == "float32")
                    {
                        var value = TypeFloat.Convert(data, TypeFloat.ByteOrder.SinglePrecIEEE);
                        dict[field.PropertyName] = value / scale;
                    }
                    else if (field.SourceType == "uint16")
                    {
                        var value = TypeUInt16.Convert(data);
                        dict[field.PropertyName] = value / scale;
                    }
                    else if (field.SourceType == "int16")
                    {
                        var value = TheCommonUtils.CInt(data[0]);
                        dict[field.PropertyName] = value / scale;
                    }
                    else if (field.SourceType == "utf8")
                    {
                        var value = TypeUTF8.Convert(data);
                        dict[field.PropertyName] = value;
                    }
                    else if (field.SourceType == "byte")
                    {
                        byte value = (byte)(data[0] & 255);
                        dict[field.PropertyName] = value;
                    }
                    field.Value = dict[field.PropertyName];

                    //dict[$"[{field.PropertyName}].[Status]"] = $"";
                }
                catch (Exception e)
                {
                    try
                    {
                        // Future: convey per-tag status similar to OPC statuscode?
                        //dict[$"[{field.PropertyName}].[Status]"] = $"##cdeError: {e.Message}";
                        TheBaseAssets.MySYSLOG.WriteToLog(10000, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM(MyBaseThing.EngineName, $"Error reading property {field.PropertyName}", eMsgLevel.l2_Warning, e.ToString()));
                    }
                    catch { }
                }
            }
            return(dict);
        }
示例#10
0
 public void Visit(TypeFloat type)
 {
     WriteProperty(type);
 }
示例#11
0
 void Visitor.Visit(TypeFloat type)
 {
     Type = Zeze.Serialize.ByteBuffer.FLOAT;
 }
示例#12
0
 void Visitor.Visit(TypeFloat type)
 {
     text = var.NamePrivate + (isEquals ? " == " : " != ") + another + "." + var.NamePrivate;
 }
示例#13
0
 void Visitor.Visit(TypeFloat type)
 {
     ChangeVariableCollectorName = "Zeze.Transaction.ChangeVariableCollectorChanged()";
 }
示例#14
0
 void Visitor.Visit(TypeFloat type)
 {
 }
示例#15
0
文件: TypeName.cs 项目: e2wugui/zeze
 public void Visit(TypeFloat type)
 {
     name = "float";
 }
示例#16
0
 public void Visit(TypeFloat type)
 {
     text = "System.BitConverter.SingleToInt32Bits(" + varname + ").GetHashCode()";
 }
示例#17
0
 void Visitor.Visit(TypeFloat type)
 {
     Name = "Zeze.ByteBuffer.FLOAT";
 }
示例#18
0
文件: Construct.cs 项目: e2wugui/zeze
 public void Visit(TypeFloat type)
 {
     Initial();
 }
示例#19
0
文件: Compare.cs 项目: e2wugui/zeze
 public void Visit(TypeFloat type)
 {
     text = variable.NamePrivate + ".CompareTo(" + another + "." + variable.NamePrivate + ")";
 }
示例#20
0
 public void Visit(TypeFloat type)
 {
     WriteLogValue(type);
 }
示例#21
0
文件: Default.cs 项目: e2wugui/zeze
 void Visitor.Visit(TypeFloat type)
 {
     SetDefaultValue("0");
 }