本文整理汇总了C#中Ticks.ToMicroseconds方法的典型用法代码示例。如果您正苦于以下问题:C# Ticks.ToMicroseconds方法的具体用法?C# Ticks.ToMicroseconds怎么用?C# Ticks.ToMicroseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ticks
的用法示例。
在下文中一共展示了Ticks.ToMicroseconds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteNextRecordBinary
/// <summary>
/// Writes next COMTRADE record in binary format.
/// </summary>
/// <param name="output">Destination stream.</param>
/// <param name="schema">Source schema.</param>
/// <param name="timestamp">Record timestamp (implicitly castable as <see cref="DateTime"/>).</param>
/// <param name="values">Values to write - 16-bit digitals should exist as a word in an individual double value.</param>
/// <param name="sample">User incremented sample index.</param>
/// <param name="injectFracSecValue">Determines if FRACSEC value should be automatically injected into stream as first digital - defaults to <c>true</c>.</param>
/// <param name="fracSecValue">FRACSEC value to inject into output stream - defaults to 0x0000.</param>
/// <remarks>
/// This function is primarily intended to write COMTRADE binary data records based on synchrophasor data
/// (see Annex H: Schema for Phasor Data 2150 Using the COMTRADE File Standard in IEEE C37.111-2010),
/// it may be necessary to manually write records for other COMTRADE needs (e.g., non 16-bit digitals).
/// </remarks>
public static void WriteNextRecordBinary(Stream output, Schema schema, Ticks timestamp, double[] values, uint sample, bool injectFracSecValue = true, ushort fracSecValue = 0x0000)
{
// Make timestamp relative to beginning of file
timestamp -= schema.StartTime.Value;
uint microseconds = (uint)(timestamp.ToMicroseconds() / schema.TimeFactor);
double value;
bool isFirstDigital = true;
output.Write(LittleEndian.GetBytes(sample), 0, 4);
output.Write(LittleEndian.GetBytes(microseconds), 0, 4);
for (int i = 0; i < values.Length; i++)
{
value = values[i];
if (i < schema.AnalogChannels.Length)
{
value -= schema.AnalogChannels[i].Adder;
value /= schema.AnalogChannels[i].Multiplier;
}
else if (isFirstDigital)
{
// Handle automatic injection of IEEE C37.118 FRACSEC digital value if requested
isFirstDigital = false;
if (injectFracSecValue)
output.Write(LittleEndian.GetBytes(fracSecValue), 0, 2);
}
output.Write(LittleEndian.GetBytes((ushort)value), 0, 2);
}
// Make sure FRACSEC values are injected
if (isFirstDigital && injectFracSecValue)
output.Write(LittleEndian.GetBytes(fracSecValue), 0, 2);
}
示例2: WriteNextRecordAscii
/// <summary>
/// Writes next COMTRADE record in ASCII format.
/// </summary>
/// <param name="output">Destination stream.</param>
/// <param name="schema">Source schema.</param>
/// <param name="timestamp">Record timestamp (implicitly castable as <see cref="DateTime"/>).</param>
/// <param name="values">Values to write - 16-bit digitals should exist as a word in an individual double value, method will write out bits.</param>
/// <param name="sample">User incremented sample index.</param>
/// <param name="injectFracSecValue">Determines if FRACSEC value should be automatically injected into stream as first digital - defaults to <c>true</c>.</param>
/// <param name="fracSecValue">FRACSEC value to inject into output stream - defaults to 0x0000.</param>
/// <remarks>
/// This function is primarily intended to write COMTRADE ASCII data records based on synchrophasor data
/// (see Annex H: Schema for Phasor Data 2150 Using the COMTRADE File Standard in IEEE C37.111-2010),
/// it may be necessary to manually write records for other COMTRADE needs (e.g., non 16-bit digitals).
/// </remarks>
public static void WriteNextRecordAscii(StreamWriter output, Schema schema, Ticks timestamp, double[] values, uint sample, bool injectFracSecValue = true, ushort fracSecValue = 0x0000)
{
// Make timestamp relative to beginning of file
timestamp -= schema.StartTime.Value;
uint microseconds = (uint)(timestamp.ToMicroseconds() / schema.TimeFactor);
double value;
StringBuilder line = new StringBuilder();
bool isFirstDigital = true;
line.Append(sample);
line.Append(',');
line.Append(microseconds);
for (int i = 0; i < values.Length; i++)
{
value = values[i];
if (i < schema.AnalogChannels.Length)
{
value -= schema.AnalogChannels[i].Adder;
value /= schema.AnalogChannels[i].Multiplier;
line.Append(',');
line.Append(value);
}
else
{
if (isFirstDigital)
{
// Handle automatic injection of IEEE C37.118 FRACSEC digital value if requested
isFirstDigital = false;
if (injectFracSecValue)
{
for (int j = 0; j < 16; j++)
{
line.Append(',');
line.Append(fracSecValue.CheckBits(BitExtensions.BitVal(j)) ? 1 : 0);
}
}
}
ushort digitalWord = (ushort)value;
for (int j = 0; j < 16; j++)
{
line.Append(',');
line.Append(digitalWord.CheckBits(BitExtensions.BitVal(j)) ? 1 : 0);
}
}
}
// Make sure FRACSEC values are injected
if (isFirstDigital && injectFracSecValue)
{
for (int j = 0; j < 16; j++)
{
line.Append(',');
line.Append(fracSecValue.CheckBits(BitExtensions.BitVal(j)) ? 1 : 0);
}
}
output.WriteLine(line.ToString());
}