From 44b24f0d4b4a6a7f7afbd75a7f59fd55323a0d25 Mon Sep 17 00:00:00 2001 From: Luc Vandenbroucke Date: Mon, 14 Oct 2024 13:31:46 +0200 Subject: [PATCH] 2.35 Elatec --- eDosStation/App.config | 1 + eDosStation/EntryBadge.xaml.cs | 64 ++++++++++++++++++-------- eDosStation/MainWindow.xaml.cs | 1 + eDosStation/Properties/AssemblyInfo.cs | 5 +- eDosStation/Resources/BuildDate.txt | 2 +- eDosStation/Settings.xaml | 9 ++-- eDosStation/Settings.xaml.cs | 17 ++++++- eDosStation/Station.cs | 55 ++++++++++++++++++++-- 8 files changed, 124 insertions(+), 30 deletions(-) diff --git a/eDosStation/App.config b/eDosStation/App.config index e0590ac..bca97c6 100644 --- a/eDosStation/App.config +++ b/eDosStation/App.config @@ -45,6 +45,7 @@ + diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs index 82e5f7a..de451dc 100644 --- a/eDosStation/EntryBadge.xaml.cs +++ b/eDosStation/EntryBadge.xaml.cs @@ -37,6 +37,7 @@ namespace eDosStation private DateTime ResultTime; private bool EpdReading=false; private bool FinalTimeOut=false; + enum eCOE { quiz = 1 }; #if SimulateEPD @@ -644,7 +645,7 @@ namespace eDosStation } EpdReading = false; dispatcherTimer?.Stop(); - + dispatcherTimer = null; this.Close(); } @@ -953,29 +954,54 @@ namespace eDosStation } //StartBadge - if (dfReader == null) + if (thisStation.isElatec) { - dfReader = new LSWDesfirePublic.CCard(); - dfReader.GetReaderList(); - if (dfReader.readersList.Contains(thisStation.Reader)) + thisStation.ReceivedPersid = Pelatec_DataReceived; + } else + { + if (dfReader == null) { - dfReader.SetReader(thisStation.Reader); - dfReader.Badged += DFReader_Badged; - dfReader.BadgeTO += DfReader_BadgeTO; - dfReader.BadgeError += DfReader_BadgeError; - ReaderTask = dfReader.Wait(PageTimeout,10); - } - else - { - StringBuilder er = new StringBuilder($"Badgelezer \"{thisStation.Reader}\" niet gevonden!.\nDeze lezers zijn beschikbaar:\n"); + dfReader = new LSWDesfirePublic.CCard(); dfReader.GetReaderList(); - foreach (string r in dfReader.readersList) er.AppendLine($"-> {r}"); - MessageBox.Show(er.ToString(), "Badge Lezer", MessageBoxButton.OK, MessageBoxImage.Exclamation); - dfReader.Dispose(); dfReader = null; + if (dfReader.readersList.Contains(thisStation.Reader)) + { + dfReader.SetReader(thisStation.Reader); + dfReader.Badged += DFReader_Badged; + dfReader.BadgeTO += DfReader_BadgeTO; + dfReader.BadgeError += DfReader_BadgeError; + ReaderTask = dfReader.Wait(PageTimeout, 10); + } + else + { + StringBuilder er = new StringBuilder($"Badgelezer \"{thisStation.Reader}\" niet gevonden!.\nDeze lezers zijn beschikbaar:\n"); + dfReader.GetReaderList(); + foreach (string r in dfReader.readersList) er.AppendLine($"-> {r}"); + MessageBox.Show(er.ToString(), "Badge Lezer", MessageBoxButton.OK, MessageBoxImage.Exclamation); + dfReader.Dispose(); dfReader = null; + } } - } - + } } + + private void Pelatec_DataReceived(int PersID) + { + this.Dispatcher.InvokeAsync(new Action(() => showBadge(PersID, null)), DispatcherPriority.Background); + } + //private void Pelatec_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) + //{ + // var v = elatecReader.ReadLine(); + // int PersID; + // if (!int.TryParse(v, out PersID)) PersID = 0; + // if (PersID > 0) + // this.Dispatcher.InvokeAsync(new Action(() => showBadge(PersID, null)), DispatcherPriority.Background); + // else + // { + // string msg = $"No PersID found on badge "; + // MessageBox.Show(msg, "Error", MessageBoxButton.OK); + // thisStation.splunkLog?.WriteSplunkLog("Badged", LSWLib.CLog.iseverity.warning, null, msg); + // } + //} + private void DfReader_BadgeError(LSWDesfirePublic.CCard Sender, LSWDesfirePublic.BadgeErrorEventArgs e) { endPage(); diff --git a/eDosStation/MainWindow.xaml.cs b/eDosStation/MainWindow.xaml.cs index df5640e..60243f0 100644 --- a/eDosStation/MainWindow.xaml.cs +++ b/eDosStation/MainWindow.xaml.cs @@ -10,6 +10,7 @@ namespace eDosStation /// public partial class MainWindow : Window { + const string className = "MainWindow"; public DataInterface dataInterface; public Station thisStation; diff --git a/eDosStation/Properties/AssemblyInfo.cs b/eDosStation/Properties/AssemblyInfo.cs index 7e25e3f..8d7b822 100644 --- a/eDosStation/Properties/AssemblyInfo.cs +++ b/eDosStation/Properties/AssemblyInfo.cs @@ -63,5 +63,6 @@ using System.Windows; //2.31 extra disconnect/connect //2.32 VS2022 //2.34 close com at end , also MK2 -[assembly: AssemblyVersion("2.34.0.0")] -[assembly: AssemblyFileVersion("2.34.0.0")] +//2.35 Elatec +[assembly: AssemblyVersion("2.35.0.0")] +[assembly: AssemblyFileVersion("2.35.0.0")] diff --git a/eDosStation/Resources/BuildDate.txt b/eDosStation/Resources/BuildDate.txt index 30c62d0..5166a66 100644 --- a/eDosStation/Resources/BuildDate.txt +++ b/eDosStation/Resources/BuildDate.txt @@ -1 +1 @@ -Mon 10/14/2024 9:54:23.70 +Mon 10/14/2024 13:29:05.87 diff --git a/eDosStation/Settings.xaml b/eDosStation/Settings.xaml index ec269b9..aba51f2 100644 --- a/eDosStation/Settings.xaml +++ b/eDosStation/Settings.xaml @@ -26,6 +26,7 @@ + @@ -74,11 +75,13 @@ - + + + - - + + diff --git a/eDosStation/Settings.xaml.cs b/eDosStation/Settings.xaml.cs index 5f9c899..92c59b6 100644 --- a/eDosStation/Settings.xaml.cs +++ b/eDosStation/Settings.xaml.cs @@ -121,6 +121,8 @@ namespace eDosStation thisStation.LogAll = cbLogAll.IsChecked != null ? cbLogAll.IsChecked.Value : false; + thisStation.ElatecPort = eComPort.SelectedValue.ToString().Trim(); + step = "Update"; thisStation.Update(); @@ -129,7 +131,6 @@ namespace eDosStation thisStation?.splunkLog?.WriteSplunkLog(module, LSWLib.CLog.iseverity.err, thisStation.ErrorMessage); MessageBox.Show($"Error {thisStation.ErrorMessage}"); } - } catch (System.Exception ex) { @@ -185,6 +186,7 @@ namespace eDosStation foreach (string cn in System.IO.Ports.SerialPort.GetPortNames()) { cComPort.Items.Add(cn); + eComPort.Items.Add(cn); } thisStation.splunkLog?.WriteSplunkLog(step, LSWLib.CLog.iseverity.info); } @@ -258,6 +260,19 @@ namespace eDosStation thisStation?.splunkLog?.WriteException(className, step, ex); MessageBox.Show($"Serial err {ex.Message}"); } + step = "Select ecom"; + try + { + string thisComport = thisStation.ElatecPort; + if (!eComPort.Items.Contains(thisComport)) eComPort.Items.Add(thisComport); + eComPort.SelectedItem = thisComport; + thisStation.splunkLog?.WriteSplunkLog(step, LSWLib.CLog.iseverity.info); + } + catch (System.Exception ex) + { + thisStation?.splunkLog?.WriteException(className, step, ex); + MessageBox.Show($"Serial err {ex.Message}"); + } step = "tbInstallations"; try diff --git a/eDosStation/Station.cs b/eDosStation/Station.cs index d5a0f15..cc80580 100644 --- a/eDosStation/Station.cs +++ b/eDosStation/Station.cs @@ -1,9 +1,13 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using System.Diagnostics.Eventing.Reader; using System.Text; +using System.Windows; using System.Windows.Controls; using System.Windows.Documents; +using System.Windows.Threading; +using static eDosStation.Station; using spl1 = LSWLib.CLog; namespace eDosStation { @@ -22,6 +26,8 @@ namespace eDosStation public string TestCSN { get; set; } public string TestCode { get; set; } public string Reader { get; internal set; } + public bool isElatec { get; internal set; } + public string ElatecPort { get; internal set; } public bool useTestButtons { get; set; } public byte useBeep { get; set; } public bool checkUser { get; internal set; } @@ -41,6 +47,7 @@ namespace eDosStation public double InfoScreenTimeout { get; internal set; } public bool WriteConfig32 { get; internal set; } + System.IO.Ports.SerialPort elatecReader; public string sComPort { get { return MakeComportString(ComPort); } } public const int defInst_CODE1 = 1; @@ -59,6 +66,10 @@ namespace eDosStation internal bool LogAll; internal bool WriteConfig; + public delegate void dReceivedPersID(int persid); + + public dReceivedPersID ReceivedPersid; + public ushort useBeepMK3() { if (beepMk3Map.ContainsKey(useBeep)) @@ -68,6 +79,7 @@ namespace eDosStation public Station(DataInterface mDataInterface, string Station) { const string taskName = "StationInit"; + ReceivedPersid = null; splunkLog = new spl1(Environment.MachineName); stationLog = null; dataInterface = mDataInterface; @@ -84,6 +96,14 @@ namespace eDosStation LogAll = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["LogAll"]); else LogAll = false; + + if (System.Configuration.ConfigurationManager.AppSettings["Elatec"] != null) { + ElatecPort = System.Configuration.ConfigurationManager.AppSettings["Elatec"]; + if (!string.IsNullOrWhiteSpace(ElatecPort)) isElatec = true; + } else + isElatec = false; + + if (System.Configuration.ConfigurationManager.AppSettings["WriteConfig"] != null) WriteConfig = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["WriteConfig"]); else @@ -129,7 +149,8 @@ namespace eDosStation Inst_Name1 = rs.StringOrDefault("Inst_Name1", string.Empty); Inst_Name2 = rs.StringOrDefault("Inst_Name2", string.Empty); TestCSN = rs.StringOrDefault("TestCSN", string.Empty); - Reader = rs.StringOrDefault("Reader", string.Empty); + + if (!isElatec) Reader = rs.StringOrDefault("Reader", string.Empty); else Reader = string.Empty; useTestButtons = rs.BoolOrDefault("useTestButtons", false); useBeep = rs.ByteOrDefault("useBeep", 0b00010110); doLog = rs.BoolOrDefault("doLog", false); @@ -152,7 +173,7 @@ namespace eDosStation TestCSN = System.Configuration.ConfigurationManager.AppSettings["TestCSN"]; TestCode = System.Configuration.ConfigurationManager.AppSettings["TestCode"]; Changed = true; - Reader = System.Configuration.ConfigurationManager.AppSettings["Reader"]; + if (!isElatec) Reader = System.Configuration.ConfigurationManager.AppSettings["Reader"]; else Reader = string.Empty; checkUser = false; EPDTimeOut = 10000; EPDRetries = 2; @@ -212,7 +233,10 @@ namespace eDosStation } co?.Close(); } + + DevCon = new cDevCon(ComPort, splunkLog); + if (isElatec) openElatec(); } private void CmdSetParams(SqlCommand cmd) { @@ -274,10 +298,11 @@ namespace eDosStation public void UpdateAppSettings() { - string[] Keys = { "LogAll" } ; - string[] Values = { "false" }; + string[] Keys = { "LogAll", "Elatec" } ; + string[] Values = { "false" ,"" }; Values[0] = LogAll.ToString(); + Values[1] = ElatecPort; try { var configFile = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); @@ -358,6 +383,28 @@ namespace eDosStation if (!string.IsNullOrEmpty(er)) splunkLog?.WriteSplunkLog(module, spl1.iseverity.err, er); return er; } + + public void openElatec() + { + if (isElatec) + { + elatecReader = new System.IO.Ports.SerialPort(ElatecPort, 115200); + elatecReader.DataReceived += ElatecReader_DataReceived; + elatecReader.Open(); + } + } + + private void ElatecReader_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) + { + if (ReceivedPersid != null) + { + var v = elatecReader.ReadLine(); + int PersID; + if (!int.TryParse(v, out PersID)) PersID = 0; + ReceivedPersid(PersID); + } + + } } }