191 lines
6.8 KiB
C#
191 lines
6.8 KiB
C#
|
|
using NLog;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts;
|
|||
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
|||
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|||
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|||
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|||
|
|
using Xylem.Common.Utils.Logging;
|
|||
|
|
|
|||
|
|
namespace FreezzeConsole
|
|||
|
|
{
|
|||
|
|
internal class Program
|
|||
|
|
{
|
|||
|
|
private static void Main(string[] args)
|
|||
|
|
{
|
|||
|
|
Semaphore semaphoreObject = new Semaphore(initialCount: 3, maximumCount: 3, name: "PrinterApp");
|
|||
|
|
Printer printerObject = new Printer();
|
|||
|
|
|
|||
|
|
for (int i = 0; i < 20; ++i)
|
|||
|
|
{
|
|||
|
|
int j = i;
|
|||
|
|
Task.Factory.StartNew(() =>
|
|||
|
|
{
|
|||
|
|
semaphoreObject.WaitOne();
|
|||
|
|
printerObject.Print(j);
|
|||
|
|
semaphoreObject.Release();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
Console.ReadLine();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private class Printer
|
|||
|
|
{
|
|||
|
|
public void Print(int documentToPrint)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("Printing document: " + documentToPrint);
|
|||
|
|
//code to print document
|
|||
|
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Slow()
|
|||
|
|
{
|
|||
|
|
long nthPrime = FindPrimeNumber(10000); //set higher value for more time
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static long FindPrimeNumber(int n)
|
|||
|
|
{
|
|||
|
|
int count = 0;
|
|||
|
|
long a = 2;
|
|||
|
|
while (count < n)
|
|||
|
|
{
|
|||
|
|
long b = 2;
|
|||
|
|
int prime = 1;// to check if found a prime
|
|||
|
|
while (b * b <= a)
|
|||
|
|
{
|
|||
|
|
if (a % b == 0)
|
|||
|
|
{
|
|||
|
|
prime = 0;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
b++;
|
|||
|
|
}
|
|||
|
|
if (prime > 0)
|
|||
|
|
{
|
|||
|
|
count++;
|
|||
|
|
}
|
|||
|
|
a++;
|
|||
|
|
}
|
|||
|
|
return (--a);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static void Maain(string[] args)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
//Console.WriteLine("Test Runs?");
|
|||
|
|
//var inp = Console.ReadLine();
|
|||
|
|
var sw = new Stopwatch();
|
|||
|
|
|
|||
|
|
//if (!string.IsNullOrEmpty(inp))
|
|||
|
|
//{
|
|||
|
|
// s.Start();
|
|||
|
|
// var runs = int.Parse(inp);
|
|||
|
|
// for (int i = 0; i < runs; i++)
|
|||
|
|
// {
|
|||
|
|
// Console.WriteLine($"{i}_{FindPrimeNumber(100000)}");
|
|||
|
|
// }
|
|||
|
|
// s.Stop();
|
|||
|
|
// Console.WriteLine($"{runs} Runs need {s.ElapsedMilliseconds}ms");
|
|||
|
|
//}
|
|||
|
|
//Console.WriteLine($"exit");
|
|||
|
|
//Console.ReadLine();
|
|||
|
|
sw.Start();
|
|||
|
|
var loggers = new List<Tuple<string, ILogger>>();
|
|||
|
|
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("0", NLogHelper.CreateOrGetLogger("Slot:0")));
|
|||
|
|
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("1", NLogHelper.CreateOrGetMultiLogger("Slot:0", "Slot", "Meter", "MeterBase", "MeterBase")));
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("2", NLogHelper.CreateOrGetMultiLogger("Slot:0", "", "Meter", "MeterBase", "MeterBase")));
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("3", NLogHelper.CreateOrGetMultiLogger("Slot:0, Port:COM9, Protocol:Request, Type:IrDA -", "", "RequestProtocol", "MeterBase", "MeterBase")));
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("4", NLogHelper.CreateOrGetMultiLogger("COM9", "COM", "TransmitProtocol", "COMBase", "BaseTransmitProtocol")));
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("5", NLogHelper.CreateOrGetMultiLogger("Slot:0, Port:COM9, Protocol:Request, Type:IrDA -", "", "LedRawData", "TargetLedRawDataBase", "LedRawDataBase")));
|
|||
|
|
loggers.Add(new Tuple<string, ILogger>("6", NLogHelper.CreateOrGetMultiLogger("Slot:0, Port:COM9, Protocol:Request, Type:IrDA -", "", "UartSerialPort", "COMBase", "BaseSerialPort")));
|
|||
|
|
sw.Stop();
|
|||
|
|
|
|||
|
|
Console.WriteLine($"init {sw.ElapsedMilliseconds}ms");
|
|||
|
|
foreach (var item in loggers)
|
|||
|
|
{
|
|||
|
|
sw.Restart();
|
|||
|
|
item.Item2.Fatal("1");
|
|||
|
|
item.Item2.Fatal("2");
|
|||
|
|
item.Item2.Fatal("3");
|
|||
|
|
item.Item2.Fatal("4");
|
|||
|
|
item.Item2.Fatal("5");
|
|||
|
|
item.Item2.Fatal("6");
|
|||
|
|
item.Item2.Fatal("7");
|
|||
|
|
item.Item2.Fatal("8");
|
|||
|
|
item.Item2.Fatal("9");
|
|||
|
|
item.Item2.Fatal("10");
|
|||
|
|
|
|||
|
|
sw.Stop();
|
|||
|
|
Console.WriteLine($"{item.Item1} {sw.ElapsedMilliseconds}ms");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
Console.WriteLine("Start COM X?");
|
|||
|
|
var Com = "COM" + Console.ReadLine();
|
|||
|
|
Console.WriteLine("LVL8 PWD? (empty for server call)");
|
|||
|
|
//var Password = "6BA812067823";//Console.ReadLine();
|
|||
|
|
var Password = Console.ReadLine();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
using (var meterBatch = new MeterBatch())
|
|||
|
|
{
|
|||
|
|
var meter = new GenesisMeter(0,
|
|||
|
|
new PortConfig()
|
|||
|
|
{
|
|||
|
|
PortName = Com,
|
|||
|
|
Type = typeof(IrdaSerialPort).ToString()
|
|||
|
|
}, null);
|
|||
|
|
|
|||
|
|
meterBatch.AddMeter(meter);
|
|||
|
|
//Console.WriteLine("AdditionalRetryTimeoutMs? (empty for default)");
|
|||
|
|
//var inp = Console.ReadLine();
|
|||
|
|
//if (!string.IsNullOrEmpty(inp))
|
|||
|
|
//{
|
|||
|
|
// meter.RequestProtocol.AdditionalRetryTimeoutMs = int.Parse(inp);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
var pcb = meter.GetPcbId();
|
|||
|
|
Console.WriteLine($"Meter created {pcb}.");
|
|||
|
|
|
|||
|
|
var loginResult = false;
|
|||
|
|
if (!string.IsNullOrEmpty(Password))
|
|||
|
|
{
|
|||
|
|
loginResult = meter.Login(Password);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
loginResult = meter.Login();
|
|||
|
|
}
|
|||
|
|
Console.WriteLine($"Login = {loginResult}");
|
|||
|
|
for (int i = 0; i < 5; i++)
|
|||
|
|
{
|
|||
|
|
var s = RegisterConverter.ConvertTo<int>(meter.ReadRegister("SYSTEM_CalendarSeconds"));
|
|||
|
|
Console.WriteLine($"System_CalendarSeconds = {s}");
|
|||
|
|
}
|
|||
|
|
Console.WriteLine($"exit");
|
|||
|
|
Console.ReadLine();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(ex.Message);
|
|||
|
|
Console.ReadLine();
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|