CFNReader 1.1.1
dotnet add package CFNReader --version 1.1.1
NuGet\Install-Package CFNReader -Version 1.1.1
<PackageReference Include="CFNReader" Version="1.1.1" />
<PackageVersion Include="CFNReader" Version="1.1.1" />
<PackageReference Include="CFNReader" />
paket add CFNReader --version 1.1.1
#r "nuget: CFNReader, 1.1.1"
#addin nuget:?package=CFNReader&version=1.1.1
#tool nuget:?package=CFNReader&version=1.1.1
CFNReader
Introduction
Provides a simple way to read FNIRSI's CFN files (*.cfn
) produced by the FNIRSI UsbMeter tool (here). With this library you can also convert *.cfn
files to CSV files easily. Available as NuGet package.
QuickStart
using var myfile = File.OpenRead("myfile.cfn");
var cfnreader = new CFNStreamReader(myfile);
// Read general file information
var fileinfo = await cfnreader.ReadFileInfoAsync();
// Read and print data points
await foreach (var datapoint in cfnreader.ReadDatapointsAsync(fileinfo))
{
Console.WriteLine(
string.Join("\t", [datapoint.Time.ToString("G"), datapoint.Values[Channel.VBusVoltage], datapoint.Values[Channel.VBusCurrent]])
);
}
Output:
0:00:00:00,0000000 0.0000V 0.0126A
0:00:00:00,0100000 0.0100V 0.0126A
0:00:00:00,0200000 0.0200V 0.0126A
0:00:00:00,0300000 0.0300V 0.0126A
0:00:00:00,0400000 0.0400V 0.0126A
...
The CFNStreamReader
class provides two methods to read the file: ReadFileInfoAsync
and ReadDatapointsAsync
. The first one reads the file header and returns a FileInfo
object. The second one reads the data points and returns an IAsyncEnumerable<DataPoint>
. Both methods are asynchronous and support cancellation using a CancellationToken
.
Convert to CSV
A simple way to convert the data to a CSV is provided by the CFNCSVConverter
:
using var myfile = File.OpenRead("myfile.cfn");
using var csvfile = File.Create("export.csv");
var csvconverter = new CFNCSVConverter(new CFNCSVConverterOptions()
{
Channels = [Channel.AccumulatedCapacity, Channel.VBusVoltage],
Predicate = dp => dp.Values[Channel.VBusVoltage] > 0.5,
IncludeUnit = true,
LimitDataPoints = 1000
});
await csvconverter.ConvertToCSVAsync(testfile, csvfile);
The CFNCSVConverter
class constructor accepts CFNCSVConverterOptions
or IOptions<CFNCSVConverterOptions>
which has the following properties:
Channels
: An array ofChannel
values to include in the CSV. The order of the channels in the array will be the order of the columns in the CSV.Predicate
: A function that receives aDatapoint
and returns a boolean. If the function returnstrue
, theDatapoint
will be included in the CSV.FormatProvider
: AnIFormatProvider
to use when formatting the values.Separator
: The separator to use between the values (default;
).Encoding
: The encoding to use when writing the CSV file (defaultUTF8
).TimeFormat
: The format to use when formatting the time values (defaultG
).ValueFormat
: The format to use when formatting the values (defaultN4
).IncludeHeader
: Wether to include the header row in the CSV.IncludeTime
: Wether to include the time column (always first column).IncludeUnit
: Wether to include the unit of the value(s) likeA
(amps) orV
(volts) for example.LimitDataPoints
: The maximum number of data points to include in the CSV (defaultint.MaxValue
)
Acknowledgements
This library is based on didim99's work in usbmeter-utils.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.3)
- Microsoft.Extensions.Options (>= 9.0.3)
- System.Linq.Async (>= 6.0.1)
- System.Memory (>= 4.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.