laatzen/Common/CommonConsole/Program.cs
2023-10-05 09:21:54 +02:00

185 lines
6.2 KiB
C#

namespace CommonConsole
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
public class Program
{
[DllImport("GMH3x32E.dll")]
public static extern Int16 UniversalOpenCom(Int16 ini16COMPortNumber, UInt32 inui32BaudRate, Int16 inui16ConverterType, Int16 ini16Parity, Int16 ini16StoppBits);
[DllImport("GMH3x32E.dll")]
public static extern Int16 GMH_CloseCom();
[DllImport("GMH3x32E.dll")]
unsafe public static extern Int16 GMH_Transmit(Int16 ini16DeviceAddress, Int16 ini16TransmitCode, Int16* refi16ptrPriority, double* refdblptrFloatValue, Int32* refi32ptrIntegerValue);
public static void Main()
{
UniversalOpenCom(12, 4800, 8, 0, 0);
Int16 i16Priority;
Double dblFloatValue;
Int32 i32IntergerValue;
unsafe
{
var i16ErrorCode = GMH_Transmit(1, 0, &i16Priority, &dblFloatValue, &i32IntergerValue);
}
Console.WriteLine(dblFloatValue);
GMH_CloseCom();
}
//public static void Main(string[] args)
//{
// var messurementLines = File.ReadLines(@".\messurements.txt");
// var messurements = new List<Messurement>();
// var parsedData = new List<MessurementData>();
// var us = new CultureInfo("en-US");
// var de = new CultureInfo("de-DE");
// var any = NumberStyles.Any;
// var skipNext = true;
// foreach (var line in messurementLines)
// {
// if (string.IsNullOrWhiteSpace(line))
// {
// if (parsedData.Count > 0)
// {
// messurements.Add(new Messurement
// {
// PcbId = parsedData.First().PcbId,
// Start = parsedData.Min(x => x.Timestamp),
// MinT = parsedData.Min(x => x.CurrentT),
// MinTOF = parsedData.Min(x => x.CurrentTOF),
// AvgT = parsedData.Average(x => x.CurrentT),
// AvgTOF = parsedData.Average(x => x.CurrentTOF),
// MaxT = parsedData.Max(x => x.CurrentT),
// MaxTOF = parsedData.Max(x => x.CurrentTOF),
// End = parsedData.Max(x => x.Timestamp),
// });
// }
// parsedData = new List<MessurementData>();
// skipNext = true;
// continue;
// }
// if (skipNext)
// {
// skipNext = false;
// continue;
// }
// var lineTokens = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
// if (lineTokens.Length != 4)
// {
// continue;
// }
// var dateString = lineTokens[0];
// var pcbId = lineTokens[1];
// var temperatureString = lineTokens[2];
// var tofString = lineTokens[3];
// _ = DateTime.TryParse(dateString.Substring(1, dateString.Length - 2), out var timestamp);
// _ = double.TryParse(temperatureString, any, us, out var currentT) || double.TryParse(temperatureString, any, de, out currentT);
// _ = double.TryParse(tofString, any, us, out var currentTOF) || double.TryParse(tofString, any, de, out currentT);
// parsedData.Add(new MessurementData
// {
// PcbId = pcbId,
// CurrentT = currentT,
// CurrentTOF = currentTOF,
// Timestamp = timestamp
// });
// }
// File.WriteAllLines(@".\messurements.csv", messurements.Select(x
// => $"{x.PcbId,10}\t"
// + $"{x.AvgT,5:0.00}\t"
// + $"{x.AvgTOF,12:0.0000000000}\t"
// + $"{x.DifferenceT,5:00.00}\t"
// + $"{x.DifferenceTOF,12:0.0000000000}"));
// Console.WriteLine(Messurement.Header);
// messurements.ForEach(Console.WriteLine);
//}
}
public class MessurementData
{
public string PcbId { get; set; }
public double CurrentT { get; set; }
public double CurrentTOF { get; set; }
public DateTime Timestamp { get; set; }
}
public class Messurement
{
public string PcbId { get; set; }
public DateTime Start { get; set; }
public double MinTOF { get; set; }
public double MinT { get; set; }
public double AvgTOF { get; set; }
public double AvgT { get; set; }
public double MaxTOF { get; set; }
public double MaxT { get; set; }
public DateTime End { get; set; }
public double DifferenceT => Math.Abs(this.MaxT - this.MinT);
public double DifferenceTOF => Math.Abs(this.MaxTOF - this.MinTOF);
public override String ToString()
=> $"{this.PcbId,10}\t"
+ $"{this.Start,21:yyyy-MM-dd hh:mm:ss}\t"
+ $"{this.MinT,5:0.00}\t"
+ $"{this.MinTOF,12:0.0000000000}\t"
+ $"{this.AvgT,5:0.00}\t"
+ $"{this.AvgTOF,12:0.0000000000}\t"
+ $"{this.MaxT,5:0.00}\t"
+ $"{this.MaxTOF,12:0.0000000000}\t"
+ $"{this.End,21:yyyy-MM-dd hh:mm:ss}\t"
+ $"{this.DifferenceT,5:00.00}\t"
+ $"{this.DifferenceTOF,12:0.0000000000}";
public static string Header
=> $"{"PcbId",10}\t"
+ $"{"Start",21}\t"
+ $"{"Min T",5}\t"
+ $"{"Min TOF",12}\t"
+ $"{"Avg T",5}\t"
+ $"{"Avg TOF",12}\t"
+ $"{"Max T",5}\t"
+ $"{"Max TOF",12}\t"
+ $"{"End",21}\t"
+ $"{"Dif T",5}\t"
+ $"{"Dif TOF",12}";
}
}