diff --git a/EpdBase/EpdBase.cpp b/EpdBase/EpdBase.cpp index b1b11f2..d206eaa 100644 --- a/EpdBase/EpdBase.cpp +++ b/EpdBase/EpdBase.cpp @@ -33,11 +33,11 @@ DWORD EpdBase::Epd2U::StartCom() CommsInitialized = 1; return 1; } - if (CommsInitialized==0) + if (CommsInitialized == 0) do { InitRv = InitComms(port, 9600, 8, 0, 0); if (InitRv == 0) { - rv= GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + rv = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); Sleep(300); //DeinitComms(port); } else { @@ -47,16 +47,15 @@ DWORD EpdBase::Epd2U::StartCom() SetDiscoveryExpirationPeriod(port, DiscoveryExpirationPeriod); } } while (InitRv == 0 && mx > 0); - - if (InitRv == 0) ErrorReason = 1; - CommsInitialized = InitRv; - isBG = isNG = VersionOK = hasAlarm = false; - return ErrorReason; + + if (InitRv == 0) { ErrorReason = 1; CommsInitialized = 0; } + else { ErrorReason = 0; CommsInitialized = 1; } + isBG = isNG = VersionOK = hasAlarm = false; + return ErrorReason; } void EpdBase::Epd2U::EndCom() { - if (port > 0 && CommsInitialized==1) DeinitComms(port); CommsInitialized = 0; } @@ -86,7 +85,7 @@ int EpdBase::Epd2U::StartDiscover( int EpdTimeout) LARGE_INTEGER wt; //100 nanoseconds *10000 = millisec //union { LARGE_INTEGER li; FILETIME ft; LONGLONG ll; } t1, t2; //wt.QuadPart = -300000000LL; - wt.QuadPart = Int32x32To64(maxDiscoverTime, -10000); //10 seconden proberen + wt.QuadPart = Int32x32To64(maxDiscoverTime, -15000); //15 seconden proberen SetWaitableTimer(hWaitTimer, &wt, 0, NULL, NULL, 0); while (DeviceCount == 0 && wo != 0) //tries-- > 0 && { @@ -98,7 +97,6 @@ int EpdBase::Epd2U::StartDiscover( int EpdTimeout) wo = WaitForSingleObject(hWaitTimer, 100); if (wo == 0) {ConnectTimerFired = 1; DiscRV = 1; } } - //GetSystemTimeAsFileTime(&t2.ft); CancelWaitableTimer(hWaitTimer); } return DiscRV; @@ -113,7 +111,7 @@ int EpdBase::Epd2U::Open(DWORD DeviceID) { int rv = 0; CurrentDeviceID = DeviceID; - if (port > 0) { + if (port > 0 && CommsInitialized==1) { ConRV = Connect(DeviceID); if (ConRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); else { @@ -124,13 +122,12 @@ int EpdBase::Epd2U::Open(DWORD DeviceID) else { OpenRV = ConRV = 1; rv = 0; } return rv; } - void EpdBase::Epd2U::Close() { - if (port > 0) CloseDevice(); + if (port > 0 && CurrentDeviceID>0) CloseDevice(); CurrentDeviceID = 0; + FlushBuffers(port); } - int EpdBase::Epd2U::CloseAndSignal(WORD EndSessionControl, WORD duration) { int rv = 0; @@ -141,8 +138,6 @@ int EpdBase::Epd2U::CloseAndSignal(WORD EndSessionControl, WORD duration) Close(); return rv; } - - void EpdBase::Epd2U::DecodeFunctionFlags() { EpdType = (FunctionFlags & 0x1F00) >> 8; diff --git a/EpdBase3/Epd3Base.cpp b/EpdBase3/Epd3Base.cpp index 7bd4bc4..c1951a7 100644 --- a/EpdBase3/Epd3Base.cpp +++ b/EpdBase3/Epd3Base.cpp @@ -116,17 +116,12 @@ DWORD Epd3Base::Epd3U::StartCom() return Dll3RV; } - - - void Epd3Base::Epd3U::EndCom() { int rv; if (CommsInitialized == 1) { if (epdComsHandle != INVALID_HANDLE_VALUE) { - DisCon(0); - Dll3RV = CloseReader(epdComsHandle); if (Dll3RV) { rv = 1; @@ -205,12 +200,11 @@ int Epd3Base::Epd3U::DisCon(UINT16 alarm) else Dll3RV = Disconnect(epdComsHandle); Dll3RV = WaitForSingleObject(hCompletion, 2000); - if (Dll3RV == WAIT_OBJECT_0) rv = 0; - else if (Dll3RV == WAIT_TIMEOUT) { - rv = 2; + switch (Dll3RV) { + case WAIT_OBJECT_0: rv = 0; break; + case WAIT_TIMEOUT: rv = 2; break; + default: rv = 3; break; } - else - rv = 3; } return rv; } @@ -284,9 +278,7 @@ void Epd3Base::Epd3U::DecodeStatus() OtherAlarmBatLow = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery); OtherAlarmCarrier = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::TelemetryAlert); OtherAlarmBatVolt = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery); - hasAlarm = ((int)epd3status.FaultStatus != 0) || AlarmDoseHP07N || AlarmRateHP07N || AlarmDoseHP101G || AlarmDoseHP102G || AlarmRateHP101G || AlarmRateHP102G; - } void Epd3Base::Epd3U::SetTime() //Only R3 diff --git a/EpdBaseClr/EpdBaseClr.cpp b/EpdBaseClr/EpdBaseClr.cpp index 39c7b87..a26825b 100644 --- a/EpdBaseClr/EpdBaseClr.cpp +++ b/EpdBaseClr/EpdBaseClr.cpp @@ -14,7 +14,6 @@ EpdBaseClr::Epd2::Epd2(int port) Hp07Name = gcnew String(tHp07); isTitleNG = false; } - EpdBaseClr::Epd2::~Epd2() { if (epd != nullptr) { @@ -32,7 +31,6 @@ EpdBaseClr::Epd2::~Epd2() EpdBaseClr::Epd2::!Epd2() { } - int EpdBaseClr::Epd2::SetFeedbackSound(byte sound, UINT16 sound3) { epd->EndSessionControl = sound; @@ -72,10 +70,8 @@ int EpdBaseClr::Epd2::Connect(bool reinit, int EPDTimeout) int EpdBaseClr::Epd2::Close() { EpdID= 0; - if (epd !=nullptr) - epd->EndCom(); - if (epd3 != nullptr) - epd3->EndCom(); + if (epd !=nullptr) epd->EndCom(); + if (epd3 != nullptr) epd3->EndCom(); return 0; } int EpdBaseClr::Epd2::DecodeStatus(Epd3Base::Epd3U* epd) @@ -218,7 +214,6 @@ int EpdBaseClr::Epd2::AfterGetStatus() else rv=AfterGetStatus(epd); return rv; } - /// /// /// @@ -246,7 +241,6 @@ int EpdBaseClr::Epd2::GetDoses(EpdBase::Epd2U* epd) } return rv; } - int EpdBaseClr::Epd2::AfterGetDoses(Epd3Base::Epd3U* epd) { int rv = 0; @@ -311,8 +305,6 @@ int EpdBaseClr::Epd2::GetDoses(Epd3Base::Epd3U* epd) } return rv; } - - int EpdBaseClr::Epd2::ClearAlarms() { int rv = 0; @@ -320,7 +312,6 @@ int EpdBaseClr::Epd2::ClearAlarms() else rv = epd->ClearAlarms(); return rv; } - /// /// /// @@ -352,8 +343,6 @@ int EpdBaseClr::Epd2::SetIssued() else rv=SetIssued(epd); return rv; } - - int EpdBaseClr::Epd2::BeforeSetIssued(Epd3Base::Epd3U* epd) { int rv = 0; @@ -398,7 +387,6 @@ int EpdBaseClr::Epd2::SetIssued(Epd3Base::Epd3U* epd) if (rv != 0) SetIssuedError = epd->Error; return rv; } - int EpdBaseClr::Epd2::BeforeSetIssued(EpdBase::Epd2U* epd) { int rv = 0; @@ -466,7 +454,6 @@ int EpdBaseClr::Epd2::WriteCalibration(EpdBase::Epd2U* epd) return rv; } - int EpdBaseClr::Epd2::WriteCalibration(Epd3Base::Epd3U* epd) { epd->K1 = (float)K1; @@ -500,7 +487,6 @@ int EpdBaseClr::Epd2::ReadTresholds() rv = ReadTresholds(epd); return rv; } - int EpdBaseClr::Epd2::AfterReadTresholds(EpdBase::Epd2U* epd) { int rv = 0; @@ -544,7 +530,6 @@ int EpdBaseClr::Epd2::ReadTresholds(EpdBase::Epd2U* epd) rv = AfterReadTresholds(epd); return rv; } - int EpdBaseClr::Epd2::AfterReadTresholds(Epd3Base::Epd3U* epd) { int rv = 0; @@ -747,7 +732,7 @@ int EpdBaseClr::Epd2::SwitchCon() { int rv = 0; if (isMK3) { - if (epd3->epdComsHandle == INVALID_HANDLE_VALUE) { + if (epd3->epdComsHandle != INVALID_HANDLE_VALUE) { epd->EndCom(); Sleep(100); rv=epd3->StartCom(); @@ -791,22 +776,35 @@ void EpdBaseClr::Epd2::InitData() int EpdBaseClr::Epd2::ConnectAndStatus() { int rv = 1; - epd->EndCom(); + if (!onlyMK2) epd->EndCom(); //indien Mk2 InitData(); Sleep(100); - rv = epd3->ConnectAndStatus(tokenSourceTimeout); + if (onlyMK2) + rv = epd->ConnectAndStatus(tokenSourceTimeout); + else + rv = epd3->ConnectAndStatus(tokenSourceTimeout); if (rv==0) { - DeviceCount = epd3->DeviceCount; - EpdID = epd3->EpdID; - epd->EpdID = epd3->EpdID; - isMK3 = epd3->isMK3; - isBG = epd3->isBG; - isNG = epd3->isNG; + if (onlyMK2) { + DeviceCount = epd->DeviceCount; + EpdID = epd->EpdID; + epd->EpdID = epd->EpdID; + isMK3 = 0; + isBG = epd->isBG; + isNG = epd->isNG; + } + else { + DeviceCount = epd3->DeviceCount; + EpdID = epd3->EpdID; + epd->EpdID = epd3->EpdID; + isMK3 = epd3->isMK3; + isBG = epd3->isBG; + isNG = epd3->isNG; + } if (isMK3) { AfterGetStatus(epd3); } else { - rv = SwitchCon(); + if (!onlyMK2)rv = SwitchCon(); AfterGetStatus(epd); } if (isTitleNG != isNG) { @@ -823,6 +821,7 @@ int EpdBaseClr::Epd2::ConnectAndStatus() ConnectError = epd->Error; return rv; } + void EpdBaseClr::Epd2::WaitEpd() { int rv = 0; //start @@ -843,8 +842,9 @@ void EpdBaseClr::Epd2::WaitEpd() } return; } -System::Threading::Tasks::Task^ EpdBaseClr::Epd2::Wait(int timeout, int Retries) +System::Threading::Tasks::Task^ EpdBaseClr::Epd2::Wait(int timeout, int Retries, bool _onlyMK2) { + onlyMK2 = _onlyMK2; if (waitTask == nullptr) { tokenSourceTimeout = timeout; diff --git a/EpdBaseClr/EpdBaseClr.h b/EpdBaseClr/EpdBaseClr.h index 5ccd10f..c6161de 100644 --- a/EpdBaseClr/EpdBaseClr.h +++ b/EpdBaseClr/EpdBaseClr.h @@ -128,6 +128,7 @@ namespace EpdBaseClr { public: + bool onlyMK2; EpdBase::Epd2U *epd; Epd3Base::Epd3U* epd3; @@ -290,7 +291,7 @@ namespace EpdBaseClr { public: int SetDeIssued(); - System::Threading::Tasks::Task^ Wait(int timeout, int Retries); + System::Threading::Tasks::Task^ Wait(int timeout, int Retries, bool onlyMK2); void WaitEnd(); int GetAll(bool close); int GetAllDeissue(); @@ -302,7 +303,10 @@ namespace EpdBaseClr { int AfterGetStatus(); int SwitchCon(); void InitData(); + void WaitEpd(); + + }; } diff --git a/EpdBaseClr/EpdBaseClr.vcxproj b/EpdBaseClr/EpdBaseClr.vcxproj index f1c69b9..3c49e48 100644 --- a/EpdBaseClr/EpdBaseClr.vcxproj +++ b/EpdBaseClr/EpdBaseClr.vcxproj @@ -141,6 +141,7 @@ + @@ -151,6 +152,7 @@ Create Create + diff --git a/EpdBaseClr/EpdBaseClr.vcxproj.filters b/EpdBaseClr/EpdBaseClr.vcxproj.filters index 9eeba3a..4c84b53 100644 --- a/EpdBaseClr/EpdBaseClr.vcxproj.filters +++ b/EpdBaseClr/EpdBaseClr.vcxproj.filters @@ -24,6 +24,9 @@ Header Files + + Header Files + @@ -35,6 +38,9 @@ Source Files + + Source Files + diff --git a/EpdBaseClr/Helper.h b/EpdBaseClr/Helper.h new file mode 100644 index 0000000..e69de29 diff --git a/EpdBaseClr/VariableCapture.cpp b/EpdBaseClr/VariableCapture.cpp new file mode 100644 index 0000000..ef94aba --- /dev/null +++ b/EpdBaseClr/VariableCapture.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "VariableCapture.h" + + +generic + public ref class VariableCapture +{ +private: + Action^ delegateWithParams; + T1 item1; + + VariableCapture(Action^ delegateWithParams, T1 item1) + { + this->delegateWithParams = delegateWithParams; + this->item1 = item1; + + } + void RunDelegate() + { + this->delegateWithParams(item1); + } + +public: + static Action^ Capture(Action^ delegateWithParams, T1 item1) + { + VariableCapture^ capture = gcnew VariableCapture(delegateWithParams, item1); + return gcnew Action(capture, &VariableCapture::RunDelegate); + } +}; + + + + +generic + public ref class VariableCapture2 + { + private: + Action^ delegateWithParams; + T1 item1; + T2 item2; + + VariableCapture2(Action^ delegateWithParams, T1 item1, T2 item2) + { + this->delegateWithParams = delegateWithParams; + this->item1 = item1; + this->item2 = item2; + + } + void RunDelegate() + { + this->delegateWithParams(item1,item2); + } + + public: + static Action^ Capture(Action^ delegateWithParams, T1 item1, T2 item2) + { + VariableCapture2^ capture = gcnew VariableCapture2(delegateWithParams, item1,item2); + return gcnew Action(capture, &VariableCapture2::RunDelegate); + } + }; + + + /*Usage + Action^ delegateWithoutParams = VariableCapture::Capture(delegateWithParams, 7, "foo"); + */ \ No newline at end of file diff --git a/EpdBaseClr/VariableCapture.h b/EpdBaseClr/VariableCapture.h new file mode 100644 index 0000000..a0599ee --- /dev/null +++ b/EpdBaseClr/VariableCapture.h @@ -0,0 +1,5 @@ +#pragma once +using namespace System; + +//generic ref class VariableCapture; +//generic ref class VariableCapture2; \ No newline at end of file diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs index c27c274..162842f 100644 --- a/eDosStation/EntryBadge.xaml.cs +++ b/eDosStation/EntryBadge.xaml.cs @@ -37,7 +37,6 @@ namespace eDosStation { InitializeComponent(); dataInterface = curStation.dataInterface; - thisStation = curStation; _User = null; taskLoading = false; @@ -487,7 +486,6 @@ namespace eDosStation } public void endPage() { - dispatcherTimer?.Stop(); dispatcherTimer = null; this.Close(); @@ -504,7 +502,6 @@ namespace eDosStation } private void TaskOK_Click(object sender, RoutedEventArgs e) { - bool isOk = false; switch (TaskOK.Tag) { @@ -545,7 +542,7 @@ namespace eDosStation ResultTime = DateTime.Now.AddMilliseconds(thisStation.EPDTimeOut); dispatcherTimer.Start(); pWaitEpd.Value = pWaitEpd.Maximum = thisStation.EPDTimeOut/1000; - Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, 1); }),DispatcherPriority.Background); + Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, 1,thisStation.OnlyMK2); }),DispatcherPriority.Background); } } } diff --git a/eDosStation/EpdExit.xaml.cs b/eDosStation/EpdExit.xaml.cs index 7fa615f..0fceab8 100644 --- a/eDosStation/EpdExit.xaml.cs +++ b/eDosStation/EpdExit.xaml.cs @@ -21,13 +21,13 @@ namespace eDosStation public EpdExit(Station curStation) { InitializeComponent(); - //ep = curEP; - ep = new EpdBaseClr.Epd2(curStation.ComPort); - ep.SetFeedbackSound(curStation.useBeep,curStation.useBeepMK3()); + + //ep = new EpdBaseClr.Epd2(curStation.ComPort); + //ep.SetFeedbackSound(curStation.useBeep,curStation.useBeepMK3()); + //ep.EpdRead += Ep_EpdRead; + //ep.EpdError += Ep_EpdError; + //ep.EpdTO += Ep_EpdTO; - ep.EpdRead += Ep_EpdRead; - ep.EpdError += Ep_EpdError; - ep.EpdTO += Ep_EpdTO; thisStation = curStation; dataInterface = curStation.dataInterface; @@ -160,7 +160,25 @@ namespace eDosStation Wait.IsSelected = true; dispatcherTimer.Start(); ResultTime = DateTime.Now.AddMilliseconds(thisStation.EPDTimeOut); - Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, thisStation.EPDRetries), DispatcherPriority.Background); + + //StartEPD + if (ep == null) + try + { + ep = new EpdBaseClr.Epd2(thisStation.ComPort); + ep.SetFeedbackSound(thisStation.useBeep, thisStation.useBeepMK3()); + ep.EpdRead += Ep_EpdRead; + ep.EpdError += Ep_EpdError; + ep.EpdTO += Ep_EpdTO; + } + catch (System.Exception ex) + { + thisStation.splunkLog.WriteException(null, "StartEpd", ex); + MessageBox.Show($"{ex.Message}"); + ep = null; + } + + Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, thisStation.EPDRetries, thisStation.OnlyMK2), DispatcherPriority.Background); } private void BCloseExit_Click(object sender, RoutedEventArgs e) @@ -182,7 +200,10 @@ namespace eDosStation dispatcherTimer = null; if (ep != null) { ep.WaitEnd(); ep.Dispose(); ep = null; } } - catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } + catch (System.Exception ex) { + thisStation.splunkLog.WriteException("EpdExit", "Closing", ex); + System.Diagnostics.Debug.WriteLine(ex.Message); + } } public void endWithMessage(string message) diff --git a/eDosStation/MainWindow.xaml.cs b/eDosStation/MainWindow.xaml.cs index c4081a7..86c3d84 100644 --- a/eDosStation/MainWindow.xaml.cs +++ b/eDosStation/MainWindow.xaml.cs @@ -22,17 +22,35 @@ namespace eDosStation { InitializeComponent(); } - private void Button_Click(object sender, RoutedEventArgs e) { + string ers = string.Empty; + if (thisStation.RestartCom && (thisStation.RestartComFirst == true)) + { + ers = devcon.Restart(); + if (!string.IsNullOrEmpty(ers)) thisStation.splunkLog?.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; + } + var w = new ShowEPDDose(thisStation); w.ShowDialog(); - } + + if (thisStation.RestartCom && (thisStation.RestartComFirst == true)) + { + ers = devcon.Restart(); + if (!string.IsNullOrEmpty(ers)) thisStation.splunkLog?.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; + } + thisStation.splunkLog?.WriteSplunkLog("Show Dose done", LSWLib.CLog.iseverity.info); + } private void BEntry_Click(object sender, RoutedEventArgs e) { string ers = string.Empty; thisStation.splunkLog?.WriteSplunkLog("Entry", LSWLib.CLog.iseverity.info); + if (thisStation.RestartCom && (thisStation.RestartComFirst == true)) + { + ers = devcon.Restart(); + if (!string.IsNullOrEmpty(ers)) thisStation.splunkLog?.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; + } var w = new EntryBadge(thisStation); w.ShowDialog(); @@ -40,38 +58,41 @@ namespace eDosStation simulData = w.simulData; #endif w = null; - if (thisStation.RestartCom) + if (thisStation.RestartCom && !(thisStation.RestartComFirst==true)) { ers = devcon.Restart(); if (!string.IsNullOrEmpty(ers)) thisStation.splunkLog?.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; } thisStation.splunkLog?.WriteSplunkLog("Entry done", LSWLib.CLog.iseverity.info); } - private void BExit_Click(object sender, RoutedEventArgs e) { string ers = string.Empty; thisStation.splunkLog?.WriteSplunkLog("Exit", LSWLib.CLog.iseverity.info); + if (thisStation.RestartCom && thisStation.RestartComFirst==true) + { + ers = devcon.Restart(); + if (!string.IsNullOrEmpty(ers)) thisStation?.splunkLog.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; + } + var w = new EpdExit(thisStation); #if SimulateEPD w.simulData = simulData; #endif w.ShowDialog(); w = null; - if (thisStation.RestartCom) + if (thisStation.RestartCom && !(thisStation.RestartComFirst==true)) { ers = devcon.Restart(); if (!string.IsNullOrEmpty(ers)) thisStation?.splunkLog.WriteSplunkLog("Restart USB error", LSWLib.CLog.iseverity.err, null, ers); ; } thisStation.splunkLog?.WriteSplunkLog("Exit Done", LSWLib.CLog.iseverity.info); } - private void MenuItem_Click(object sender, RoutedEventArgs e) { Settings s = new Settings(thisStation); s.ShowDialog(); } - private void setLocalStatus() { if (!dataInterface.isOnline()) @@ -87,7 +108,6 @@ namespace eDosStation Offline = false; } } - private void setErrorStatus(string errMsg) { thisStation.splunkLog?.WriteSplunkLog("Errorstatus", LSWLib.CLog.iseverity.err, null, errMsg); @@ -95,7 +115,6 @@ namespace eDosStation Status.Foreground = Brushes.Yellow; Status.Background = Brushes.Red; } - private void Window_Loaded(object sender, RoutedEventArgs e) { bool ok = true; @@ -168,35 +187,29 @@ namespace eDosStation BgTimer_Tick(null, null); bgTimer.Start(); } - private void BgTimer_Tick(object sender, EventArgs e) { setLocalStatus(); tbTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); } - private void MEnc_Click(object sender, RoutedEventArgs e) { //string cfg = System.IO.Path.Combine(Environment.CurrentDirectory, System.AppDomain.CurrentDomain.FriendlyName ); //Config.ToggleConfigEncryption(cfg); } - private void Window_GotFocus(object sender, RoutedEventArgs e) { bgTimer.Start(); } - private void Window_LostFocus(object sender, RoutedEventArgs e) { bgTimer.Stop(); } - private void mAbout_Click(object sender, RoutedEventArgs e) { About x = new About(thisStation); x.ShowDialog(); } - private void mExit_Click(object sender, RoutedEventArgs e) { bgTimer?.Stop(); diff --git a/eDosStation/Settings.xaml b/eDosStation/Settings.xaml index f397c3a..ec8585a 100644 --- a/eDosStation/Settings.xaml +++ b/eDosStation/Settings.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:eDosStation" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" - Title="Settings" Height="338.281" Width="617.009" + Title="Settings" Height="464.627" Width="617.009" FontFamily="Segoe UI" FontSize="20" Loaded="Window_Loaded"> @@ -21,11 +21,13 @@ + + - + @@ -57,7 +59,14 @@ - - + + + + + + + + + diff --git a/eDosStation/Settings.xaml.cs b/eDosStation/Settings.xaml.cs index 6fb8705..9c291cf 100644 --- a/eDosStation/Settings.xaml.cs +++ b/eDosStation/Settings.xaml.cs @@ -62,6 +62,11 @@ namespace eDosStation thisStation.checkUser = cbCheckUsers.IsChecked != null ? cbCheckUsers.IsChecked.Value : false; thisStation.RestartCom = cbRestartCom.IsChecked != null ? cbRestartCom.IsChecked.Value : false; thisStation.EPDTimeOut = int.Parse(tEPDTimeout.Text); + + thisStation.OnlyMK2 = cbOnlyMK2.IsChecked != null ? cbOnlyMK2.IsChecked.Value : false; + thisStation.RestartComFirst = cbRestartComFirst.IsChecked != null ? cbRestartComFirst.IsChecked.Value : false; + + thisStation.Update(); this.Close(); if (thisStation.Error > 0) @@ -169,7 +174,6 @@ namespace eDosStation MessageBox.Show($"SerINstallations err {ex.Message}"); } - try { tBeep.SelectedValue = thisStation.useBeep; @@ -177,6 +181,8 @@ namespace eDosStation cbCheckUsers.IsChecked= thisStation.checkUser; cbRestartCom.IsChecked = thisStation.RestartCom; tEPDTimeout.Text = thisStation.EPDTimeOut.ToString(); + cbRestartComFirst.IsChecked = thisStation.RestartComFirst; + cbOnlyMK2.IsChecked = thisStation.OnlyMK2; } catch (System.Exception ex) { diff --git a/eDosStation/ShowEPDDose.xaml b/eDosStation/ShowEPDDose.xaml index b54d59b..296f11b 100644 --- a/eDosStation/ShowEPDDose.xaml +++ b/eDosStation/ShowEPDDose.xaml @@ -8,10 +8,9 @@ mc:Ignorable="d" Title="ShowEPDDose" Height="548.4" Width="858.8" Loaded="Window_Loaded" - Unloaded="Window_Unloaded" WindowStartupLocation="CenterScreen" FontFamily="Segoe UI" - WindowStyle="None"> + WindowStyle="None" Closing="Window_Closing"> diff --git a/eDosStation/ShowEPDDose.xaml.cs b/eDosStation/ShowEPDDose.xaml.cs index 6caa290..322f7af 100644 --- a/eDosStation/ShowEPDDose.xaml.cs +++ b/eDosStation/ShowEPDDose.xaml.cs @@ -19,19 +19,7 @@ namespace eDosStation public ShowEPDDose(Station curStation) { InitializeComponent(); - ep = new EpdBaseClr.Epd2(curStation.ComPort); - ep.SetFeedbackSound(curStation.useBeep, curStation.useBeepMK3()); - - ep.EpdRead += Ep_EpdRead; - ep.EpdError += Ep_EpdError; - ep.EpdTO += Ep_EpdTO; thisStation = curStation; - - dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal); - dispatcherTimer.Interval = TimeSpan.FromMilliseconds(thisStation.EPDTimeOut / 10); - Progress.Maximum = Progress.Value = dispatcherTimer.Interval.TotalSeconds * 10; - dispatcherTimer.Tick += CountDown; - } private void CountDown(object sender, EventArgs e) @@ -77,8 +65,6 @@ namespace eDosStation if (rv != 0) MessageBox.Show("Communication error"); - - isIssued.Text = ep.EPDIssued ? "Yes" : "no"; string sPersID = ep.WearerName.Trim(); Wearer.Text = sPersID; @@ -137,44 +123,54 @@ namespace eDosStation } else epdUserMargin.Text = "--"; - - } - - private void Window_Loaded(object sender, RoutedEventArgs e) { - Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, 1),DispatcherPriority.Background); + ep = new EpdBaseClr.Epd2(thisStation.ComPort); + ep.SetFeedbackSound(thisStation.useBeep, thisStation.useBeepMK3()); + ep.EpdRead += Ep_EpdRead; + ep.EpdError += Ep_EpdError; + ep.EpdTO += Ep_EpdTO; + + dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal); + dispatcherTimer.Interval = TimeSpan.FromMilliseconds(thisStation.EPDTimeOut / 10); + Progress.Maximum = Progress.Value = dispatcherTimer.Interval.TotalSeconds * 10; + dispatcherTimer.Tick += CountDown; + + Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, 1, thisStation.OnlyMK2),DispatcherPriority.Background); ResultTime = DateTime.Now.AddMilliseconds(thisStation.EPDTimeOut); dispatcherTimer.Start(); } private void endPage() + { + this.Close(); + } + + + private void RadButton_Click(object sender, RoutedEventArgs e) + { + endPage(); + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { dispatcherTimer?.Stop(); + dispatcherTimer = null; try { if (ep != null) { ep.WaitEnd(); ep.Dispose(); + ep = null; } - } catch (System.Exception ex) + } + catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } - this.Close(); - } - - private void Window_Unloaded(object sender, RoutedEventArgs e) - { - endPage(); - } - - private void RadButton_Click(object sender, RoutedEventArgs e) - { - endPage(); } } } diff --git a/eDosStation/Station.cs b/eDosStation/Station.cs index 0af71c4..b575a2e 100644 --- a/eDosStation/Station.cs +++ b/eDosStation/Station.cs @@ -30,6 +30,9 @@ namespace eDosStation public bool RestartCom { get; set; } public int EPDTimeOut { get; internal set; } public int EPDRetries { get; internal set; } + public bool OnlyMK2 { get; internal set; } + public bool RestartComFirst { get; internal set; } + public bool Changed = false; public int Error = 0; public string ErrorMessage; @@ -149,6 +152,22 @@ namespace eDosStation if (rs.IsDBNull(c)) RestartCom= false; else RestartCom = (bool)Values[c]; } catch { EPDRetries = 2; } + + + try + { + c = rs.GetOrdinal("RestartComFirst"); + if (rs.IsDBNull(c)) RestartComFirst = false; else RestartComFirst = (bool)Values[c]; + } + catch { RestartComFirst = false; } + + try + { + c = rs.GetOrdinal("OnlyMK2"); + if (rs.IsDBNull(c)) OnlyMK2 = false; else OnlyMK2= (bool)Values[c]; + } + catch { OnlyMK2 = false; } + } else { @@ -208,6 +227,7 @@ namespace eDosStation } catch (System.Exception ex) { + splunkLog.WriteException("Station", "GetInstallationsComments", ex); Error = 2; ErrorMessage = ex.Message; if (stationLog != null) stationLog.WriteLine($"GetStationComments error {ex.Message} {System.DateTime.Now}"); @@ -245,9 +265,12 @@ namespace eDosStation cmd.SetIfExists("EPDTimeout", EPDTimeOut); cmd.SetIfExists("EPDRetries", EPDRetries); cmd.SetIfExists("RestartCom", RestartCom); + cmd.SetIfExists("RestartComFirst", RestartComFirst); + cmd.SetIfExists("OnlyMK2", OnlyMK2); } catch (System.Exception ex) { + splunkLog.WriteException("Station", "SetParams", ex); Error = 1; ErrorMessage = ex.Message; if (stationLog != null) stationLog.WriteLine($"GetStationSettings error {ex.Message} {System.DateTime.Now}"); @@ -265,6 +288,7 @@ namespace eDosStation cmd.ExecuteNonQuery(); } catch (System.Exception ex) { + splunkLog.WriteException("Station", "UpdateToDb", ex); if (stationLog != null) stationLog.WriteLine($"UpdateToDb error {ex.Message} co {co.DataSource} {System.DateTime.Now}"); } } @@ -286,6 +310,7 @@ namespace eDosStation { Error = 1; ErrorMessage = ex.Message; + splunkLog.WriteException("Station", "Update", ex); if (stationLog != null) stationLog.WriteLine($"UpdateToDb error {ex.Message} co {co.DataSource} {System.DateTime.Now}"); } co?.Close();