/// <summary> /// Formats the channel value, which is a number. /// </summary> protected string FormatNumber(double cnlVal, int dataTypeID, string format) { switch (dataTypeID) { case DataTypeID.Double: return(FormatIsHex(format) ? ((int)cnlVal).ToString(format, culture) + 'h' : cnlVal.ToString(format, culture)); case DataTypeID.Int64: string s = CnlDataConverter.DoubleToInt64(cnlVal).ToString(format, culture); return(FormatIsHex(format) ? s + 'h' : s); default: return(FormatError); } }
/// <summary> /// Formats the channel value, which is a date and time. /// </summary> protected string FormatDate(double cnlVal, int dataTypeID, string format) { string DateToString(DateTime dt) { return(TimeZoneInfo.ConvertTimeFromUtc(dt, timeZone).ToString(format, culture)); } switch (dataTypeID) { case DataTypeID.Double: return(DateToString(DateTime.FromOADate(cnlVal))); case DataTypeID.Int64: return(DateToString(ScadaUtils.TicksToTime(CnlDataConverter.DoubleToInt64(cnlVal)))); default: return(FormatError); } }
/// <summary> /// Formats the channel value depending on the data type. /// </summary> protected string FormatByDataType(double cnlVal, int dataTypeID) { switch (dataTypeID) { case DataTypeID.Double: return(cnlVal.ToString(DefaultFormat, culture)); case DataTypeID.Int64: return(CnlDataConverter.DoubleToInt64(cnlVal).ToString(culture)); case DataTypeID.ASCII: return(CnlDataConverter.DoubleToAscii(cnlVal)); case DataTypeID.Unicode: return(CnlDataConverter.DoubleToUnicode(cnlVal)); default: return(FormatError); } }
/// <summary> /// Formats the channel value, which is an enumeration. /// </summary> protected string FormatEnum(double cnlVal, int dataTypeID, EnumFormat format) { string GetEnumValue(int intVal) { return(format != null && 0 <= intVal && intVal < format.Values.Length ? format.Values[intVal] : intVal.ToString()); } switch (dataTypeID) { case DataTypeID.Double: return(GetEnumValue((int)cnlVal)); case DataTypeID.Int64: return(GetEnumValue((int)CnlDataConverter.DoubleToInt64(cnlVal))); default: return(FormatError); } }