diff --git a/EpdBase/EpdBase.cpp b/EpdBase/EpdBase.cpp index 27d2f20..173a3d6 100644 --- a/EpdBase/EpdBase.cpp +++ b/EpdBase/EpdBase.cpp @@ -7,6 +7,20 @@ #define RxRetryCount 5 #define TxRetryCount 5 #pragma unmanaged + +void EpdBase::Epd2U::CancelAll() +{ + SetEvent(hCancel); + //Cancel(epdComsHandle); +} +void EpdBase::Epd2U::test() +{ + const char* msg = "Processing step test..."; + if (progressCallback) { + progressCallback(StepTest, EPDStepResult); // Triggers the callback + } +} + EpdBase::Epd2U::Epd2U(int comport) { port = comport; @@ -14,6 +28,7 @@ EpdBase::Epd2U::Epd2U(int comport) isBG = isNG = VersionOK = hasAlarm = false; maxDiscoverTime = 10000; hWaitTimer = CreateWaitableTimer(NULL, TRUE, NULL); + hCancel = CreateWaitableTimer(NULL, TRUE, NULL); if (port == 0) return; SetAutoCommit(0); Error = 123; @@ -68,8 +83,18 @@ EpdBase::Epd2U::~Epd2U() { EndCom(); } + +bool EpdBase::Epd2U::isCancelled() +{ + return WaitForSingleObject(hCancel, 0) == WAIT_OBJECT_0; +} + + int EpdBase::Epd2U::StartDiscover( int EpdTimeoutms) { + ResetEvent(hCancel); + EPDStep = StepDiscovering; + maxDiscoverTime = EpdTimeoutms; if (port == 0) { DeviceCount = 1; @@ -91,18 +116,31 @@ int EpdBase::Epd2U::StartDiscover( int EpdTimeoutms) INT64 t = maxDiscoverTime; t *= (INT64)-10000; wt.QuadPart = t; // Int32x32To64(maxDiscoverTime, -10000); //15 seconden proberen SetWaitableTimer(hWaitTimer, &wt, 0, NULL, NULL, 0); - while (DeviceCount == 0 && wo != 0) //tries-- > 0 && + while (DeviceCount == 0 && wo != 0 && !isCancelled()) //tries-- > 0 && { ConnectTries++; DiscRV = Discover(port, DeviceIDs, MaxDevices, &DeviceCount); if (DiscRV == 0) { Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); } - wo = WaitForSingleObject(hWaitTimer, 100); - if (wo == 0) {ConnectTimerFired = 1; DiscRV = 1; } + else { + HANDLE handles[2]; + handles[0] = hWaitTimer; + handles[1] = hCancel; + + wo = WaitForMultipleObjects(2, handles, false, 100); + if (wo == 0) { ConnectTimerFired = 1; DiscRV = 1; EPDStepResult = EpdStepResults::OK; } + else if (wo == 1) { //Cancelled + DiscRV = 0; EPDStepResult = EpdStepResults::Error; } + else { + DiscRV = 0; EPDStepResult = EpdStepResults::Error; + } + } } CancelWaitableTimer(hWaitTimer); + } + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return DiscRV; } @@ -211,6 +249,8 @@ void EpdBase::Epd2U::DecodeStatus() WORD EpdBase::Epd2U::ReadStatus() { int rv = 0; + EPDStep = StepReadStatus; + EPDStepResult = EpdStepResults::Started; Error = 0; ReadStatusRV = 0; memset(WearerID, 0, WearerIDLength + 1); memset(WearerName, 0, WearerNameLength + 1); @@ -248,9 +288,11 @@ WORD EpdBase::Epd2U::ReadStatus() Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); ReadStatusRV = ErrorReason; rv = ErrorReason; + EPDStepResult = EpdStepResults::Error; return rv; } else { + EPDStepResult = EpdStepResults::OK; CurrentDeviceID = EpdID; time_t t = RealTime; TimeFunctions::UnixTimeToSystemTime(t, &tRealTime); @@ -283,6 +325,7 @@ WORD EpdBase::Epd2U::ReadStatus() for (int i = 0; i < WearerIDLength; i++) if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30; } + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return rv; } /// @@ -486,6 +529,9 @@ WORD EpdBase::Epd2U::PrepareForIssue() int rv = 0; if (port == 0) return 0; + EPDStep = StepPrepareIssue; + EPDStepResult = EpdStepResults::Started; + CommitRV = WriteConfig(); CommitRV = 0; ClearAlarms(); @@ -496,6 +542,10 @@ WORD EpdBase::Epd2U::PrepareForIssue() if (CommitRV) CommitRV = ClearPeakRates(); if (CommitRV) CommitRV = Commit(); if (CommitRV) rv = 0; else rv = 1; + EPDStepResult = EpdStepResults::OK; + if (progressCallback) { + progressCallback(EPDStep, EPDStepResult); + } return rv; } /// @@ -630,6 +680,7 @@ int EpdBase::Epd2U::ConnectAndStatus(int tokenSourceTimeoutms) else if (ReadStatus() != 0) rv = 1; //Read Error else rv = 0; } + return rv; } diff --git a/EpdBase/EpdBase.h b/EpdBase/EpdBase.h index a869a3e..6e94ddd 100644 --- a/EpdBase/EpdBase.h +++ b/EpdBase/EpdBase.h @@ -2,9 +2,12 @@ #pragma unmanaged #include #include "reader2.h" +#include "../EpdBase3/EpdProgress.h" #pragma unmanaged namespace EpdBase { + typedef void(*ProgressCallback)(int percentage, const char* message); + class Epd2U { @@ -16,6 +19,8 @@ namespace EpdBase bool hasFault = false; public: + + WORD port = 3; const WORD MaxDevices = 10; WORD DeviceCount = 0; @@ -253,9 +258,17 @@ namespace EpdBase int ConnectAndStatus(int tokenSourceTimeout); int IssueAndCheck(float gain); - + void CancelAll(); + bool isCancelled(); + public: HANDLE hWaitTimer = 0; + HANDLE hCancel = 0; + EpdSteps EPDStep; + EpdStepResults EPDStepResult; + typedef void (*ProgressCallback)(EpdSteps percentage, EpdStepResults result); + ProgressCallback progressCallback; + void test(); }; } diff --git a/EpdBase3/Epd3Base.cpp b/EpdBase3/Epd3Base.cpp index 4e015f6..b69fbe1 100644 --- a/EpdBase3/Epd3Base.cpp +++ b/EpdBase3/Epd3Base.cpp @@ -236,7 +236,7 @@ void Epd3Base::Epd3U::CancelAll() void Epd3Base::Epd3U::test() { const char* msg = "Processing step test..."; - progressCallback(StepTest); // Triggers the callback + progressCallback(StepTest, EPDStepResult); // Triggers the callback } DWORD Epd3Base::Epd3U::StartCom() { @@ -245,7 +245,8 @@ DWORD Epd3Base::Epd3U::StartCom() OpenRetries = 0; int step = 1; int mx = 10; - EPDStep = StepStartCom; + EPDStep = EpdSteps::StepStartCom; + EPDStepResult = EpdStepResults::Started; epdComsHandle = nullptr; if (port == 0) { CommsInitialized = 1; @@ -268,7 +269,7 @@ DWORD Epd3Base::Epd3U::StartCom() } else { - EPDStep = StepStartComFailed; + EPDStepResult = EpdStepResults::Error; SetEndReturnValue(-1); } @@ -291,14 +292,14 @@ DWORD Epd3Base::Epd3U::StartCom() CommsInitialized = 1; Dll3RV = SetMultipleDiscoveryMode(epdComsHandle, false); Dll3RV = SetResponseTimeout(epdComsHandle, ResponseTimeout); - EPDStep = StepStartComOK; + EPDStepResult = EpdStepResults::OK; } } else { Dll3RV = r_FunctionFail; } } - progressCallback(EPDStep); // Triggers the callback + progressCallback(EPDStep, EPDStepResult); // Triggers the callback if (Dll3RV) goto error; return 0; error: @@ -397,10 +398,10 @@ int Epd3Base::Epd3U::StartDiscover(int tokentimeout) Dll3RV = Connect3(epdComsHandle, Epd, true); if (Dll3RV != 0) { DiscoverError = DiscoverErrorConnecting; - EPDStep = StepConnectFailed; + EPDStepResult = EpdStepResults::Error; rv = 2; } else - EPDStep = StepConnected; + EPDStepResult = EpdStepResults::OK; } return rv; } @@ -686,10 +687,10 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) rv2 = SetEndReturnValue(rv); current->StatusDecoded = false; if (rv != 0) { - EPDStep = StepFailedStatus ; + EPDStepResult = EpdStepResults::Error; goto error; } - progressCallback(EPDStep); + if (progressCallback) progressCallback(EPDStep, EPDStepResult); IssueCount = epd3status.IssueCount; OperatingStatus = epd3status.OperatingStatus; @@ -712,17 +713,18 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) MarkNumber.Major = 0; MarkNumber.Minor=0; VersionNumber.Major = 0; - + EPDStepResult = EpdStepResults::Started; SetFunctionReturnValue(ReadEpdIdentities,0); token = BeginReadEpdIdentities(epdComsHandle, nullptr); rv = CommitAndSetRV(); if (!rv) rv = EndReadEpdIdentities(epdComsHandle, token, &EpdID32, (EpdTypes*)&EpdType, &capabilities, &MarkNumber, &VersionNumber, NULL, 0); rv = SetEndReturnValue(rv); if (rv != 0) { - EPDStep = StepReadIdentitiesFailed; + + EPDStepResult = EpdStepResults::Error; goto error; - } - progressCallback(EPDStep); + } else EPDStepResult = EpdStepResults::OK; + if (progressCallback) progressCallback(EPDStep, EPDStepResult); EpdID = EpdID32; isBG = (EpdType == EpdTypes::Mk2BetaGamma) || (EpdType == EpdTypes::Mk3BetaGamma); @@ -741,7 +743,8 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) if (!rv) rv = EndReadCounts(epdComsHandle, token, Counts, MaxCounts, &countsRead, &utc, &seconds); rv2= SetEndReturnValue(rv); if (rv) { - EPDStep = StepReadCountsFailed; + + EPDStepResult = EpdStepResults::Error; goto error; } @@ -761,7 +764,7 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) rv = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2 rv2= SetEndReturnValue(rv); if (rv) { - EPDStep = StepReadRTCFailed; + EPDStepResult = EpdStepResults::Error; goto error; } @@ -791,7 +794,7 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) if (!rv) rv = EndReadWearerId(epdComsHandle, token, &mk3WearerID); rv = SetEndReturnValue(rv); if (rv != 0) { - EPDStep = StepReadWearerIdFailed; + EPDStepResult = EpdStepResults::Error; goto error; } @@ -806,7 +809,7 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) if (!rv) rv = EndReadWearerId(epdComsHandle, token, &mk3WearerID); rv = SetEndReturnValue(rv); if (rv != 0) { - EPDStep = StepReadWearerIdFailed; + EPDStepResult = EpdStepResults::Error; goto error; } @@ -816,12 +819,15 @@ int Epd3Base::Epd3U::ReadStatus(bool onlyStatus) for (int i = 0; i < mk3WearerID.Length; i++) if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30; } + EPDStepResult = EpdStepResults::OK; + - exitroutine: +exitroutine: + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return rv; error: - //Cancel(epdComsHandle); + if (progressCallback) progressCallback(EPDStep, EPDStepResult); Error = rv; ErrorStep = step; return rv; @@ -852,26 +858,28 @@ int Epd3Base::Epd3U::ConnectAndStatus(int tokenSourceTimeout) if (dllStatus != 1) { rv = 1; //Connect error - EPDStep = StepDiscoverFailed; + + EPDStepResult = EpdStepResults::Error; } else if (DeviceCount < 1) { rv = 2; Error = r_OperationTimeout; - EPDStep = StepDiscoverFailed; + EPDStepResult = EpdStepResults::Error; } else if (isMK3) { if (ReadStatus(false) != 0) { rv = 3; //Read Error - EPDStep = StepFailedStatus; + EPDStepResult = EpdStepResults::Error; } else - EPDStep = StepGotStatus; + EPDStepResult = EpdStepResults::OK; rv = 0; } else rv = 0; //MK2 } else rv = 1; - progressCallback(EPDStep); + + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return rv; } /// @@ -1360,13 +1368,15 @@ int Epd3Base::Epd3U::ClearAlarms() Error = rv; return rv; } + WORD Epd3Base::Epd3U::PrepareForIssue() { int rv = 0; int step = 0; if (port == 0) return 0; - + EPDStep = StepPrepareIssue; + EPDStepResult = EpdStepResults::Started; step = 2; if (WriteConfig32) { rv = WriteConfig(); @@ -1378,7 +1388,6 @@ WORD Epd3Base::Epd3U::PrepareForIssue() if (!isConnected) rv = ReOpenDev(); - step = 4; if (!DetectorsOn) { token = BeginEpdOnOff(epdComsHandle, 1, nullptr); @@ -1390,25 +1399,31 @@ WORD Epd3Base::Epd3U::PrepareForIssue() step = 5; rv = ClearAlarms(); - if (rv != 0) + if (rv != 0) { + EPDStepResult = EpdStepResults::Error; goto error; + } step = 4; rv = ClearDoses(); if (rv != 0) + { + EPDStepResult = EpdStepResults::Error; goto error; + } + EPDStepResult = EpdStepResults::OK; OutputDebugStringA("**** After clear ****\n"); Disconnect(epdComsHandle); Sleep(SleepAfterClear); - + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return rv; error: DebugWrite("**** After clear step %d error %d ****\n", step, rv); - ErrorStep = step; Error = rv; + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return rv; } WORD Epd3Base::Epd3U::ReadAlarmConfig() { @@ -1491,7 +1506,9 @@ error: WORD Epd3Base::Epd3U::DeIssue() { int r = 1; - + EPDStep = StepDeIssue; + EPDStepResult = EpdStepResults::Started; + if (port == 0) return 0; if (CurrentDeviceID == 0) return 0; @@ -1585,13 +1602,18 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru if (!PrepareDone) { r = PrepareForIssue(); if (r) + EPDStepResult = EpdStepResults::Error; goto error; } + EPDStep = StepIssue; + EPDStepResult = EpdStepResults::Started; step = 1; if (!isConnected) r = ReOpenDev(); - if (r) + if (r) { + EPDStepResult = EpdStepResults::Error; goto error; + } step = 4; @@ -1599,7 +1621,7 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru token = BeginEpdOnOff(epdComsHandle, 1, nullptr); r = CommitAndEnd2RV(EndEpdOnOff, token); -#ifdef ProtectSession +#ifdef ProtectSession if (isMK3) { Control = 1; // EndSessionControl; //SetFunctionReturnValue(EnableProtectedSession, 1); @@ -1611,10 +1633,14 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru Control = 0; #endif + step = 2; r = WriteAlarmTresholds(); if (r != 0) + { + EPDStepResult = EpdStepResults::Error; goto error; + } step = 3; if (!isConnected) @@ -1623,7 +1649,10 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru step = 4; r = WriteWearer(); if (r != 0) + { + EPDStepResult = EpdStepResults::Error; goto error; + } tries = 1; SetFunctionReturnValue(eFunctions::IssueEPD,0); @@ -1639,9 +1668,12 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru r = CommitAndEnd2RV(EndIssueEPD, token); } if (r) + { + EPDStepResult = EpdStepResults::Error; goto error; + } EPDIssued = 1; - + EPDStepResult = EpdStepResults::OK; step = 6; if (isMK3) { @@ -1649,11 +1681,13 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru } step = 7; + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return r; error: ErrorStep = step; Error = r; + if (progressCallback) progressCallback(EPDStep, EPDStepResult); return r; } @@ -1830,6 +1864,7 @@ int Epd3Base::Epd3U::IssueAndCheck(float gain, float ChirpRate) if (!isConnected) rv = ReOpenDev(); + rv = ReadStatusOnly(); if (rv) rv2=1; @@ -2042,7 +2077,7 @@ int Epd3Base::Epd3U::WriteConfig(void) if (r != 0) Error = r; - Error = r; + } else Error = r; diff --git a/EpdBase3/Epd3Base.h b/EpdBase3/Epd3Base.h index b6dbacd..0f5c6e1 100644 --- a/EpdBase3/Epd3Base.h +++ b/EpdBase3/Epd3Base.h @@ -7,6 +7,7 @@ #include "EpdCommon.h" #include "Epd3.h" #include "Epd2.h" +#include "EpdProgress.h" #pragma unmanaged @@ -41,31 +42,7 @@ namespace Epd3Base { }; typedef void(*ProgressCallback)(int percentage, const char* message); - enum EpdSteps - { - StepTest, - StepStartCom, - StepStartComFailed, - StepStartComOK, - StepInitialized, - StepDiscovering, - StepDiscoverFailed, - StepDiscovered, - StepConnecting, - StepConnected, - StepConnectFailed, - StepReadStatus, - StepGotStatus, - StepFailedStatus, - StepReadIdentities, - StepReadIdentitiesFailed, - StepReadCounts, - StepReadCountsFailed, - StepReadRTC, - StepReadRTCFailed, - StepReadWearerId, - StepReadWearerIdFailed - }; + class Epd3U { @@ -129,6 +106,7 @@ namespace Epd3Base { DiscoverErrorCodes DiscoverError; EpdSteps EPDStep; + EpdStepResults EPDStepResult; //OperatingStatus BYTE DetectorsOn = 0; @@ -388,7 +366,7 @@ namespace Epd3Base { public: char DiagnosticsWrite[DiagnosticsWriteSize]; - typedef void (*ProgressCallback)(EpdSteps percentage); + typedef void (*ProgressCallback)(EpdSteps percentage, EpdStepResults result); ProgressCallback progressCallback; void test(); }; diff --git a/EpdBase3/EpdBase3.vcxproj b/EpdBase3/EpdBase3.vcxproj index 34703c6..2fe0614 100644 --- a/EpdBase3/EpdBase3.vcxproj +++ b/EpdBase3/EpdBase3.vcxproj @@ -163,6 +163,7 @@ + diff --git a/EpdBase3/EpdBase3.vcxproj.filters b/EpdBase3/EpdBase3.vcxproj.filters index 77d98db..5ece1c0 100644 --- a/EpdBase3/EpdBase3.vcxproj.filters +++ b/EpdBase3/EpdBase3.vcxproj.filters @@ -42,6 +42,9 @@ Header Files + + Header Files + diff --git a/EpdBase3/EpdProgress.h b/EpdBase3/EpdProgress.h new file mode 100644 index 0000000..9536de9 --- /dev/null +++ b/EpdBase3/EpdProgress.h @@ -0,0 +1,29 @@ +#pragma once +enum EpdSteps +{ + StepTest=0, + StepStartCom=1, + + StepInitialized=2, + StepDiscovering=3, + + StepConnecting=4, + StepReadStatus=5, + StepReadIdentities=6, + StepReadCounts=7, + StepReadRTC=8 , + StepReadWearerId=9, + StepPrepareIssue = 10, + StepIssue=11, + StepDeIssue=12 + +}; + +enum EpdStepResults +{ + None=0, + Started=1, + OK=2, + Error + +}; \ No newline at end of file diff --git a/EpdBaseClr/EpdBaseClr.cpp b/EpdBaseClr/EpdBaseClr.cpp index fee3ecc..8d3b9af 100644 --- a/EpdBaseClr/EpdBaseClr.cpp +++ b/EpdBaseClr/EpdBaseClr.cpp @@ -8,8 +8,9 @@ typedef void (*ProgressCallback)(int percentage, const char* message); void EpdBaseClr::Epd2::OnCancelRequested() { if (epd3 != nullptr) epd3->CancelAll(); - //if (epd != nullptr) epd->Cancel(); + if (epd != nullptr) epd->CancelAll(); } + bool EpdBaseClr::Epd2::HasStepError() { return (bool)epd3->HasStepError; @@ -33,11 +34,13 @@ int EpdBaseClr::Epd2::GetSteps() return nsteps; } -void EpdBaseClr::Epd2::OnProgress(Epd3Base::EpdSteps step) +void EpdBaseClr::Epd2::OnProgress(EpdSteps step, EpdStepResults result) { // Handle the progress info here (e.g., print or log it) - System::Console::WriteLine("Step: " + ((int)step).ToString() ); - if (_EpdProgress) _EpdProgress(this,step); + System::Console::WriteLine("Step: " + ((int)step).ToString() + ", Result: " + ((int)result).ToString()); + if (_EpdProgress) { + _EpdProgress(this, step, result);Sleep(100); + } } EpdBaseClr::Epd2::Epd2(int port, bool OnlyMK2) @@ -67,6 +70,10 @@ EpdBaseClr::Epd2::Epd2(int port, bool OnlyMK2) epd3->progressCallback = static_cast(ip.ToPointer()); epd3->test(); } + if (epd != nullptr) { + epd->progressCallback = static_cast(ip.ToPointer()); + epd->test(); + } } EpdBaseClr::Epd2::~Epd2() @@ -1072,7 +1079,6 @@ void EpdBaseClr::Epd2::WaitEnd() delete waitTask; waitTask = nullptr; } - Close(); } } diff --git a/EpdBaseClr/EpdBaseClr.h b/EpdBaseClr/EpdBaseClr.h index a0641b8..b8b6187 100644 --- a/EpdBaseClr/EpdBaseClr.h +++ b/EpdBaseClr/EpdBaseClr.h @@ -14,7 +14,7 @@ namespace EpdBaseClr { [UnmanagedFunctionPointer(CallingConvention::Cdecl)] - public delegate void ProgressCallbackDelegate(Epd3Base::EpdSteps step); + public delegate void ProgressCallbackDelegate(EpdSteps step, EpdStepResults result); const char* cEpdError = "Setreader Error"; ref class Epd2; @@ -141,12 +141,12 @@ namespace EpdBaseClr { const wchar_t* tHp10G = L"HP10G"; public: - void OnProgress(Epd3Base::EpdSteps step); + void OnProgress(EpdSteps step, EpdStepResults result); ProgressCallbackDelegate^ progressDelegate; delegate void dEpdRead(Epd2^ Sender, EpdEventArgs^ e); delegate void dEpdTO(Epd2^ Sender, EpdTOEventArgs^ e); delegate void dEpdError(Epd2^ Sender, EpdErrorEventArgs^ e); - delegate void dEpdProgress(Epd2^ Sender, int step); + delegate void dEpdProgress(Epd2^ Sender, int step, int result); dEpdRead^ _EpdRead; dEpdTO^ _EpdTO; @@ -421,32 +421,28 @@ namespace EpdBaseClr { public ref class EpdHelpers { public: - static System::String^ EpdStepToString(Epd3Base::EpdSteps step) + static System::String^ EpdStepToString(EpdSteps step) { switch (step) { - case Epd3Base::StepTest: return L"Test"; - case Epd3Base::StepStartCom: return L"StartCom"; - case Epd3Base::StepStartComFailed: return L"StartCom Failed"; - case Epd3Base::StepStartComOK: return L"StartCom OK"; - case Epd3Base::StepInitialized: return L"Initialized"; - case Epd3Base::StepDiscovering: return L"Discovering"; - case Epd3Base::StepDiscoverFailed: return L"Discover Failed"; - case Epd3Base::StepDiscovered: return L"Discovered"; - case Epd3Base::StepConnecting: return L"Connecting"; - case Epd3Base::StepConnected: return L"Connected"; - case Epd3Base::StepConnectFailed: return L"Connect Failed"; - case Epd3Base::StepReadStatus: return L"ReadStatus"; - case Epd3Base::StepGotStatus: return L"Got Status"; - case Epd3Base::StepFailedStatus: return L"Failed Status"; - case Epd3Base::StepReadIdentities: return L"Read Identities"; - case Epd3Base::StepReadIdentitiesFailed: return L"Read Identities Failed"; - case Epd3Base::StepReadCounts: return L"Read Counts"; - case Epd3Base::StepReadCountsFailed: return L"Read Counts Failed"; - case Epd3Base::StepReadRTC: return L"Read RTC"; - case Epd3Base::StepReadRTCFailed: return L"Read RTC Failed"; - case Epd3Base::StepReadWearerId: return L"Read WearerId"; - case Epd3Base::StepReadWearerIdFailed: return L"Read WearerId Failed"; + case StepTest: return L"Test"; + case StepStartCom: return L"StartCom"; + + case StepInitialized: return L"Initialized"; + case StepDiscovering: return L"Discovering"; + + case StepConnecting: return L"Connecting"; + + case StepReadStatus: return L"ReadStatus"; + + case StepReadIdentities: return L"Read Identities"; + + case StepReadCounts: return L"Read Counts"; + + case StepReadRTC: return L"Read RTC"; + + case StepReadWearerId: return L"Read WearerId"; + default: return L"Unknown"; } } diff --git a/eDosStation/DosimeterDisplay.xaml b/eDosStation/DosimeterDisplay.xaml new file mode 100644 index 0000000..00c4f2d --- /dev/null +++ b/eDosStation/DosimeterDisplay.xaml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eDosStation/DosimeterDisplay.xaml.cs b/eDosStation/DosimeterDisplay.xaml.cs new file mode 100644 index 0000000..62dc134 --- /dev/null +++ b/eDosStation/DosimeterDisplay.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace eDosStation +{ + /// + /// Interaction logic for DosimeterDisplay.xaml + /// + public partial class DosimeterDisplay : UserControl + { + public static readonly RoutedEvent CloseClickedEvent = + EventManager.RegisterRoutedEvent( + nameof(CloseClicked), + RoutingStrategy.Bubble, + typeof(RoutedEventHandler), + typeof(DosimeterDisplay)); + + public event RoutedEventHandler CloseClicked + { + add => AddHandler(CloseClickedEvent, value); + remove => RemoveHandler(CloseClickedEvent, value); + } + public DosimeterDisplay() + { + InitializeComponent(); + } + + + private void RadButton_Click(object sender, RoutedEventArgs e) + { + // Raise the event so parent controls/windows know "Close" was clicked + RaiseEvent(new RoutedEventArgs(CloseClickedEvent)); + } + } +} \ No newline at end of file diff --git a/eDosStation/EntryBadge.xaml b/eDosStation/EntryBadge.xaml index 8185e56..9cf9b8d 100644 --- a/eDosStation/EntryBadge.xaml +++ b/eDosStation/EntryBadge.xaml @@ -299,6 +299,7 @@ + @@ -382,6 +383,11 @@ + + + + + diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs index 91ab17a..7af6218 100644 --- a/eDosStation/EntryBadge.xaml.cs +++ b/eDosStation/EntryBadge.xaml.cs @@ -9,11 +9,13 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Resources; using System.Windows.Threading; +using Telerik.Windows.Controls; namespace eDosStation { /// /// Interaction logic for EntryBadge.xaml + /// startEPDRead /// /// @@ -979,6 +981,7 @@ namespace eDosStation ep.EpdRead += Ep_EpdRead; ep.EpdError += Ep_EpdError; ep.EpdTO += Ep_EpdTO; + ep.EpdProgress += Ep_EpdProgress; } catch (System.Exception ex) { @@ -1017,10 +1020,36 @@ namespace eDosStation } } + private void Ep_EpdProgress(EpdBaseClr.Epd2 Sender, int step, int result) + { + System.Diagnostics.Debug.WriteLine($"EPD Progress step:{step} result:{result}"); + int index = -1; + switch (step) + { + case 4: index = 0; break; + case 5: index = 1; break; + case 10: index = 2; break; + } + if (index >= 0 && index < stepEPD.Items.Count) + { + this.Dispatcher.Invoke(() => + { + stepEPD.SelectedIndex = index; + + // Optional: Force the progress step visual item to update status if needed + if (stepEPD.ItemContainerGenerator.ContainerFromIndex(index) is FrameworkElement container) + { + container.UpdateLayout(); + } + }, System.Windows.Threading.DispatcherPriority.Normal); + } + } + 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(); diff --git a/eDosStation/EpdExit.xaml b/eDosStation/EpdExit.xaml index f009426..c43a88f 100644 --- a/eDosStation/EpdExit.xaml +++ b/eDosStation/EpdExit.xaml @@ -28,6 +28,7 @@ + @@ -39,6 +40,13 @@ + + + + + + + diff --git a/eDosStation/EpdExit.xaml.cs b/eDosStation/EpdExit.xaml.cs index 65f479c..f823dd0 100644 --- a/eDosStation/EpdExit.xaml.cs +++ b/eDosStation/EpdExit.xaml.cs @@ -59,6 +59,32 @@ namespace eDosStation Dispatcher.InvokeAsync(() => LoadDoses()); } + private void Ep_EpdProgress(EpdBaseClr.Epd2 Sender, int step, int result) + { + System.Diagnostics.Debug.WriteLine($"EPD Progress step:{step} result:{result}"); + int index = -1; + switch (step) + { + case 4: index = 0; break; + case 5: index = 1; break; + case 12: index = 2; break; + } + + if (index >= 0 && index < stepEPD.Items.Count) + { + this.Dispatcher.Invoke(() => + { + stepEPD.SelectedIndex = index; + + // Optional: Force the progress step visual item to update status if needed + if (stepEPD.ItemContainerGenerator.ContainerFromIndex(index) is FrameworkElement container) + { + container.UpdateLayout(); + } + }, System.Windows.Threading.DispatcherPriority.Normal); + } + } + private void startEPDRead() { EpdReading = true; bCancel.IsEnabled = false; @@ -228,6 +254,7 @@ namespace eDosStation epdDevice.EpdRead += Ep_EpdRead; epdDevice.EpdError += Ep_EpdError; epdDevice.EpdTO += Ep_EpdTO; + epdDevice.EpdProgress += Ep_EpdProgress; } catch (System.Exception ex) { diff --git a/eDosStation/HPHToolbox.xaml.cs b/eDosStation/HPHToolbox.xaml.cs index 90dcb3c..4be86d9 100644 --- a/eDosStation/HPHToolbox.xaml.cs +++ b/eDosStation/HPHToolbox.xaml.cs @@ -19,7 +19,7 @@ namespace eDosStation EpdBaseClr.Epd2 ep; DispatcherTimer dispatcherTimer; private DateTime ResultTime; - private User thisUser; + //private User thisUser; #pragma warning disable CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used private bool EpdReading; #pragma warning restore CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used diff --git a/eDosStation/MainWindow.xaml.cs b/eDosStation/MainWindow.xaml.cs index 947e220..586cb26 100644 --- a/eDosStation/MainWindow.xaml.cs +++ b/eDosStation/MainWindow.xaml.cs @@ -42,7 +42,7 @@ namespace eDosStation { thisStation.DeviceRestart(); } - var w = new ShowEPDDose(thisStation); + var w = new ShowEPDDose2(thisStation); w.ShowDialog(); diff --git a/eDosStation/Resources/BuildDate.txt b/eDosStation/Resources/BuildDate.txt index d8604e4..ef14887 100644 --- a/eDosStation/Resources/BuildDate.txt +++ b/eDosStation/Resources/BuildDate.txt @@ -1 +1 @@ -Sat 08/01/2026 17:11:30.39 +Sun 08/02/2026 15:56:50.38 diff --git a/eDosStation/ShowEPDDose.xaml b/eDosStation/ShowEPDDose.xaml index b64f69e..6c5c901 100644 --- a/eDosStation/ShowEPDDose.xaml +++ b/eDosStation/ShowEPDDose.xaml @@ -105,8 +105,18 @@ - - + + + + + + + + + + + + diff --git a/eDosStation/ShowEPDDose.xaml.cs b/eDosStation/ShowEPDDose.xaml.cs index bef3ad2..535825b 100644 --- a/eDosStation/ShowEPDDose.xaml.cs +++ b/eDosStation/ShowEPDDose.xaml.cs @@ -58,7 +58,8 @@ namespace eDosStation private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e) { System.Diagnostics.Debug.WriteLine("ERROR "); - Dispatcher.InvokeAsync(() => { + Dispatcher.InvokeAsync(() => + { MessageBox.Show($"EPD Error {e.returnValue} {e.ErrorRV} {e.ErrorStep}"); Dispatcher.InvokeAsync(() => { SetTimedOutAndEnd(); }); }); @@ -66,10 +67,25 @@ namespace eDosStation private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e) { - EpdReading = false; + EpdReading = false; dispatcherTimer?.Stop(); Dispatcher.InvokeAsync(() => LoadDoses()); } + private void Ep_EpdProgress(EpdBaseClr.Epd2 Sender, int step, int result) + { + System.Diagnostics.Debug.WriteLine($"EPD Progress step:{step} result:{result}"); + int index = -1; + switch (step) + { + case 4: index = 0; break; + case 5: index = 1; break; + case 10: index = 2; break; + } + if (index >= 0 && index < stepEPD.Items.Count) + { + this.Dispatcher.InvokeAsync(new Action(() => stepEPD.SelectedIndex = 1), DispatcherPriority.Render); + } + } #endregion @@ -90,7 +106,8 @@ namespace eDosStation if (ep.eDoshasAlarm) { hasAlarm.Text = "Yes"; - } else + } + else hasAlarm.Text = "No"; epdid.Text = ep.EpdID.ToString(); @@ -107,24 +124,27 @@ namespace eDosStation HpDose07.Text = $"{ep.Hp07:0.00} µSv"; HpDose10.Text = $"{ep.Hp10:0.00} µSv"; - HP10AlarmDose1l.Text = "Warning "+ ep.Hp10Name; - HP10AlarmDose2l.Text = "Alarm "+ ep.Hp10Name; - HP07AlarmDosel.Text = "Alarm "+ ep.Hp07Name; + HP10AlarmDose1l.Text = "Warning " + ep.Hp10Name; + HP10AlarmDose2l.Text = "Alarm " + ep.Hp10Name; + HP07AlarmDosel.Text = "Alarm " + ep.Hp07Name; HP10AlarmDose1.Text = $"{ep.Hp10THDose1:0.00} µSv"; HP10AlarmDose2.Text = $"{ep.Hp10THDose2:0.00} µSv"; HP07AlarmDose.Text = $"{ep.Hp07THDose:0.00} µSv"; - HpPeak07l.Text = ep.Hp07Name +" Peak"; + HpPeak07l.Text = ep.Hp07Name + " Peak"; HpPeak07.Text = $"{ep.Hp07Peak:0.00} µSv {ep.Hp07PeakTime:yyyy-MM-dd HH:mm} "; HpPeak10l.Text = ep.Hp10Name + " Peak"; HpPeak10.Text = $"{ep.Hp10Peak:0.00} µSv {ep.Hp10PeakTime:yyyy-MM-dd HH:mm} "; - if (ep.isNG) { + if (ep.isNG) + { lNGain.Visibility = NGain.Visibility = Visibility.Visible; NGain.Text = ep.NGgain.ToString("#.##"); - } else { + } + else + { lNGain.Visibility = NGain.Visibility = Visibility.Hidden; } @@ -132,10 +152,10 @@ namespace eDosStation { try { - thisUser = thisStation.dataInterface.GetUser(string.Empty, sPersID,false); + thisUser = thisStation.dataInterface.GetUser(string.Empty, sPersID, false); epdUserMargin.Text = thisUser.Margin.ToString(); } - catch + catch { } } @@ -151,11 +171,12 @@ namespace eDosStation FinalTimeOut = false; EpdReading = false; - ep = new EpdBaseClr.Epd2(thisStation.ComPort,thisStation.OnlyMK2); + ep = new EpdBaseClr.Epd2(thisStation.ComPort, thisStation.OnlyMK2); ep.SetFeedbackSound(thisStation.useBeep, thisStation.useBeepMK3()); ep.EpdRead += Ep_EpdRead; ep.EpdError += Ep_EpdError; ep.EpdTO += Ep_EpdTO; + ep.EpdProgress += Ep_EpdProgress; dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background); dispatcherTimer.Interval = thisStation.ScreenProgressBarInterval; @@ -172,6 +193,10 @@ namespace eDosStation //Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, 1),DispatcherPriority.Background); //dispatcherTimer.Start(); } + + + + private void startEPDRead() { EpdReading = true; bEpdCancel.IsEnabled = false; @@ -207,7 +232,7 @@ namespace eDosStation { this.Close(); } - + private void RadButton_Click(object sender, RoutedEventArgs e) { @@ -218,7 +243,7 @@ namespace eDosStation { dispatcherTimer?.Stop(); dispatcherTimer = null; - EpdReading = true; + EpdReading = true; try { if (ep != null) @@ -233,5 +258,11 @@ namespace eDosStation System.Diagnostics.Debug.WriteLine(ex.Message); } } + + + private void DosimeterView_CloseClicked(object sender, RoutedEventArgs e) + { + this.Close(); + } } -} +} \ No newline at end of file diff --git a/eDosStation/ShowEPDDose2.xaml b/eDosStation/ShowEPDDose2.xaml new file mode 100644 index 0000000..e0f10d6 --- /dev/null +++ b/eDosStation/ShowEPDDose2.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/eDosStation/ShowEPDDose2.xaml.cs b/eDosStation/ShowEPDDose2.xaml.cs new file mode 100644 index 0000000..98c0b8e --- /dev/null +++ b/eDosStation/ShowEPDDose2.xaml.cs @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Windows.Threading; + +namespace eDosStation +{ + /// + /// Interaction logic for ShowEPDDose2.xaml + /// + public partial class ShowEPDDose2 : Window + { + private enum eEntryState { none, getepd, epdtimeout, epdError, epdOK, final }; +#pragma warning disable CS0414 // The field 'ShowEPDDose.EntryState' is assigned but its value is never used + private eEntryState EntryState; +#pragma warning restore CS0414 // The field 'ShowEPDDose.EntryState' is assigned but its value is never used + + Station thisStation; + EpdBaseClr.Epd2 ep; + DispatcherTimer dispatcherTimer; + private DateTime ResultTime; + private User thisUser; +#pragma warning disable CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used + private bool EpdReading; +#pragma warning restore CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used + private bool FinalTimeOut; + + public ShowEPDDose2(Station curStation) + { + InitializeComponent(); + thisStation = curStation; + EpdReading = false; + FinalTimeOut = false; + EntryState = eEntryState.none; + } + + + private void CountDown(object sender, EventArgs e) + { + double v = (ResultTime - DateTime.Now).TotalSeconds; + if (v > DosimeterView.Progress.Minimum) + { + DosimeterView.Progress.Value = v; + DosimeterView.ProgressText.Text = ((int)v).ToString(); + } + else + { + SetTimedOutAndEnd(); + } + } + + #region EPD Callback + private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdTOEventArgs e) + { + System.Diagnostics.Debug.WriteLine("TIME OUT"); + DosimeterView.Dispatcher.InvokeAsync(() => { SetTimedOutAndEnd(); }); + } + + private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e) + { + System.Diagnostics.Debug.WriteLine("ERROR "); + DosimeterView.Dispatcher.InvokeAsync(() => { + MessageBox.Show($"EPD Error {e.returnValue} {e.ErrorRV} {e.ErrorStep}"); + DosimeterView.Dispatcher.InvokeAsync(() => { SetTimedOutAndEnd(); }); + }); + } + + private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e) + { + EpdReading = false; + dispatcherTimer?.Stop(); + DosimeterView.Dispatcher.InvokeAsync(() => LoadDoses()); + } + private void Ep_EpdProgress(EpdBaseClr.Epd2 Sender, int step, int result) + { + System.Diagnostics.Debug.WriteLine($"EPD Progress step:{step} result:{result}"); + int index = -1; + switch (step) + { + case 4: index = 0; break; + case 5: index = 1; break; + case 10: index = 2; break; + } + if (index >= 0 && index <= DosimeterView.stepEPD.Items.Count) + { + this.Dispatcher.Invoke(() => + { + DosimeterView.stepEPD.SelectedIndex = index; + + // Optional: Force the progress step visual item to update status if needed + if (DosimeterView.stepEPD.ItemContainerGenerator.ContainerFromIndex(index) is FrameworkElement container) + { + container.UpdateLayout(); + } + }, System.Windows.Threading.DispatcherPriority.Normal); + } + } + + #endregion + + private void LoadDoses() + { + int rv = 0; + if (ep == null) return; + rv = ep.GetAll(true); + if (rv != 0) MessageBox.Show("Communication error"); + + DosimeterView.isIssued.Text = ep.EPDIssued ? "Yes" : "no"; + string sPersID = ep.WearerName.Trim(); + DosimeterView.Wearer.Text = sPersID; + DosimeterView.EpdVisit.Text = ep.WearerID.ToString(); + + DosimeterView.HardVersion.Text = ep.HardVersion.ToString() + '.' + ep.HardVersionMinor.ToString(); // ep.SoftVersion.ToString(); + + if (ep.eDoshasAlarm) + { + DosimeterView.hasAlarm.Text = "Yes"; + } + else + DosimeterView.hasAlarm.Text = "No"; + + DosimeterView.epdid.Text = ep.EpdID.ToString(); + var stype = new StringBuilder(); + if (ep.isMK3) stype.Append("MK3 "); else stype.Append("MK2 "); + if (ep.isBG) stype.Append(" BG"); else stype.Append(" NG"); + DosimeterView.epdtype.Text = stype.ToString(); + + Decoder.AlarmToTextBox(DosimeterView.sAlarm, ep); + + DosimeterView.HpDose07l.Text = ep.Hp07Name; + DosimeterView.HpDose10l.Text = ep.Hp10Name; + + DosimeterView.HpDose07.Text = $"{ep.Hp07:0.00} µSv"; + DosimeterView.HpDose10.Text = $"{ep.Hp10:0.00} µSv"; + + DosimeterView.HP10AlarmDose1l.Text = "Warning " + ep.Hp10Name; + DosimeterView.HP10AlarmDose2l.Text = "Alarm " + ep.Hp10Name; + DosimeterView.HP07AlarmDosel.Text = "Alarm " + ep.Hp07Name; + + DosimeterView.HP10AlarmDose1.Text = $"{ep.Hp10THDose1:0.00} µSv"; + DosimeterView.HP10AlarmDose2.Text = $"{ep.Hp10THDose2:0.00} µSv"; + DosimeterView.HP07AlarmDose.Text = $"{ep.Hp07THDose:0.00} µSv"; + + DosimeterView.HpPeak07l.Text = ep.Hp07Name + " Peak"; + DosimeterView.HpPeak07.Text = $"{ep.Hp07Peak:0.00} µSv {ep.Hp07PeakTime:yyyy-MM-dd HH:mm} "; + + DosimeterView.HpPeak10l.Text = ep.Hp10Name + " Peak"; + DosimeterView.HpPeak10.Text = $"{ep.Hp10Peak:0.00} µSv {ep.Hp10PeakTime:yyyy-MM-dd HH:mm} "; + + if (ep.isNG) + { + DosimeterView.lNGain.Visibility = DosimeterView.NGain.Visibility = Visibility.Visible; + DosimeterView.NGain.Text = ep.NGgain.ToString("#.##"); + } + else + { + DosimeterView.lNGain.Visibility = DosimeterView.NGain.Visibility = Visibility.Hidden; + } + + if (!string.IsNullOrEmpty(sPersID)) + { + try + { + thisUser = thisStation.dataInterface.GetUser(string.Empty, sPersID, false); + DosimeterView.epdUserMargin.Text = thisUser.Margin.ToString(); + } + catch + { + } + } + else + DosimeterView.epdUserMargin.Text = "--"; + + DosimeterView.Progress.Visibility = Visibility.Collapsed; + DosimeterView.bEpdCancel.IsEnabled = true; + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + FinalTimeOut = false; + EpdReading = false; + + ep = new EpdBaseClr.Epd2(thisStation.ComPort, thisStation.OnlyMK2); + ep.SetFeedbackSound(thisStation.useBeep, thisStation.useBeepMK3()); + ep.EpdRead += Ep_EpdRead; + ep.EpdError += Ep_EpdError; + ep.EpdTO += Ep_EpdTO; + ep.EpdProgress += Ep_EpdProgress; + + dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background); + dispatcherTimer.Interval = thisStation.ScreenProgressBarInterval; + dispatcherTimer.Tick += CountDown; + ResultTime = DateTime.Now.AddSeconds(thisStation.ScreenEPDTimeout); + DosimeterView.Progress.Value = DosimeterView.Progress.Maximum = thisStation.ScreenEPDTimeout; + dispatcherTimer.Start(); + startEPDRead(); + + //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),DispatcherPriority.Background); + //dispatcherTimer.Start(); + } + + + + + private void startEPDRead() + { + EpdReading = true; DosimeterView.bEpdCancel.IsEnabled = false; + DosimeterView.Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, thisStation.EPDRetries); }), DispatcherPriority.Background); + } + + private void SetTimedOutAndEnd() + { + if (!FinalTimeOut) + { + DosimeterView.bEpdCancel.IsEnabled = true; + FinalTimeOut = true; + dispatcherTimer?.Stop(); + DosimeterView.Progress.Value = 0; + DosimeterView.Progress.Background = System.Windows.Media.Brushes.Red; + statusEPD.Content = "Time out"; + DosimeterView.tWaitFor.Text = "Lezer niet gevonden !"; + dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background); + dispatcherTimer.Tick += ShowAndEnd; + dispatcherTimer.Interval = thisStation.ShowTimeoutTime; + dispatcherTimer.Start(); + } + } + + private void ShowAndEnd(object sender, EventArgs e) + { + dispatcherTimer?.Stop(); + dispatcherTimer = null; + endPage(); + } + + private void endPage() + { + this.Close(); + } + private void DosimeterView_CloseClicked(object sender, RoutedEventArgs e) + { + endPage(); + } + + private void RadButton_Click(object sender, RoutedEventArgs e) + { + endPage(); + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + dispatcherTimer?.Stop(); + dispatcherTimer = null; + EpdReading = true; + try + { + if (ep != null) + { + ep.WaitEnd(); + ep.Dispose(); + ep = null; + } + } + catch (System.Exception ex) + { + System.Diagnostics.Debug.WriteLine(ex.Message); + } + } + } + +} + diff --git a/eDosStation/eDosStation.csproj b/eDosStation/eDosStation.csproj index fdb2d64..400f865 100644 --- a/eDosStation/eDosStation.csproj +++ b/eDosStation/eDosStation.csproj @@ -188,6 +188,9 @@ + + DosimeterDisplay.xaml + EntryBadge.xaml @@ -209,6 +212,9 @@ ShowEPDDose.xaml + + ShowEPDDose2.xaml + @@ -233,6 +239,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -283,6 +293,10 @@ MSBuild:Compile true + + Designer + MSBuild:Compile + Designer MSBuild:Compile