79 lines
2.9 KiB
C#
79 lines
2.9 KiB
C#
using IobManComm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IobManComm
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("-------------------------");
|
|
Console.WriteLine("Starting console IOB-MAN client");
|
|
Console.WriteLine("-------------------------");
|
|
|
|
/*-----------------
|
|
nome dell'istanza corrente, con cui viene invocato il programma
|
|
es: consoleApp.exe SERIAL_TEST_01
|
|
--> leggerà il file di conf SERIAL_TEST_01.ini
|
|
*/
|
|
int idx = 0;
|
|
foreach (var item in args)
|
|
{
|
|
Console.WriteLine($"Args[{idx}]: {item}");
|
|
idx++;
|
|
}
|
|
string codIob = "SERIAL_TEST_01";
|
|
if (args != null && args.Length > 0)
|
|
{
|
|
codIob = args[0];
|
|
}
|
|
|
|
// valori da recuperare da ini... che dovranno corrispondere nel programma che fa partire il sw
|
|
string tipoIob = "SERIAL";
|
|
string appName = "CVSER";
|
|
int redisDb = 14; // 14 è normalmente libero... valori ammessi 0..15)
|
|
int minSecDelta = 1; // periodo minimo x considerare il dato variato da aprte del server
|
|
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
// preparo oggetto x gestione WathDog
|
|
var rwd = new RedisWatchDog(codIob, tipoIob, appName, redisDb, minSecDelta);
|
|
// oggetto di status che si impiega come watchdog, popolati solo i dati importanti
|
|
var currStatus = rwd.iobStatus;
|
|
currStatus.freeNotes = "starting";
|
|
currStatus.online = false;
|
|
rwd.iobStatus = currStatus;
|
|
Console.WriteLine("Premi enter x continuare");
|
|
Console.ReadLine();
|
|
|
|
// aggiorno info
|
|
Console.WriteLine("Press ESC to stop");
|
|
int count = 0;
|
|
do
|
|
{
|
|
while (!Console.KeyAvailable)
|
|
{
|
|
// Do something
|
|
Task.Delay(1000).Wait();
|
|
count++;
|
|
adesso = DateTime.Now;
|
|
// aggiorno valori, ad esempio IN da macchina, OUT verso macchina? last update = ultima comunicazione?
|
|
currStatus.lastDataIn = adesso.AddSeconds(-3);
|
|
currStatus.lastDataOut = adesso.AddSeconds(-2);
|
|
currStatus.lastUpdate = adesso;
|
|
currStatus.online = true;
|
|
// note libere x indicare ultimo task?
|
|
currStatus.freeNotes = $"Conteggio: {count}";
|
|
// invio update
|
|
rwd.iobStatus = currStatus;
|
|
Console.WriteLine($"Clock: {DateTime.Now}");
|
|
}
|
|
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
|
|
}
|
|
}
|
|
}
|