diff --git a/EpdBase/EpdBase.vcxproj b/EpdBase/EpdBase.vcxproj index cd93298..e4f08df 100644 --- a/EpdBase/EpdBase.vcxproj +++ b/EpdBase/EpdBase.vcxproj @@ -30,7 +30,7 @@ StaticLibrary true - v143 + v145 true Unicode diff --git a/EpdBase3/Epd3Base.cpp b/EpdBase3/Epd3Base.cpp index 011d671..7810a88 100644 --- a/EpdBase3/Epd3Base.cpp +++ b/EpdBase3/Epd3Base.cpp @@ -3,6 +3,7 @@ #pragma unmanaged #include "Epd3Base.h" #include "TimeFunctions.h" +//#include "../EpdBaseClr/EpdBaseClr.h" #pragma unmanaged #define noDeissueWithClear #define ProtectSession @@ -13,7 +14,7 @@ #define DebugWrite(f,...) ; #endif -constexpr int SleepAfterClear = 1000; +constexpr int SleepAfterClear = 2000; //-102 = permission Epd3Base::Epd3U* current; @@ -117,6 +118,7 @@ void WINAPI discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_ current->EpdID = current->Epd.Id; } else { + current->isMK3 = true; current->EpdID = 0; current->CurrentDeviceID = 0; current->DeviceCount = 0; @@ -230,6 +232,11 @@ void Epd3Base::Epd3U::Cancel() SetEvent(current->hCancel); } +void Epd3Base::Epd3U::test() +{ + const char* msg = "Processing step test..."; + progressCallback(0, msg); // Triggers the callback +} DWORD Epd3Base::Epd3U::StartCom() { ErrorReason = 0; @@ -248,13 +255,22 @@ DWORD Epd3Base::Epd3U::StartCom() step = 2; SetFunctionReturnValue(fCreateReaderInterface, 0); epdComsHandle = CreateReaderInterface(); - if (!epdComsHandle ) step = 3; + if (!epdComsHandle) step = 3; while (epdComsHandle == nullptr && ++ConnectRetries < 4) { Sleep(200); epdComsHandle = CreateReaderInterface(); //try again; } SetCommitReturnValue(0); - if (epdComsHandle) SetEndReturnValue(0); else SetEndReturnValue(-1); + if (epdComsHandle) { + + SetEndReturnValue(0); + progressCallback(1, "CreateInterface"); // Triggers the callback + } + + else { + SetEndReturnValue(-1); + progressCallback(1, "Fail Interface"); // Triggers the callback + } if (epdComsHandle != nullptr) { step = 4; @@ -323,7 +339,7 @@ void Epd3Base::Epd3U::EndCom(bool doDiscon) int Epd3Base::Epd3U::StartDiscover(int tokentimeout) { ResetEvent(current->hCancel); - EPDStep = EPDStepStartDiscover; + EPDStep = StepDiscovering; DiscoverStep = 0; DiscoverError = DiscoverErrorNone; int32_t rv = 1; @@ -374,13 +390,14 @@ int Epd3Base::Epd3U::StartDiscover(int tokentimeout) if (DiscoverError == DiscoverErrorNone && DeviceCount > 0 && Epd.Id >0) { - + Dll3RV = Connect3(epdComsHandle, Epd, true); if (Dll3RV != 0) { DiscoverError = DiscoverErrorConnecting; + EPDStep = StepConnectFailed; rv = 2; } else - EPDStep = EPDStepConnected; + EPDStep = StepConnected; } return rv; } @@ -525,9 +542,6 @@ void Epd3Base::Epd3U::DecodeStatus() EPDTrhFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::BadThreshold); EPDTimeFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::TimeInvalid); - - - for (int ix = 0; ix < 4; ix++) { DoseAlarmFlags status = epd3status.DoseAlarms[ix].Status; @@ -801,24 +815,39 @@ int Epd3Base::Epd3U::ConnectAndStatus(int tokenSourceTimeout) { WORD dllStatus; int rv = 1; - EPDStep = EPDConnectAndStatus; + Error = 0; ErrorStep = 0; hasAlarm = hasFault = 0; ResetStepReturnValues(); if (CommsInitialized == 0) StartCom(); if (CommsInitialized) { SetFunctionReturnValue(fStartDiscover,0); + EPDStep = StepDiscovering; dllStatus = StartDiscover(tokenSourceTimeout); SetCommitReturnValue(0); - if (dllStatus==1) SetEndReturnValue(0); else SetEndReturnValue(dllStatus); - + if (dllStatus == 1) { + SetEndReturnValue(0); + } + else SetEndReturnValue(dllStatus); - if (dllStatus != 1) rv = 1; //Connect error + if (dllStatus != 1) { + rv = 1; //Connect error + EPDStep = StepDiscoverFailed; + } else if (DeviceCount < 1) { - rv = 2; + rv = 2; Error = r_OperationTimeout; - } - else if (isMK3 && ReadStatus(false) != 0) rv = 3; //Read Error - else rv = 0; + EPDStep = StepDiscoverFailed; + } + else if (isMK3) { + if (ReadStatus(false) != 0) { + rv = 3; //Read Error + EPDStep = StepFailedStatus; + } + else + EPDStep = StepGotStatus; + rv = 0; + } + else rv = 0; //MK2 } else rv = 1; return rv; @@ -1271,8 +1300,10 @@ int Epd3Base::Epd3U::ClearDoses() //rv = r[0]; //for (int b = 1; !rv && b < maxbatch;++b) if (r[b]) rv = r[b]; + error: Error = rv; + return rv; } @@ -1284,8 +1315,12 @@ int Epd3Base::Epd3U::ClearAlarms() int s[maxbatch]; int batchstep = 0; + + + s[batchstep] = SetFunctionReturnValue(eFunctions::ClearFaultStatus,0); btoken[batchstep]= BeginClearFaultStatus(epdComsHandle, nullptr); + batchstep = 1; s[batchstep] = SetFunctionReturnValue(eFunctions::ClearLatchedAlarms, 0); btoken[batchstep] = BeginClearLatchedAlarms(epdComsHandle, nullptr); @@ -1294,6 +1329,7 @@ int Epd3Base::Epd3U::ClearAlarms() batchstep = 0; r[batchstep] = End2RV(s[batchstep],EndClearFaultStatus, btoken[batchstep]); + batchstep = 1; r[batchstep] = End2RV(s[batchstep],EndClearLatchedAlarms, btoken[batchstep]); @@ -1309,20 +1345,6 @@ WORD Epd3Base::Epd3U::PrepareForIssue() if (port == 0) return 0; - /*if (DetectorsOn) { - token = BeginEpdOnOff(epdComsHandle, 0, nullptr); - rv = Commit3(epdComsHandle); - if (!rv) rv = EndEpdOnOff(epdComsHandle, token); - rv = ReOpenDev(); - } - if (rv != 0) - goto error;*/ - - /* gebeurt bij clearalrms - SetFunctionReturnValue(eFunctions::ClearLatchedAlarms,0); - token = BeginEpdOnOff(epdComsHandle, 1, nullptr); - rv = CommitAndEnd2RV(EndEpdOnOff, token); - */ step = 2; if (WriteConfig32) { rv = WriteConfig(); @@ -1334,8 +1356,18 @@ WORD Epd3Base::Epd3U::PrepareForIssue() if (!isConnected) rv = ReOpenDev(); + + step = 4; + if (!DetectorsOn) { + token = BeginEpdOnOff(epdComsHandle, 1, nullptr); + rv = Commit3(epdComsHandle); + if (!rv) rv = EndEpdOnOff(epdComsHandle, token); + rv = ReOpenDev(); + DetectorsOn = 1; + } + step = 5; - rv = ClearAlarms(); + rv = ClearAlarms(); if (rv != 0) goto error; @@ -1540,8 +1572,7 @@ WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru goto error; step = 4; - //EPDIssued - //if (!DetectorsOn) { + SetFunctionReturnValue(eFunctions::EpdOnOff, 0); token = BeginEpdOnOff(epdComsHandle, 1, nullptr); r = CommitAndEnd2RV(EndEpdOnOff, token); @@ -1753,10 +1784,22 @@ int Epd3Base::Epd3U::IssueAndCheck(float gain, float ChirpRate) goto error; step = 1; + + //todo: Set off + + if (DetectorsOn) { + token = BeginEpdOnOff(epdComsHandle, 0, nullptr); + rv = Commit3(epdComsHandle); + if (!rv) rv = EndEpdOnOff(epdComsHandle, token); + rv = ReOpenDev(); + DetectorsOn = 0; + } + OutputDebugStringW(L"**** IssueAndCheck step 1 settime ****\n"); rv = SetTime(); //synctime + //Tpodo :: Set ON OutputDebugStringW(L"**** Prepare IssueAndCheck ****\n"); step = 2; rv = PrepareForIssue(); //Set epd on, clear doses and alarms diff --git a/EpdBase3/Epd3Base.h b/EpdBase3/Epd3Base.h index ebe56f3..a738696 100644 --- a/EpdBase3/Epd3Base.h +++ b/EpdBase3/Epd3Base.h @@ -9,6 +9,7 @@ #include "Epd2.h" #pragma unmanaged + #define MaxPeakRates 10 #define MaxSensitivities 10 #define MaxGains 10 @@ -19,7 +20,8 @@ #define MaxTresholds 10 #define MaxSteps 50 #define MaxBatch 4 -#define ResponseTimeout 2500 +//ResponseTimeout was set to 2500 in code, but initial this was 500ms +#define ResponseTimeout 500 #define DiagnosticsWriteSize 256 namespace Epd3Base { @@ -37,6 +39,8 @@ namespace Epd3Base { , fCreateReaderInterface,fOpenReader , TestVibe }; + typedef void(*ProgressCallback)(int percentage, const char* message); + class Epd3U { public: @@ -87,8 +91,6 @@ namespace Epd3Base { void EndCom(bool doDiscon); int StartDiscover(int tokentimeout); - enum EPDStepEnum { EPDNone, EPDConnectAndStatus, EPDStepConnecting, EPDStepConnected , EPDStepStartDiscover }; - EPDStepEnum EPDStep; int DiscoverStep; enum DiscoverErrorCodes { @@ -98,8 +100,20 @@ namespace Epd3Base { DiscoverErrorOther=4, DiscoverErrorConnecting=5 }; - + enum EpdSteps + { + StepInitialized = 0, + StepDiscovering = 1, + StepDiscoverFailed = 2, + StepDiscovered, + StepConnecting = 3, + StepConnected, + StepConnectFailed, + StepGotStatus, + StepFailedStatus + }; DiscoverErrorCodes DiscoverError; + EpdSteps EPDStep; //OperatingStatus BYTE DetectorsOn = 0; @@ -359,6 +373,9 @@ namespace Epd3Base { public: char DiagnosticsWrite[DiagnosticsWriteSize]; + typedef void (*ProgressCallback)(int percentage, const char* message); + ProgressCallback progressCallback; + void test(); }; } diff --git a/EpdBase3/EpdBase3.vcxproj b/EpdBase3/EpdBase3.vcxproj index 365b5a5..34703c6 100644 --- a/EpdBase3/EpdBase3.vcxproj +++ b/EpdBase3/EpdBase3.vcxproj @@ -30,7 +30,7 @@ StaticLibrary true - v143 + v145 Unicode diff --git a/EpdBaseClr/EpdBaseClr.cpp b/EpdBaseClr/EpdBaseClr.cpp index 97e188b..ce3ccea 100644 --- a/EpdBaseClr/EpdBaseClr.cpp +++ b/EpdBaseClr/EpdBaseClr.cpp @@ -1,7 +1,9 @@ #include "stdafx.h" #include "EpdBaseClr.h" #pragma managed +#include "../EpdBase3/Epd3Base.h" // or "Epd3Base.h" if on include path +typedef void (*ProgressCallback)(int percentage, const char* message); void EpdBaseClr::Epd2::OnCancelRequested() { @@ -31,6 +33,12 @@ int EpdBaseClr::Epd2::GetSteps() return nsteps; } +void EpdBaseClr::Epd2::OnProgress(int percentage, String^ message) +{ + // Handle the progress info here (e.g., print or log it) + System::Console::WriteLine(percentage.ToString() + "%: " + message); +} + EpdBaseClr::Epd2::Epd2(int port, bool OnlyMK2) { //HANDLE hMod = LoadLibrary(L"Reader2.dll"); @@ -48,7 +56,18 @@ EpdBaseClr::Epd2::Epd2(int port, bool OnlyMK2) Hp10Name = gcnew String(tHp10); Hp07Name = gcnew String(tHp07); isTitleNG = false; + + progressDelegate = gcnew ProgressCallbackDelegate(&Epd2::OnProgress); + IntPtr ip = System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(progressDelegate); + /* epd3->postgre + epd3->ProgressCallback = static_cast(ip.ToPointer()); + epd3.prog*/ + if (epd3 != nullptr) { + epd3->progressCallback = static_cast(ip.ToPointer()); + epd3->test(); + } } + EpdBaseClr::Epd2::~Epd2() { if (epd != nullptr) { @@ -63,9 +82,11 @@ EpdBaseClr::Epd2::~Epd2() } this->!Epd2(); } + EpdBaseClr::Epd2::!Epd2() { } + int EpdBaseClr::Epd2::SetFeedbackSound(byte sound, UINT16 sound3) { epd->EndSessionControl = sound; @@ -878,6 +899,12 @@ void EpdBaseClr::Epd2::InitData() SoftVersion = 0; FunctionFlags = 0; CountsClock = 0; + + ErrorStep = ErrorRV = 0; + ConnectError = 0; eDoshasAlarm = eDosHasFault = false; + ErrorEPD = EpdErrorCodes::EpdErrorNone; + + } //void EpdBaseClr::Epd2::OnCancelRequested() diff --git a/EpdBaseClr/EpdBaseClr.h b/EpdBaseClr/EpdBaseClr.h index 3eb4e77..7aab927 100644 --- a/EpdBaseClr/EpdBaseClr.h +++ b/EpdBaseClr/EpdBaseClr.h @@ -8,12 +8,18 @@ #pragma comment(lib,"dll2/Reader32.lib") #pragma managed using namespace System; - +using namespace System::Runtime::InteropServices; namespace EpdBaseClr { + [UnmanagedFunctionPointer(CallingConvention::Cdecl)] + delegate void ProgressCallbackDelegate(int percentage, String^ message); + const char* cEpdError = "Setreader Error"; ref class Epd2; + + + public ref class cStepValues { public: @@ -44,6 +50,7 @@ namespace EpdBaseClr { EpdErrorOther = 4, EpdErrorConnecting = 5 }; + public ref class EpdEventArgs : EventArgs { @@ -132,6 +139,8 @@ namespace EpdBaseClr { const wchar_t* tHp10G = L"HP10G"; public: + static void OnProgress(int, String^); + ProgressCallbackDelegate^ progressDelegate; delegate void dEpdRead(Epd2^ Sender, EpdEventArgs^ e); delegate void dEpdTO(Epd2^ Sender, EpdTOEventArgs^ e); delegate void dEpdError(Epd2^ Sender, EpdErrorEventArgs^ e); @@ -218,6 +227,7 @@ namespace EpdBaseClr { int ErrorStep=0; int ErrorRV = 0; EpdErrorCodes ErrorEPD; + double Hp07; double Hp10; diff --git a/EpdBaseClr/EpdBaseClr.vcxproj b/EpdBaseClr/EpdBaseClr.vcxproj index f84d941..07ffc1a 100644 --- a/EpdBaseClr/EpdBaseClr.vcxproj +++ b/EpdBaseClr/EpdBaseClr.vcxproj @@ -30,7 +30,7 @@ DynamicLibrary true - v143 + v145 true Unicode diff --git a/MK3/MK3.vcxproj b/MK3/MK3.vcxproj index 6c90dff..65c5d25 100644 --- a/MK3/MK3.vcxproj +++ b/MK3/MK3.vcxproj @@ -30,7 +30,7 @@ DynamicLibrary true - v143 + v145 true Unicode diff --git a/OkReadBadge/OkReadBadge.vcxproj b/OkReadBadge/OkReadBadge.vcxproj index cdff5fa..24a869d 100644 --- a/OkReadBadge/OkReadBadge.vcxproj +++ b/OkReadBadge/OkReadBadge.vcxproj @@ -30,7 +30,7 @@ DynamicLibrary true - v143 + v145 true Unicode diff --git a/TestMK3/TestMK3.cpp b/TestMK3/TestMK3.cpp index 06f875e..23f121f 100644 --- a/TestMK3/TestMK3.cpp +++ b/TestMK3/TestMK3.cpp @@ -107,11 +107,13 @@ int startCom() FALSE, // initial state is nonsignaled TEXT("WriteEvent") // object name ); - uint32_t ms, slots; bool state = true; + uint32_t ms1, ms, slots; bool state = true; + GetResponseTimeout(epdComsHandle, &ms1); r = GetMultipleDiscoveryMode(epdComsHandle, &state); r = GetDiscoveryTimeslots(epdComsHandle, &slots); r = GetDiscoveryTimeout(epdComsHandle, &ms); - //SetDiscoveryTimeout(epdComsHandle, 2000); + SetDiscoveryCacheTimeout(epdComsHandle, 2000); + SetResponseTimeout(epdComsHandle, 500); return r; } @@ -142,17 +144,19 @@ void detectepd() auto t1 = high_resolution_clock::now(); //memset(DevceIDs, 0, sizeof(DeviceIDs)); r = StartDiscovery(epdComsHandle, discovery2); - auto t2 = high_resolution_clock::now(); - auto elapsed = duration_cast(t2 - t1); + if (r == 0) { - r = WaitForSingleObject(Ev1, 20000); - r2 = StopDiscovery(epdComsHandle); + r = WaitForSingleObject(Ev1, 10000); + std::cout << "EPD " << EpdID << "\n"; } else { std::cout << "StartDiscovery failed " << r << "\n"; } - + r2 = StopDiscovery(epdComsHandle); + auto t2 = high_resolution_clock::now(); + auto elapsed = duration_cast(t2 - t1); + std::cout << "Elapsed time: " << elapsed.count() << " ms\n"; } diff --git a/TestMK3/TestMK3.vcxproj b/TestMK3/TestMK3.vcxproj index 9ecfc61..d0764b6 100644 --- a/TestMK3/TestMK3.vcxproj +++ b/TestMK3/TestMK3.vcxproj @@ -29,7 +29,7 @@ Application true - v143 + v145 Unicode diff --git a/eDosLocal/eDosLocal.sqlproj b/eDosLocal/eDosLocal.sqlproj index 8223b16..abda41b 100644 --- a/eDosLocal/eDosLocal.sqlproj +++ b/eDosLocal/eDosLocal.sqlproj @@ -16,12 +16,13 @@ 1033, CI BySchemaAndSchemaType True - v4.5 + v4.7.2 CS Properties False True True + bin\Release\ diff --git a/eDosPrep/eDosPrep.vcxproj b/eDosPrep/eDosPrep.vcxproj index 06bdca6..21f84ac 100644 --- a/eDosPrep/eDosPrep.vcxproj +++ b/eDosPrep/eDosPrep.vcxproj @@ -29,7 +29,7 @@ Application true - v143 + v145 Unicode diff --git a/eDosStation/Resources/BuildDate.txt b/eDosStation/Resources/BuildDate.txt index 0e27295..3bb0a37 100644 --- a/eDosStation/Resources/BuildDate.txt +++ b/eDosStation/Resources/BuildDate.txt @@ -1 +1 @@ -Wed 01/07/2026 14:54:13.44 +Thu 07/30/2026 17:58:59.17