protected override OpTypeFloat VisitTypeFloat(TypeFloat node) { var visitTypeFloat = base.VisitTypeFloat(node); visitTypeFloat.Width = node.Width; return(Register(visitTypeFloat, _typeInstructions)); }
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 + ");"); }
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();"); } }
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); }
void Visitor.Visit(TypeFloat type) { sw.WriteLine(prefix + $"sb.Append(new string(' ', level * 4)).Append(\"{var}\").Append(\"=\").Append({var}).Append(\"{sep}\").Append(Environment.NewLine);"); }
public void Visit(TypeFloat type) { DefineStack(type); }
public void Visit(TypeFloat type) { name = "number"; }
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); }
public void Visit(TypeFloat type) { WriteProperty(type); }
void Visitor.Visit(TypeFloat type) { Type = Zeze.Serialize.ByteBuffer.FLOAT; }
void Visitor.Visit(TypeFloat type) { text = var.NamePrivate + (isEquals ? " == " : " != ") + another + "." + var.NamePrivate; }
void Visitor.Visit(TypeFloat type) { ChangeVariableCollectorName = "Zeze.Transaction.ChangeVariableCollectorChanged()"; }
void Visitor.Visit(TypeFloat type) { }
public void Visit(TypeFloat type) { name = "float"; }
public void Visit(TypeFloat type) { text = "System.BitConverter.SingleToInt32Bits(" + varname + ").GetHashCode()"; }
void Visitor.Visit(TypeFloat type) { Name = "Zeze.ByteBuffer.FLOAT"; }
public void Visit(TypeFloat type) { Initial(); }
public void Visit(TypeFloat type) { text = variable.NamePrivate + ".CompareTo(" + another + "." + variable.NamePrivate + ")"; }
public void Visit(TypeFloat type) { WriteLogValue(type); }
void Visitor.Visit(TypeFloat type) { SetDefaultValue("0"); }