diff --git a/EpdBase/EpdBase.cpp b/EpdBase/EpdBase.cpp
index 16b6795..fc54627 100644
--- a/EpdBase/EpdBase.cpp
+++ b/EpdBase/EpdBase.cpp
@@ -42,6 +42,7 @@ DWORD EpdBase::Epd2U::StartCom()
else {
SetRetryCounts(RxRetryCount, TxRetryCount);
SetDiscoveryTimeslotPeriod(port, DiscoveryTimeslotPeriod);
+ SetDiscoveryTimeslotCount(port, 1);
SetDiscoveryExpirationPeriod(port, DiscoveryExpirationPeriod);
}
} while (InitRv == 0 && mx > 0);
@@ -67,11 +68,12 @@ int EpdBase::Epd2U::StartDiscover( int EpdTimeout)
FlushDiscoveryCache(port);
FlushBuffers(port);
Sleep(100);
- Error = 0;
+ Error = 0;
Ev1 = CreateWaitableTimer(NULL, TRUE, NULL);
LARGE_INTEGER wt;
- wt.QuadPart = Int32x32To64(maxDiscoverTime, -10000); //10 seconden proberen
+ wt.QuadPart = Int32x32To64(maxDiscoverTime-100, -10000); //10 seconden proberen
if (Ev1 != NULL) SetWaitableTimer(Ev1, &wt, 0, NULL, NULL, FALSE);
+
int maxtries = 100; DeviceCount = 0; DiscRV = 1; DWORD wo = 1; // ongeveer 43 tries in 10 seconden
int tries = 0;
while (DeviceCount == 0 && wo != 0) //tries-- > 0 &&
@@ -315,7 +317,7 @@ WORD EpdBase::Epd2U::ReadTresHolds()
return 1;
}
Hp10THDose1 = Hp10THDose2 = Hp07THDose = 0;
- ReadDoseTresholdRV = ReadAlarmDoseThresholds(&Hp10THDose1, &Hp10THDose2, &Hp10THDose2);
+ ReadDoseTresholdRV = ReadAlarmDoseThresholds(&Hp10THDose1, &Hp10THDose2, &Hp07THDose);
CommitRV = Commit();
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
ReadAlarmRateThresholdsRV = ReadAlarmRateThresholds(
diff --git a/EpdBaseClr/EpdBaseClr.cpp b/EpdBaseClr/EpdBaseClr.cpp
index 2bbc90a..02eaebd 100644
--- a/EpdBaseClr/EpdBaseClr.cpp
+++ b/EpdBaseClr/EpdBaseClr.cpp
@@ -4,7 +4,8 @@
EpdBaseClr::Epd2::Epd2(int port)
{
//HANDLE hMod = LoadLibrary(L"Reader2.dll");
- b = gcnew sEpdBase();
+ EpdID = 0;
+ isMK3 = Issued = isBG = 0;
epd = new EpdBase::Epd2U(port);
this->InitRV = epd->InitRv;
epd->StartCom();
@@ -12,8 +13,9 @@ EpdBaseClr::Epd2::Epd2(int port)
EpdBaseClr::Epd2::~Epd2()
{
- delete b;
- delete epd;
+ if (epd != nullptr) {
+ delete epd; epd = nullptr;
+ }
this->!Epd2();
}
@@ -32,12 +34,12 @@ int EpdBaseClr::Epd2::SetFeedbackSound(byte sound)
/// find Epd
///
///
-/// 0 = no discovery 1=ok
+/// 0 = success
int EpdBaseClr::Epd2::Connect(bool reinit, int EPDTimeout)
{
+ int rv = 1;
ConnectError = 0;
- b->CurrentDeviceID = 0;
-
+ EpdID= 0;
DeviceCount = 0;
DiscRV = 0;
if (epd != nullptr) {
@@ -46,18 +48,22 @@ int EpdBaseClr::Epd2::Connect(bool reinit, int EPDTimeout)
if (DiscRV == 1)
{
DeviceCount = epd->DeviceCount;
- if (epd->DeviceCount >= 0) b->CurrentDeviceID = epd->DeviceIDs[0];
+ if (epd->DeviceCount > 0) {
+ EpdID = epd->DeviceIDs[0]; rv = 0;
+ }
+ else rv = 1;
}
else {
+ rv = 2;
ConnectError = epd->Error;
}
}
- return DiscRV;
+ return rv;
}
int EpdBaseClr::Epd2::Close()
{
- b->CurrentDeviceID = 0;
+ EpdID= 0;
if (epd!=nullptr) epd->Close();
return 0;
}
@@ -99,13 +105,18 @@ int EpdBaseClr::Epd2::DecodeStatus()
return 1;
}
+///
+///
+///
+/// 0=success
int EpdBaseClr::Epd2::GetStatus()
{
+ int rv = 1;
GetStatusError = 0; StatusRV = 0; Issued = false;
WearerID = String::Empty;
WearerName = String::Empty;
StatusRV = epd->ReadStatus();
- if (StatusRV != 1 ) GetStatusError=epd->Error;
+ if (StatusRV != 1) GetStatusError = epd->Error; else rv = 0;
Issued = epd->EPDIssued;
WearerID = gcnew String((char *)epd->WearerID);
WearerName = gcnew String((char *)epd->WearerName);
@@ -123,7 +134,7 @@ int EpdBaseClr::Epd2::GetStatus()
FunctionFlags = epd->FunctionFlags;
CountsClock = epd->EpdClock;
DecodeStatus();
- return StatusRV;
+ return rv;
}
int EpdBaseClr::Epd2::GetDoses()
@@ -214,7 +225,6 @@ int EpdBaseClr::Epd2::SetIssued()
_memccpy(epd->WearerName, str2, l, WearerNameLength);
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
-
int rv = epd->Issue();
if (rv != 1) SetIssuedError = epd->Error;
return rv;
@@ -271,7 +281,6 @@ int EpdBaseClr::Epd2::ReadTresholds()
BC = epd->BC;
FB = epd->FB;
HG = epd->HG;
-
return rv;
}
@@ -290,4 +299,70 @@ int EpdBaseClr::Epd2::ReadExtraStatus()
CountsClockBase = epd->BaseCountsClock;
return rv;
+}
+
+///
+/// connect to Epd and read status
+///
+/// 0=success
+int EpdBaseClr::Epd2::ConnectAndStatus()
+{
+ int rv = Connect(false, tokenSourceTimeout);
+ if (rv == 0)
+ {
+ //EpdID = epd/*->Epd.Id;*/
+ isMK3 = 0;
+ rv = GetStatus();
+ }
+ return rv;
+}
+
+void EpdBaseClr::Epd2::WaitEpd()
+{
+ int rv = 0; //start
+ System::Threading::CancellationToken^ token = tokenSource->Token;
+ do {
+ rv = ConnectAndStatus();
+ } while (rv != 0 && !token->IsCancellationRequested);
+
+ if (token->IsCancellationRequested)
+ rv=7;
+ if (rv == 0) {
+ if (_EpdRead != nullptr) _EpdRead(this, gcnew EpdEventArgs(EpdID, Issued, isBG, isMK3));
+ } else if (rv > 0 && _EpdError != nullptr) {
+ _EpdError(this, gcnew EpdErrorEventArgs(rv));
+ }
+
+ return;
+}
+
+System::Threading::Tasks::Task^ EpdBaseClr::Epd2::Wait(int timeout, int Retries)
+{
+ if (waitTask == nullptr)
+ {
+ tokenSourceTimeout = timeout;
+ tokenSource = gcnew System::Threading::CancellationTokenSource(tokenSourceTimeout - 100);
+ readRetries = Retries;
+ waitTask = System::Threading::Tasks::Task::Run(gcnew Action(this, &Epd2::WaitEpd)); // System::Threading::Tasks::Task::Factory->cre(gcnew Action(this, &CCard::WaitBadge), tokenSource->Token);
+ }
+ else {
+ tokenSource = gcnew System::Threading::CancellationTokenSource(tokenSourceTimeout - 1000);
+
+ //readRetries = Retries + 1;
+ }
+ return waitTask;
+}
+void EpdBaseClr::Epd2::WaitEnd()
+{
+ if (waitTask != nullptr)
+ {
+ tokenSource->Cancel();
+ //cbCard->Cancel();
+ waitTask->Wait(750);
+ delete waitTask;
+ waitTask = nullptr;
+ delete tokenSource;
+ tokenSource = nullptr;
+ Close();
+ }
}
\ No newline at end of file
diff --git a/EpdBaseClr/EpdBaseClr.h b/EpdBaseClr/EpdBaseClr.h
index d101917..3260093 100644
--- a/EpdBaseClr/EpdBaseClr.h
+++ b/EpdBaseClr/EpdBaseClr.h
@@ -5,27 +5,117 @@ using namespace System;
namespace EpdBaseClr {
- public ref class sEpdBase
+ const char* cEpdError = "Setreader Error";
+ ref class Epd2;
+
+ public ref class EpdEventArgs : EventArgs
+ {
+
+ public:
+ int deviceID;
+ bool isIssued, isBG, isMK3;
+
+ EpdEventArgs(int epdID, bool epdIssued, bool isBG, bool isMK3) : EventArgs()
+ {
+
+ this->deviceID = epdID;
+ this->isIssued = epdIssued;
+ this->isBG = isBG;
+ this->isMK3 = isMK3;
+ }
+
+ };
+ public ref struct EpdException : System::Exception
+ {
+ public:
+ int errorCode;
+ EpdException(int r) : System::Exception(gcnew String(cEpdError))
+ {
+ this->errorCode = r;
+ }
+ };
+ public ref class EpdErrorEventArgs : EventArgs
+ {
+ public:
+ int returnValue;
+
+ EpdErrorEventArgs(int ReturnValue) : EventArgs()
+ {
+ this->returnValue = ReturnValue;
+ }
+
+ };
+
+
+
+
+ /*public ref class sEpdBase
{
public :
DateTime^ RealTime;
unsigned int CurrentDeviceID;
- };
+ };*/
public ref class Epd2
{
-
+ public:
+ delegate void dEpdRead(Epd2^ Sender, EpdEventArgs^ e);
+ delegate void dEpdTO(Epd2^ Sender, EventArgs^ e);
+ delegate void dEpdError(Epd2^ Sender, EpdErrorEventArgs^ e);
+
+ dEpdRead^ _EpdRead;
+ dEpdTO^ _EpdTO;
+ dEpdError^ _EpdError;
+
+ event dEpdRead^ EpdRead
+ {
+ void add(dEpdRead^ handler)
+ {
+ _EpdRead += handler;
+ }
+
+ void remove(dEpdRead^ handler)
+ {
+ _EpdRead -= handler;
+ }
+ }
+ event dEpdError^ EpdError
+ {
+ void add(dEpdError^ handler)
+ {
+ _EpdError += handler;
+ }
+
+ void remove(dEpdError^ handler)
+ {
+ _EpdError -= handler;
+ }
+ }
+ event dEpdTO^ EpdTO
+ {
+ void add(dEpdTO^ handler)
+ {
+ _EpdTO += handler;
+ }
+
+ void remove(dEpdTO^ handler)
+ {
+ _EpdTO -= handler;
+ }
+ }
+
public:
EpdBase::Epd2U *epd;
- sEpdBase^ b;
+ //sEpdBase^ b;
DateTime^ RealTime;
String^ WearerName;
String^ WearerID;
bool Issued;
bool isOn;
bool isBG;
+ bool isMK3;
int InitRV;
int DiscRV;
@@ -156,7 +246,17 @@ namespace EpdBaseClr {
int ReadExtraStatus();
+ int ConnectAndStatus();
+ void WaitEpd();
+
+ System::Threading::CancellationTokenSource^ tokenSource;
+ int tokenSourceTimeout;
+ int readRetries;
+ System::Threading::Tasks::Task^ waitTask;
+ System::Threading::Tasks::Task^ Wait(int timeout, int Retries);
+
+ void WaitEnd();
};
}
diff --git a/MK3/MK3.cpp b/MK3/MK3.cpp
index ae57c6f..715d7cb 100644
--- a/MK3/MK3.cpp
+++ b/MK3/MK3.cpp
@@ -3,304 +3,363 @@
#pragma managed
-MK3::Epd2::Epd2(int port)
-{
- b = gcnew sEpdBase();
- epd = new Epd2U(port);
- Jan2000 = gcnew DateTime(2000, 1, 1);
- this->InitRV = epd->InitRv;
- epd->StartCom();
-}
+namespace MK3 {
+ Epd2::Epd2(int port)
+ {
+ //epdBase = gcnew sEpdBase(this);
+ epd = new Epd2U(port);
+ Jan2000 = gcnew DateTime(2000, 1, 1);
+ this->InitRV = epd->InitRv;
+ epd->StartCom();
+ Issued=isOn=isBG=isMK3=0;
+ }
-MK3::Epd2::~Epd2()
-{
- delete b;
- delete epd;
- this->!Epd2();
-}
+ Epd2::~Epd2()
+ {
+ delete epd;
+ this->!Epd2();
+ }
-MK3::Epd2::!Epd2()
-{
-}
+ Epd2::!Epd2()
+ {
+ }
-int MK3::Epd2::Connect(bool reinit)
-{
- ConnectError = 0;
- b->CurrentDeviceID = 0;
- DeviceCount = 0;
- DiscRV = 0;
- if (epd != nullptr) {
- if (epd->CommsInitialized == 0) epd->StartCom();
- DiscRV = epd->StartDiscover();
- if (DiscRV == 1)
- {
- DeviceCount = epd->DeviceCount;
- if (epd->DeviceCount >= 0)
+ int Epd2::Connect(bool reinit)
+ {
+ ConnectError = 0;
+ EpdID = 0;
+ DeviceCount = 0;
+ DiscRV = 0;
+ if (epd != nullptr) {
+ if (epd->CommsInitialized == 0) epd->StartCom();
+ DiscRV = epd->StartDiscover();
+ if (DiscRV == 1)
{
- b->CurrentDeviceID = epd->DeviceIDs[0];
- EpdID = b->CurrentDeviceID;
+ DeviceCount = epd->DeviceCount;
+ if (epd->DeviceCount >= 0)
+ {
+ EpdID = epd->DeviceIDs[0];
+ }
+ }
+ else {
+ ConnectError = epd->Error;
}
}
+ return DiscRV;
+ }
+
+ int Epd2::Close()
+ {
+ EpdID = 0;
+ if (epd != nullptr) epd->CloseDev();
+ return 0;
+ }
+
+ int Epd2::DecodeStatus()
+ {
+ epd->DecodeStatus();
+ //OperatingStatus
+ DetectorsOn = epd->DetectorsOn;
+ EPDIssued = epd->EPDIssued;
+ EPDLocked = epd->EPDLocked;
+ EPDTesting = epd->EPDTesting;
+ EPDProcSec = epd->EPDProcSec;
+ EPDFaulty = epd->EPDFaulty;
+
+ EPDNewFault = epd->EPDNewFault;
+ EPDComFault = epd->EPDComFault;
+ EPDCalFault = epd->EPDCalFault;
+ EPDDetFault = epd->EPDDetFault;
+ EPDEprFault = epd->EPDEprFault;
+ EPDTrhFault = epd->EPDTrhFault;
+ EPDOthFault = epd->EPDOthFault;
+
+ AlarmDoseHP101G = epd->AlarmDoseHP101G;
+ AlarmDoseHP102G = epd->AlarmDoseHP102G;
+ AlarmDoseHP07N = epd->AlarmDoseHP07N;
+ AlarmRateHP101G = epd->AlarmRateHP101G;
+ AlarmRateHP102G = epd->AlarmRateHP102G;
+ AlarmRateHP07N = epd->AlarmRateHP07N;
+
+ OtherAlarmRateHp101G = epd->OtherAlarmRateHp101G;
+ OtherAlarmRateHp102G = epd->OtherAlarmRateHp102G;
+ OtherAlarmRateHp07N = epd->OtherAlarmRateHp07N;
+ OtherAlarmReturn = epd->OtherAlarmReturn;
+ OtherAlarmBatLow = epd->OtherAlarmBatLow;
+ OtherAlarmCarrier = epd->OtherAlarmCarrier;
+ OtherAlarmBatVolt = epd->OtherAlarmBatVolt;
+
+ return 1;
+ }
+
+ int Epd2::SetTime() {
+ epd->SetTime();
+ return epd->utc;
+ }
+
+ int Epd2::ReadAlarmConfig() {
+ epd->ReadAlarmConfig();
+ return epd->numAlarm;
+ }
+
+ int Epd2::ReadAlarmTresholds() {
+ epd->ReadAlarmTresholds();
+ return 0;
+ }
+
+
+ int Epd2::GetStatus()
+ {
+ GetStatusError = 0; StatusRV = 0; Issued = false;
+ WearerID = String::Empty;
+ WearerName = String::Empty;
+ StatusRV = epd->ReadStatus();
+ if (StatusRV != 0) GetStatusError = epd->Error;
+
+ Issued = epd->EPDIssued;
+
+ WearerID = gcnew String((char*)epd->WearerID);
+ WearerName = gcnew String((char*)epd->WearerName);
+ isOn = (epd->DetectorsOn != 0);
+ epdType = (int)epd->EpdType;
+ isBG = (epd->EpdType == EpdTypes::Mk2BetaGamma || epd->EpdType == EpdTypes::Mk3BetaGamma);
+
+ alarmStatus = epd->AlarmStatus;
+ otherAlarms = epd->OtherAlarms;
+ errorStatus = epd->ErrorStatus;
+ operatingStatus = epd->OperatingStatus;
+
+ EpdID = epd->EpdID;
+ HardVersion = epd->HardVersion;
+ SoftVersion = epd->SoftVersion;
+ FunctionFlags = epd->FunctionFlags;
+ CountsClock = epd->EpdClock;
+ DecodeStatus();
+ return StatusRV;
+ }
+
+ int Epd2::GetDoses()
+ {
+ Hp10 = Hp07 = 0.0;
+ int ReadDosesRV = epd->ReadDoses();
+
+ if (ReadDosesRV == 1) {
+ GetDosesError = 0;
+ Hp10 = (double)epd->Hp10Dose;
+ Hp07 = (double)epd->Hp07Dose;
+ Hp07Peak = (double)epd->Hp07Peak;
+ Hp10Peak = (double)epd->Hp10Peak;
+
+ Hp07Total = epd->Hp07Total;
+ Hp10Total = epd->Hp10Total;
+ }
else {
- ConnectError = epd->Error;
+ GetDosesError = epd->Error;
+ }
+
+ if (epd->Hp10Time > 0) {
+ //seconds since 2000 ?
+ //double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
+ Hp10PeakTime = Jan2000->AddSeconds(epd->Hp10Time);
+ }
+ else
+ Hp10PeakTime = System::Nullable();;
+ if (epd->Hp07Time > 0) {
+ //double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
+ Hp07PeakTime = Jan2000->AddSeconds(epd->Hp07Time);
+ }
+ else
+ Hp07PeakTime = System::Nullable();
+
+ QualityData = epd->QualityData;
+ K1 = epd->K1;
+ K2 = epd->K2;
+ K3 = epd->K3;
+ K4 = epd->K4;
+ K5 = epd->K5;
+ K6 = epd->K6;
+ SG = epd->SG;
+ BC = epd->SG;
+ FB = epd->FB;
+ HG = epd->HG;
+
+ return ReadDosesRV;
+ }
+
+ int Epd2::SetDeIssued()
+ {
+ return epd->DeIssue();
+ }
+
+ int Epd2::PrepareForIssue()
+ {
+ PrepareForIssueError = 0;
+ int rv = epd->PrepareForIssue();
+ if (rv != 1) PrepareForIssueError = epd->Error;
+ return rv;
+ }
+
+ int Epd2::SetIssued()
+ {
+ SetIssuedError = 0;
+ epd->Hp07THDose = (float)Hp07THDose;
+ epd->Hp10THDose1 = (float)Hp10THDose1;
+ epd->Hp10THDose2 = (float)Hp10THDose2;
+
+ epd->Hp10Rate1On = (float)(Hp10Rate1On);
+ epd->Hp10Rate2On = (float)(Hp10Rate2On);
+ epd->Hp07RateOn = (float)(Hp07RateOn);
+
+ epd->Hp10Rate1Off = (float)(Hp10Rate1Off);
+ epd->Hp10Rate2Off = (float)(Hp10Rate2Off);
+ epd->Hp07RateOff = (float)(Hp07RateOff);
+
+ epd->K3 = K3;
+ epd->K4 = K4;
+
+ memset(epd->WearerID, ' ', WearerIDLength); epd->WearerID[WearerIDLength] = 0;
+ char* str1 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerID);
+ int l = strlen(str1);
+ if (l > WearerIDLength) l = WearerIDLength;
+ _memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength - l);
+ Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
+
+ memset(epd->WearerName, 0, WearerNameLength + 1);
+ char* str2 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerName);
+ l = strlen(str2);
+ if (l > WearerNameLength) l = WearerNameLength;
+ _memccpy(epd->WearerName, str2, l, WearerNameLength);
+ Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
+
+ int rv = epd->Issue();
+ if (rv != 0)
+ SetIssuedError = epd->Error;
+ return rv;
+ }
+
+ int Epd2::WriteCalibration()
+ {
+ epd->K1 = K1;
+ epd->K2 = K2;
+
+ epd->K3 = K3;
+ epd->K4 = K4;
+
+ epd->K5 = K5;
+ epd->K6 = K6;
+
+ //epd->K1 = 903;
+ //epd->K2 = 613;
+ //epd->K5 = 13100;
+ //epd->K6 = 1310;
+
+ int rv = epd->WriteCal();
+ return rv;
+
+ }
+
+ int Epd2::ReadTresholds()
+ {
+ ReadTresholdsError = 0;
+ int rv = epd->ReadAlarmTresholds();
+ if (rv != 0) ReadTresholdsError = epd->Error;
+
+ Hp10THDose1 = (double)epd->Hp10THDose1 / 64.0;
+ Hp10THDose2 = (double)epd->Hp10THDose2 / 64.0;
+ Hp07THDose = (double)epd->Hp07THDose / 64.0;
+
+ Hp10Total = (double)epd->Hp10Total / 64.0;
+ Hp07Total = (double)epd->Hp07Total / 64.0;
+
+ Hp10Rate1On = (double)epd->Hp10Rate1On;
+ Hp10Rate2On = (double)epd->Hp10Rate2On;
+ Hp07RateOn = (double)epd->Hp07RateOn;
+ Hp10Rate1Off = (double)epd->Hp10Rate1Off;
+ Hp10Rate2Off = (double)epd->Hp10Rate2Off;
+ Hp07RateOff = (double)epd->Hp07RateOff;
+
+ K1 = epd->K1;
+ K2 = epd->K2;
+ K3 = epd->K3;
+ K4 = epd->K4;
+ K5 = epd->K5;
+ K6 = epd->K6;
+ SG = epd->SG;
+ BC = epd->BC;
+ FB = epd->FB;
+ HG = epd->HG;
+ return rv;
+ }
+
+ int Epd2::ReadExtraStatus()
+ {
+ int rv = epd->EPDReadExtraStatus();
+ BatADC = epd->byBatADC;
+ SupplyADC = epd->bySupplyADC;
+
+ D1 = epd->D1;
+ D2 = epd->D2;
+ D3 = epd->D3;
+ D4 = epd->D4;
+ CountsClock = epd->CountsClock;
+ CountsClockBase = epd->BaseCountsClock;
+ return rv;
+ }
+
+ int Epd2::ConnectAndStatus()
+ {
+ int rv = Connect(false);
+ if (rv == 0)
+ {
+ EpdID= epd->Epd.Id;
+ isMK3 = (epd->EpdGen == EpdGeneration::Mk3);
+ rv = GetStatus();
+ }
+ return rv;
+ }
+
+ void Epd2::WaitEpd()
+ {
+ int rv = 0; //start
+ System::Threading::CancellationToken^ token = tokenSource->Token;
+
+ do {
+ rv = ConnectAndStatus();
+ } while (rv != 0 && --readRetries > 0 && !token->IsCancellationRequested);
+
+ //if (token->IsCancellationRequested) lastStatusRV = 7;
+ if (rv == 0) {
+ if (_EpdRead != nullptr)
+ _EpdRead(this, gcnew EpdEventArgs(EpdID,Issued,isBG,isMK3));
+ } else if (rv > 0 && _EpdError != nullptr) {
+ _EpdError(this, gcnew EpdErrorEventArgs(rv));
+ }
+ return ;
+ }
+
+ System::Threading::Tasks::Task^ Epd2::Wait(int timeout, int Retries)
+ {
+ if (waitTask == nullptr)
+ {
+ tokenSourceTimeout = timeout;
+ tokenSource = gcnew System::Threading::CancellationTokenSource(tokenSourceTimeout - 1000);
+ readRetries = Retries;
+ waitTask = System::Threading::Tasks::Task::Run(gcnew Action(this, &Epd2::WaitEpd)); // System::Threading::Tasks::Task::Factory->cre(gcnew Action(this, &CCard::WaitBadge), tokenSource->Token);
+ }
+ else {
+ readRetries = Retries + 1;
+ }
+ return waitTask;
+ }
+ void Epd2::WaitEnd()
+ {
+ if (waitTask != nullptr)
+ {
+ tokenSource->Cancel();
+ //cbCard->Cancel();
+ Sleep(500);
+ delete waitTask; waitTask = nullptr;
+ delete tokenSource; tokenSource = nullptr;
}
}
- return DiscRV;
-}
-
-int MK3::Epd2::Close()
-{
- b->CurrentDeviceID = 0;
- if (epd != nullptr) epd->CloseDev();
- return 0;
-}
-
-int MK3::Epd2::DecodeStatus()
-{
- epd->DecodeStatus();
- //OperatingStatus
- DetectorsOn = epd->DetectorsOn;
- EPDIssued = epd->EPDIssued;
- EPDLocked = epd->EPDLocked;
- EPDTesting = epd->EPDTesting;
- EPDProcSec = epd->EPDProcSec;
- EPDFaulty = epd->EPDFaulty;
-
- EPDNewFault = epd->EPDNewFault;
- EPDComFault = epd->EPDComFault;
- EPDCalFault = epd->EPDCalFault;
- EPDDetFault = epd->EPDDetFault;
- EPDEprFault = epd->EPDEprFault;
- EPDTrhFault = epd->EPDTrhFault;
- EPDOthFault = epd->EPDOthFault;
-
- AlarmDoseHP101G = epd->AlarmDoseHP101G;
- AlarmDoseHP102G = epd->AlarmDoseHP102G;
- AlarmDoseHP07N = epd->AlarmDoseHP07N;
- AlarmRateHP101G = epd->AlarmRateHP101G;
- AlarmRateHP102G = epd->AlarmRateHP102G;
- AlarmRateHP07N = epd->AlarmRateHP07N;
-
- OtherAlarmRateHp101G = epd->OtherAlarmRateHp101G;
- OtherAlarmRateHp102G = epd->OtherAlarmRateHp102G;
- OtherAlarmRateHp07N = epd->OtherAlarmRateHp07N;
- OtherAlarmReturn = epd->OtherAlarmReturn;
- OtherAlarmBatLow = epd->OtherAlarmBatLow;
- OtherAlarmCarrier = epd->OtherAlarmCarrier;
- OtherAlarmBatVolt = epd->OtherAlarmBatVolt;
-
- return 1;
-}
-
-int MK3::Epd2::SetTime() {
- epd->SetTime();
- return epd->utc;
-}
-
-int MK3::Epd2::ReadAlarmConfig() {
- epd->ReadAlarmConfig();
- return epd->numAlarm;
-}
-
-int MK3::Epd2::ReadAlarmTresholds() {
- epd->ReadAlarmTresholds();
- return 0;
-}
-
-
-int MK3::Epd2::GetStatus()
-{
- GetStatusError = 0; StatusRV = 0; Issued = false;
- WearerID = String::Empty;
- WearerName = String::Empty;
- StatusRV = epd->ReadStatus();
- if (StatusRV != 1) GetStatusError = epd->Error;
- Issued = epd->EPDIssued;
- WearerID = gcnew String((char*)epd->WearerID);
- WearerName = gcnew String((char*)epd->WearerName);
- isOn = (epd->DetectorsOn != 0);
- epdType = (int)epd->EpdType;
- isBG = (epd->EpdType == EpdTypes::Mk2BetaGamma || epd->EpdType == EpdTypes::Mk3BetaGamma);
- alarmStatus = epd->AlarmStatus;
- otherAlarms = epd->OtherAlarms;
- errorStatus = epd->ErrorStatus;
- operatingStatus = epd->OperatingStatus;
-
- EpdID = epd->EpdID;
- HardVersion = epd->HardVersion;
- SoftVersion = epd->SoftVersion;
- FunctionFlags = epd->FunctionFlags;
- CountsClock = epd->EpdClock;
- DecodeStatus();
- return StatusRV;
-}
-
-int MK3::Epd2::GetDoses()
-{
- Hp10 = Hp07 = 0.0;
- int ReadDosesRV = epd->ReadDoses();
-
- if (ReadDosesRV == 1) {
- GetDosesError = 0;
- Hp10 = (double)epd->Hp10Dose ;
- Hp07 = (double)epd->Hp07Dose ;
- Hp07Peak = (double)epd->Hp07Peak ;
- Hp10Peak = (double)epd->Hp10Peak ;
-
- Hp07Total = epd->Hp07Total ;
- Hp10Total = epd->Hp10Total ;
- }
- else {
- GetDosesError = epd->Error;
- }
-
- if (epd->Hp10Time > 0) {
- //seconds since 2000 ?
- //double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
- Hp10PeakTime = Jan2000->AddSeconds(epd->Hp10Time);
- }
- else
- Hp10PeakTime = System::Nullable();;
- if (epd->Hp07Time > 0) {
- //double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
- Hp07PeakTime = Jan2000->AddSeconds(epd->Hp07Time);
- }
- else
- Hp07PeakTime = System::Nullable();
-
- QualityData = epd->QualityData;
- K1 = epd->K1;
- K2 = epd->K2;
- K3 = epd->K3;
- K4 = epd->K4;
- K5 = epd->K5;
- K6 = epd->K6;
- SG = epd->SG;
- BC = epd->SG;
- FB = epd->FB;
- HG = epd->HG;
-
- return ReadDosesRV;
-}
-
-int MK3::Epd2::SetDeIssued()
-{
- return epd->DeIssue();
-}
-
-int MK3::Epd2::PrepareForIssue()
-{
- PrepareForIssueError = 0;
- int rv = epd->PrepareForIssue();
- if (rv != 1) PrepareForIssueError = epd->Error;
- return rv;
-}
-
-int MK3::Epd2::SetIssued()
-{
- SetIssuedError = 0;
- epd->Hp07THDose = (float)Hp07THDose ;
- epd->Hp10THDose1 = (float)Hp10THDose1 ;
- epd->Hp10THDose2 = (float)Hp10THDose2 ;
-
- epd->Hp10Rate1On = (float)(Hp10Rate1On);
- epd->Hp10Rate2On = (float)(Hp10Rate2On);
- epd->Hp07RateOn = (float)(Hp07RateOn);
-
- epd->Hp10Rate1Off = (float)(Hp10Rate1Off);
- epd->Hp10Rate2Off = (float)(Hp10Rate2Off);
- epd->Hp07RateOff = (float)(Hp07RateOff);
-
- epd->K3 = K3;
- epd->K4 = K4;
-
- memset(epd->WearerID, ' ', WearerIDLength); epd->WearerID[WearerIDLength] = 0;
- char* str1 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerID);
- int l = strlen(str1);
- if (l > WearerIDLength) l = WearerIDLength;
- _memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength-l);
- Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
-
- memset(epd->WearerName, 0, WearerNameLength + 1);
- char* str2 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerName);
- l = strlen(str2);
- if (l > WearerNameLength) l = WearerNameLength;
- _memccpy(epd->WearerName, str2, l, WearerNameLength);
- Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
-
- int rv = epd->Issue();
- if (rv != 0)
- SetIssuedError = epd->Error;
- return rv;
-}
-
-int MK3::Epd2::WriteCalibration()
-{
- epd->K1 = K1;
- epd->K2 = K2;
-
- epd->K3 = K3;
- epd->K4 = K4;
-
- epd->K5 = K5;
- epd->K6 = K6;
-
- //epd->K1 = 903;
- //epd->K2 = 613;
- //epd->K5 = 13100;
- //epd->K6 = 1310;
-
- int rv = epd->WriteCal();
- return rv;
-
-}
-
-int MK3::Epd2::ReadTresholds()
-{
- ReadTresholdsError = 0;
- int rv = epd->ReadAlarmTresholds();
- if (rv != 0) ReadTresholdsError = epd->Error;
-
- Hp10THDose1 = (double)epd->Hp10THDose1 / 64.0;
- Hp10THDose2 = (double)epd->Hp10THDose2 / 64.0;
- Hp07THDose = (double)epd->Hp07THDose / 64.0;
-
- Hp10Total = (double)epd->Hp10Total / 64.0;
- Hp07Total = (double)epd->Hp07Total / 64.0;
-
- Hp10Rate1On = (double)epd->Hp10Rate1On;
- Hp10Rate2On = (double)epd->Hp10Rate2On;
- Hp07RateOn = (double)epd->Hp07RateOn;
- Hp10Rate1Off = (double)epd->Hp10Rate1Off;
- Hp10Rate2Off = (double)epd->Hp10Rate2Off;
- Hp07RateOff = (double)epd->Hp07RateOff;
-
- K1 = epd->K1;
- K2 = epd->K2;
- K3 = epd->K3;
- K4 = epd->K4;
- K5 = epd->K5;
- K6 = epd->K6;
- SG = epd->SG;
- BC = epd->BC;
- FB = epd->FB;
- HG = epd->HG;
- return rv;
-}
-
-int MK3::Epd2::ReadExtraStatus()
-{
- int rv = epd->EPDReadExtraStatus();
- BatADC = epd->byBatADC;
- SupplyADC = epd->bySupplyADC;
-
- D1 = epd->D1 ;
- D2 = epd->D2 ;
- D3 = epd->D3 ;
- D4 = epd->D4 ;
- CountsClock = epd->CountsClock;
- CountsClockBase = epd->BaseCountsClock;
-
- return rv;
-}
-
+}
\ No newline at end of file
diff --git a/MK3/MK3.h b/MK3/MK3.h
index 8f951be..ca274b5 100644
--- a/MK3/MK3.h
+++ b/MK3/MK3.h
@@ -1,28 +1,110 @@
#pragma once
#include "MK3Base.h"
#pragma comment(lib,"Reader3.lib")
-using namespace System;
-
#pragma managed
-namespace MK3 {
- public ref class sEpdBase
- {
- public:
- DateTime^ RealTime;
+using namespace System;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+#include
+#include
+
+namespace MK3 {
+ const char* cEpdError = "Setreader Error";
+ ref class Epd2;
+
+ public ref class EpdEventArgs : EventArgs
+ {
- unsigned int CurrentDeviceID;
+ public:
+ int deviceID;
+ bool isIssued, isBG, isMK3;
+
+ EpdEventArgs(int epdID,bool epdIssued, bool isBG, bool isMK3) : EventArgs()
+ {
+
+ this->deviceID = epdID;
+ this->isIssued = epdIssued;
+ this->isBG = isBG;
+ this->isMK3 = isMK3;
+ }
+
};
+ public ref struct EpdException : System::Exception
+ {
+ public:
+ int errorCode;
+ EpdException(int r) : System::Exception(gcnew String(cEpdError))
+ {
+ this->errorCode = r;
+ }
+ };
+ public ref class EpdErrorEventArgs : EventArgs
+ {
+ public:
+ int returnValue;
+
+ EpdErrorEventArgs(int ReturnValue) : EventArgs()
+ {
+ this->returnValue = ReturnValue;
+ }
+
+ };
+
public ref class Epd2
{
-
private:
DateTime^ Jan2000;
public:
+ delegate void dEpdRead(Epd2^ Sender, EpdEventArgs^ e);
+ delegate void dEpdTO(Epd2^ Sender, EventArgs^ e);
+ delegate void dEpdError(Epd2^ Sender, EpdErrorEventArgs^ e);
+
+ dEpdRead^ _EpdRead;
+ dEpdTO^ _EpdTO;
+ dEpdError^ _EpdError;
+
+ event dEpdRead^ EpdRead
+ {
+ void add(dEpdRead^ handler)
+ {
+ _EpdRead += handler;
+ }
+
+ void remove(dEpdRead^ handler)
+ {
+ _EpdRead -= handler;
+ }
+ }
+ event dEpdError^ EpdError
+ {
+ void add(dEpdError^ handler)
+ {
+ _EpdError += handler;
+ }
+
+ void remove(dEpdError^ handler)
+ {
+ _EpdError -= handler;
+ }
+ }
+ event dEpdTO^ EpdTO
+ {
+ void add(dEpdTO^ handler)
+ {
+ _EpdTO += handler;
+ }
+
+ void remove(dEpdTO^ handler)
+ {
+ _EpdTO -= handler;
+ }
+ }
+
Epd2U* epd;
- sEpdBase^ b;
+ //int CurrentDeviceID; ==> is EpdID
DateTime^ RealTime;
String^ WearerName;
@@ -30,6 +112,7 @@ namespace MK3 {
bool Issued;
bool isOn;
bool isBG;
+ bool isMK3;
int InitRV;
int DiscRV;
@@ -155,6 +238,18 @@ namespace MK3 {
int ReadTresholds();
int ReadExtraStatus();
+ int ConnectAndStatus();
+
+ void WaitEpd();
+
+ System::Threading::CancellationTokenSource^ tokenSource;
+ int tokenSourceTimeout;
+ int readRetries;
+ System::Threading::Tasks::Task^ waitTask;
+ System::Threading::Tasks::Task^ Wait(int timeout, int Retries);
+
+ void WaitEnd();
+
};
diff --git a/MK3/MK3Base.cpp b/MK3/MK3Base.cpp
index fb59c8d..ab11f88 100644
--- a/MK3/MK3Base.cpp
+++ b/MK3/MK3Base.cpp
@@ -80,6 +80,10 @@ void WINAPI discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_
}
}
+///
+///
+///
+/// 0 = success
int MK3::Epd2U::StartDiscover()
{
int32_t rv;
@@ -96,6 +100,7 @@ int MK3::Epd2U::StartDiscover()
//FlushDiscoveryCache(port);
//FlushBuffers(port);
int tries = 25; DeviceCount = 0; DiscRV = 1;
+ ResetEvent(Ev1);
while (tries-- > 0 && DeviceCount == 0)
{
//memset(DevceIDs, 0, sizeof(DeviceIDs));
@@ -103,10 +108,10 @@ int MK3::Epd2U::StartDiscover()
rv = StartDiscovery(epdComsHandle, discovery);
if (rv==0) rv = WaitForSingleObject(Ev1, 10000);
}
- if (rv == 0) DiscRV=Connect(epdComsHandle, Epd, true);
+ if (rv == 0) rv=Connect(epdComsHandle, Epd, true);
//System::Diagnostics::Trace::WriteLine(System::String::Format("Discover DeviceCount = {0}", DeviceCount));
- return DiscRV;
+ return rv;
}
void MK3::Epd2U::Open(DiscoveryId DeviceID)
@@ -212,7 +217,9 @@ void MK3::Epd2U::SetTime() //Only R3
WORD MK3::Epd2U::ReadStatus()
{
- int32_t r;
+
+ int32_t r; //0=ok
+ Error = 0;
if (port == 0) {
EpdID = 4567;
EpdType = EpdTypes::Mk2BetaGamma;
@@ -221,7 +228,7 @@ WORD MK3::Epd2U::ReadStatus()
Epd.Gen = EpdGeneration::None;
Epd.MaxBaud = 0;
Epd.Id = EpdID;
- return 1;
+ return 0;
}
OperatingStatus = (OpStatusFlags)0U;
@@ -232,65 +239,84 @@ WORD MK3::Epd2U::ReadStatus()
ErrorSource = ErrorReason = ErrorData = 0;
HardVersion = SoftVersion = FunctionFlags = 0;
- ResetEvent(Ev1);
- token = BeginReadStatus(epdComsHandle, completion);
+ SetResponseTimeout(epdComsHandle, 2000);
+ //ResetEvent(Ev1);
+ token = BeginReadStatus(epdComsHandle, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadStatus(epdComsHandle, token, &epd3status);
+ if (r != 0) {
+ Error = GetErrorCode(); return r;
+ }
+
IssueCount = epd3status.IssueCount;
OperatingStatus = epd3status.OperatingStatus;
AlarmStatus = epd3status.AlarmStatus;
ErrorStatus = epd3status.FaultStatus;
OtherAlarms = epd3status.OtherBits;
-
- Error = 0; ReadStatusRV = 0;
+ ReadStatusRV = 0;
uint32_t EpdID32;
uint32_t capabilities;
MarkNumber_t MarkNumber;
VersionNumber_t VersionNumber;
- ResetEvent(Ev1);
- token = BeginReadEpdIdentities(epdComsHandle, completion);
+ //ResetEvent(Ev1);
+ token = BeginReadEpdIdentities(epdComsHandle, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadEpdIdentities(epdComsHandle, token, &EpdID32, (EpdTypes*)&EpdType, &capabilities, &MarkNumber, &VersionNumber, NULL, 0);
+
+ if (r != 0) {
+ Error = GetErrorCode(); return r;
+ }
+
EpdID = EpdID32;
isBG = (EpdType == EpdTypes::Mk2BetaGamma || EpdType == EpdTypes::Mk3BetaGamma);
+
DecodeStatus();
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerName, 0, WearerNameLength + 1);
-
-
uint8_t length = 0;
countsRead = 0; utc = 0; seconds = 0;
- ResetEvent(Ev1);
- token = BeginReadCounts(epdComsHandle, nullptr, 0, completion);
+ //ResetEvent(Ev1);
+ token = BeginReadCounts(epdComsHandle, nullptr, 0, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadCounts(epdComsHandle,token,Counts,MaxCounts, &countsRead,&utc,&seconds);
// - 101 = InvalidParam
// - 104 = FunctionFail,
+ if (r != 0 && r!=-104) {
+ Error = GetErrorCode(); return r;
+ }
decodeCounters(countsRead); //HG,SG ..
IdString_t mk3WearerID;
//Mk2 EPDs only support Name and Primary ID
- ResetEvent(Ev1);
- token = BeginReadWearerId(epdComsHandle, static_cast(WearerIdType::WearerId_Name), completion);
+ //ResetEvent(Ev1);
+ token = BeginReadWearerId(epdComsHandle, static_cast(WearerIdType::WearerId_Name), nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadWearerId(epdComsHandle, token, &mk3WearerID);
+ if (r != 0) {
+ Error = GetErrorCode(); return r;
+ }
+
if (mk3WearerID.Length > WearerNameLength) mk3WearerID.Length = WearerNameLength;
memcpy(WearerName, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0;
- ResetEvent(Ev1);
- token = BeginReadWearerId(epdComsHandle, static_cast(WearerIdType::WearerId_Primary), completion);
+ //ResetEvent(Ev1);
+ token = BeginReadWearerId(epdComsHandle, static_cast(WearerIdType::WearerId_Primary), nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadWearerId(epdComsHandle, token, &mk3WearerID);
+ if (r != 0) {
+ Error = GetErrorCode(); return r;
+ }
+
if (mk3WearerID.Length > WearerIDLength) mk3WearerID.Length = WearerIDLength;
memcpy(this->WearerID, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0;
for (int i = 0; i < mk3WearerID.Length; i++)
@@ -300,10 +326,10 @@ WORD MK3::Epd2U::ReadStatus()
//MK2 .. some utc... but no real time clock
if (utc == 0) {
- ResetEvent(Ev1);
- token = BeginReadRTC(epdComsHandle, completion);
+ //ResetEvent(Ev1);
+ token = BeginReadRTC(epdComsHandle, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2
EpdClock = utc;
utc = TimeFunctions::NowToEpdTime(true);
@@ -568,11 +594,11 @@ WORD MK3::Epd2U::ReadSensitivitiesAndTresholds()
uint16_t FBthresh;
uint16_t HGthresh;
- ResetEvent(Ev1);
+ //ResetEvent(Ev1);
//token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion);
- token = BeginReadCalibrationData_R2(epdComsHandle, completion);
+ token = BeginReadCalibrationData_R2(epdComsHandle, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r=EndReadCalibrationData_R2(epdComsHandle, token,
&HGSens10,
&SGSens10,
@@ -602,7 +628,8 @@ WORD MK3::Epd2U::ReadSensitivitiesAndTresholds()
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadDetectorThresholds_R3(epdComsHandle, token, dTresholds, MaxTresholds, &numTresholds);
-
+ decodedTresholds(numTresholds);
+
ResetEvent(Ev1);
token = BeginReadSensitivities(epdComsHandle,nullptr,0, completion);
r = Commit(epdComsHandle);
@@ -629,17 +656,18 @@ WORD MK3::Epd2U::ReadDoses()
ReadDosesQualityRV = ReadPeaksRV = CommitRV = 0;
numDoses = 0; utc = 0;
- ResetEvent(Ev1);
- token = BeginReadDoses(epdComsHandle, nullptr, 0, completion);
+ SetResponseTimeout(epdComsHandle, 2000);
+ //ResetEvent(Ev1);
+ token = BeginReadDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadDoses(epdComsHandle, token, doses, MaxDoses, &numDoses, &utc);
decodeDoses(numDoses);
- ResetEvent(Ev1);
- token = BeginReadTotalDoses(epdComsHandle, nullptr, 0, completion);
+ //ResetEvent(Ev1);
+ token = BeginReadTotalDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadTotalDoses(epdComsHandle, token, totdoses, MaxDoses, &numtotDoses, &utc);
decodetotDoses(numtotDoses);
@@ -783,59 +811,26 @@ WORD MK3::Epd2U::ReadAlarmTresholds() {
bool isNeutron = (EpdType == EpdTypes::Mk2Neutron || EpdType == EpdTypes::Mk3Neutron);
uint8_t measID;
+ uint32_t r;
-// Start CheckEverything
-
- ResetEvent(Ev1);
- hp07tresholds.MeasId = (uint8_t)0;
- token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
- int32_t r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
- r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
- decodeTreshold(&hp07tresholds);
-
- ResetEvent(Ev1);
- hp07tresholds.MeasId = (uint8_t)1;
- token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
- r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
- r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
- decodeTreshold(&hp07tresholds);
-
- ResetEvent(Ev1);
- hp07tresholds.MeasId = (uint8_t)2;
- token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
- r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
- r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
- decodeTreshold(&hp07tresholds);
-
- ResetEvent(Ev1);
- hp07tresholds.MeasId = (uint8_t)3;
- token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
- r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
- r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
- decodeTreshold(&hp07tresholds);
-
- // End CheckEverything
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
- ResetEvent(Ev1);
+ SetResponseTimeout(epdComsHandle, 2000);
+ //ResetEvent(Ev1);
hp07tresholds.MeasId = measID;
- token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId,nullptr,0, completion);
+ token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t) hp07tresholds.MeasId,nullptr,0, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
- hp10tresholds.MeasId = measID;
- ResetEvent(Ev1);
- token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, nullptr, 0, completion);
+ hp10tresholds.MeasId = 0;
+ //ResetEvent(Ev1);
+ token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, nullptr, 0, nullptr);
r = Commit(epdComsHandle);
- r = WaitForSingleObject(Ev1, 10000); // no time-out interval
+ //r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp10tresholds);
decodeTreshold(&hp10tresholds);
return r;
diff --git a/MK3/sEpdBase.cpp b/MK3/sEpdBase.cpp
new file mode 100644
index 0000000..9b54c07
--- /dev/null
+++ b/MK3/sEpdBase.cpp
@@ -0,0 +1,10 @@
+#include "pch.h"
+#include "sEpdBase.h"
+
+namespace MK3 {
+ sEpdBase::sEpdBase(Epd2^ p) {
+ par = p;
+ CurrentDeviceID = 0;
+ isIssued = isBG = isMK3 = 0;
+ }
+}
diff --git a/MK3/sEpdBase.h b/MK3/sEpdBase.h
new file mode 100644
index 0000000..7c401b1
--- /dev/null
+++ b/MK3/sEpdBase.h
@@ -0,0 +1,109 @@
+#pragma once
+#include "MK3.h"
+
+#pragma managed
+using namespace System;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+#include
+#include
+
+
+
+namespace MK3 {
+ const char* cEpdError = "Setreader Error";
+ public ref class sEpdBase
+ {
+ public:
+ int CurrentDeviceID;
+ bool isIssued;
+ bool isBG;
+ bool isMK3;
+ Epd2^ par;
+
+ public:
+ sEpdBase(Epd2^ p);
+ delegate void dEpdRead(sEpdBase^ Sender, EpdEventArgs^ e);
+ delegate void dEpdTO(sEpdBase^ Sender, EventArgs^ e);
+ delegate void dEpdError(sEpdBase^ Sender, EpdErrorEventArgs^ e);
+
+ public:
+ dEpdRead^ _EpdRead;
+ dEpdTO^ _EpdTO;
+ dEpdError^ _EpdError;
+
+ public:
+ /*event dEpdRead^ EpdRead
+ {
+ void add(dEpdRead^ handler)
+ {
+ _EpdRead += handler;
+ }
+
+ void remove(dEpdRead^ handler)
+ {
+ _EpdRead -= handler;
+ }
+ }
+ event dEpdError^ EpdError
+ {
+ void add(dEpdError^ handler)
+ {
+ _EpdError += handler;
+ }
+
+ void remove(dEpdError^ handler)
+ {
+ _EpdError -= handler;
+ }
+ }
+ event dEpdTO^ EpdTO
+ {
+ void add(dEpdTO^ handler)
+ {
+ _EpdTO += handler;
+ }
+
+ void remove(dEpdTO^ handler)
+ {
+ _EpdTO -= handler;
+ }
+ }*/
+
+ };
+ public ref class EpdEventArgs : EventArgs
+ {
+ public:
+ int deviceID;
+ bool isIssued, isBG, isMK3;
+
+ EpdEventArgs(sEpdBase^ eb) : EventArgs()
+ {
+ this->deviceID = eb->CurrentDeviceID;
+ this->isIssued = eb->isIssued;
+ this->isBG = eb->isBG;
+ this->isMK3 = eb->isMK3;
+ }
+
+ };
+ public ref struct EpdException : System::Exception
+ {
+ public:
+ int errorCode;
+ EpdException(int r) : System::Exception(gcnew String(cEpdError))
+ {
+ this->errorCode = r;
+ }
+ };
+ public ref class EpdErrorEventArgs : EventArgs
+ {
+ public:
+ int returnValue;
+
+ EpdErrorEventArgs(int ReturnValue) : EventArgs()
+ {
+ this->returnValue = ReturnValue;
+ }
+
+ };
+}
\ No newline at end of file
diff --git a/TestEPD3Dll/Program.cs b/TestEPD3Dll/Program.cs
index 6b092d3..f3a3eea 100644
--- a/TestEPD3Dll/Program.cs
+++ b/TestEPD3Dll/Program.cs
@@ -22,7 +22,7 @@ namespace TestEPD3Dll
x.Connect(false);
//var rv = x.SetTime();
rv = x.GetStatus();
- //x.ReadAlarmTresholds();
+ x.ReadAlarmTresholds();
rv = x.GetDoses();
x.SetDeIssued();
//x.WriteCalibration();
diff --git a/eDosStation/EntryBadge.xaml b/eDosStation/EntryBadge.xaml
index 83c8a85..be308d0 100644
--- a/eDosStation/EntryBadge.xaml
+++ b/eDosStation/EntryBadge.xaml
@@ -253,8 +253,8 @@
-
-
+
+
diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs
index 9efe9c0..e83b6eb 100644
--- a/eDosStation/EntryBadge.xaml.cs
+++ b/eDosStation/EntryBadge.xaml.cs
@@ -3,7 +3,9 @@ using System.Data;
using System.Text;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Data;
using System.Windows.Documents;
+using System.Windows.Shapes;
using System.Windows.Threading;
namespace eDosStation
@@ -40,30 +42,59 @@ namespace eDosStation
public SimulateData simulData = new SimulateData();
#endif
- public EntryBadge(EpdBaseClr.Epd2 curEP, Station curStation)
+ public EntryBadge(Station curStation)
{
InitializeComponent();
dataInterface = curStation.dataInterface;
- ep = curEP;
+ ep = new EpdBaseClr.Epd2(curStation.ComPort);
+ ep.SetFeedbackSound(curStation.useBeep);
+
+ ep.EpdRead += Ep_EpdRead;
+ ep.EpdError += Ep_EpdError;
+ ep.EpdTO += Ep_EpdTO;
thisStation = curStation;
_User = null;
taskLoading = true;
}
+ private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EventArgs e)
+ {
+ MessageBox.Show("EPD timeout");
+ endPage();
+
+ }
+
+ private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => {
+ MessageBox.Show($"EPD Error {e.returnValue}");
+ endPage();
+ });
+
+ }
+
+ private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => GetEPD());
+ }
+
+
+
private bool LoadDoses()
{
bool rv = true;
+ int rva = 0;
System.Diagnostics.Debug.WriteLine("LoadDoses: EPD GEt Status");
- int rva = ep.GetStatus();
+ //int rva = ep.GetStatus();
#if SimulateEPD
ep.CountsClock = 12345;
ep.alarmStatus = 0;
ep.otherAlarms = 0;
#endif
- if (rva != 1)
- {
- MessageBox.Show($"Entry GetStatus error {rva} {ep.GetStatusError}");
- }
+ //if (rva != 0)
+ //{
+ // MessageBox.Show($"Entry GetStatus error {rva} {ep.GetStatusError}");
+ //}
System.Diagnostics.Debug.WriteLine($"LoadDoses: EPD {ep.EpdID} Type:{ep.epdType}");
statusEPD.Text = $"EPD: {ep.EpdID}";
if (ep.Issued)
@@ -80,26 +111,59 @@ namespace eDosStation
//MessageBox.Show("EPD is currently issued\nPlease take an other", "EDP", MessageBoxButton.OK, MessageBoxImage.Hand, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
- this.Close();
+ endPage();
return false;
}
if (ep.alarmStatus != 0 || (ep.otherAlarms & 0x7f) != 0)
{
- StringBuilder sb = new StringBuilder("EPD is in alarm status\n\n");
- if (ep.alarmStatus > 0) sb.AppendLine("- Alarm dose");
- if (ep.OtherAlarmBatLow > 0) sb.AppendLine("- Battery Low");
- sb.AppendLine();
- sb.AppendLine("Please take another");
- MessageBox.Show(sb.ToString(), "EDP", MessageBoxButton.OK, MessageBoxImage.Hand, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
- this.Close();
+ TextBlock il = new TextBlock();
+ il.Inlines.Add(new Run("EPD is in alarm status\n\n")
+ {
+ FontSize = 36
+ }); ;
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ if (ep.alarmStatus > 0) il.Inlines.Add(new Run("* Dose alarm *"));
+ if (ep.OtherAlarmBatLow > 0) il.Inlines.Add(new Run("* Battery Low *"));
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new Run("Please take an other."));
+ il.HorizontalAlignment = HorizontalAlignment.Center;
+ il.TextAlignment = System.Windows.TextAlignment.Center;
+ (new InstMessage(il)).ShowDialog();
+ endPage();
return false;
}
-
- //bool isBG = ep.epdType == 0;
if (ep.isBG != CurTaskRow.EPDRad.Equals("BG"))
{
- MessageBox.Show("Wrong EPD Type", "EDP", MessageBoxButton.OK, MessageBoxImage.Hand, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
- this.Close();
+ string curtype = null, needdtype = string.Empty;
+ if (ep.isBG) curtype = "BG Beta-Gamma"; else curtype = "NG (Neutron)";
+ if (CurTaskRow.EPDRad.Equals("BG")) needdtype = "BG (Beta-Gamma)"; else needdtype = "NG (Neutron)";
+
+ TextBlock il = new TextBlock();
+ il.Inlines.Add(new Run("This EPD is not the right type")
+ {
+ FontSize = 36
+ }); ;
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(InstMessage.GetFullWidthLine());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new Run($"This task needs a {needdtype} EPD,\n this is a {curtype}")
+ {
+ Background = System.Windows.Media.Brushes.Yellow
+ }); ;
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(InstMessage.GetFullWidthLine());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new LineBreak());
+ il.Inlines.Add(new Run("Please take an other."));
+ il.HorizontalAlignment = HorizontalAlignment.Center;
+ il.TextAlignment = System.Windows.TextAlignment.Center;
+ (new InstMessage(il)).ShowDialog();
+ endPage();
return false;
}
@@ -119,11 +183,12 @@ namespace eDosStation
dispatcherTimer.Stop();
ep.Close();
System.Threading.Thread.Sleep(200);
+
int rv = ep.Connect(false,thisStation.EPDTimeOut);
System.Diagnostics.Debug.WriteLine($"Connect {rv} error {ep.ConnectError}");
- if (ep.DeviceCount > 0 && ep.b.CurrentDeviceID > 0)
+ if (ep.DeviceCount > 0 && ep.EpdID > 0)
{
- System.Diagnostics.Debug.WriteLine($"Devices:{ep.DeviceCount} id:{ep.b.CurrentDeviceID} {ep.ConnectError} ");
+ System.Diagnostics.Debug.WriteLine($"Devices:{ep.DeviceCount} id:{ep.EpdID} {ep.ConnectError} ");
EpdFound = true;
DoEPD();
}
@@ -145,47 +210,51 @@ namespace eDosStation
{
int? StationVisitID = null;
int? ID_Visit = null;
- try
- {
- ID_Visit = DataInterface.NextID();
- } catch (System.Exception ex)
- {
- MessageBox.Show($"Error {ex.Message}");
- }
- if (ID_Visit.HasValue && LoadDoses())
- {
- bool isBG = ep.isBG; // (ep.epdType != 3); //3 = zwarte 0=grijs
- var co = dataInterface.getCon(true);
- dataInterface.VisitInitCommand.Connection = co;
- dataInterface.VisitInitCommand.Parameters["ID_Station"].Value = thisStation.ID_Station;
- dataInterface.VisitInitCommand.Parameters["ID_Visit"].Value = ID_Visit;
- dataInterface.VisitInitCommand.Parameters["PersID"].Value = _User.PersID;
- dataInterface.VisitInitCommand.Parameters["ID_Task"].Value = CurTaskRow.ID_Task;
- dataInterface.VisitInitCommand.Parameters["Inst_CODE"].Value = CurTaskRow.Inst_CODE;
- dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID;
- dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG;
- dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock;
- using (var l = new SqlLog())
- try
- {
- dataInterface.VisitInitCommand.ExecuteNonQuery();
- l.LogCommand(dataInterface.VisitInitCommand);
- }
- catch (System.Exception ex)
- {
- l.LogCommand(ex.Message);
- MessageBox.Show(ex.Message);
- }
- StationVisitID = (int?)dataInterface.VisitInitCommand.Parameters["EPDVisitID"].Value;
- co.Close();
- int rv = ep.PrepareForIssue();
- if (rv != 1)
+ if (LoadDoses())
+ {
+ try
{
- MessageBox.Show($"PrepareForIssue error {ep.PrepareForIssueError}");
+ ID_Visit = DataInterface.NextID();
}
- ep.WearerID = StationVisitID.ToString();
- ep.WearerName = _User.PersID.ToString();
+ catch (System.Exception ex)
+ {
+ MessageBox.Show($"Error {ex.Message}");
+ }
+ if (ID_Visit.HasValue)
+ {
+ bool isBG = ep.isBG; // (ep.epdType != 3); //3 = zwarte 0=grijs
+ var co = dataInterface.getCon(true);
+ dataInterface.VisitInitCommand.Connection = co;
+ dataInterface.VisitInitCommand.Parameters["ID_Station"].Value = thisStation.ID_Station;
+ dataInterface.VisitInitCommand.Parameters["ID_Visit"].Value = ID_Visit;
+ dataInterface.VisitInitCommand.Parameters["PersID"].Value = _User.PersID;
+ dataInterface.VisitInitCommand.Parameters["ID_Task"].Value = CurTaskRow.ID_Task;
+ dataInterface.VisitInitCommand.Parameters["Inst_CODE"].Value = CurTaskRow.Inst_CODE;
+ dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID;
+ dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG;
+ dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock;
+ using (var l = new SqlLog())
+ try
+ {
+ dataInterface.VisitInitCommand.ExecuteNonQuery();
+ l.LogCommand(dataInterface.VisitInitCommand);
+ }
+ catch (System.Exception ex)
+ {
+ l.LogCommand(ex.Message);
+ MessageBox.Show(ex.Message);
+ }
+ StationVisitID = (int?)dataInterface.VisitInitCommand.Parameters["EPDVisitID"].Value;
+ co.Close();
+
+ int rv = ep.PrepareForIssue();
+ if (rv != 1)
+ {
+ MessageBox.Show($"PrepareForIssue error {ep.PrepareForIssueError}");
+ }
+ ep.WearerID = StationVisitID.ToString();
+ ep.WearerName = _User.PersID.ToString();
#if SimulateEPD
simulData.EdpType = ep.epdType;
@@ -193,32 +262,32 @@ namespace eDosStation
simulData.WearerName = ep.WearerName;
#endif
- ep.Hp07RateOn = CurTaskRow.HP07RateON;
- ep.Hp07RateOff = CurTaskRow.HP07RateOFF;
- ep.Hp10Rate1On = CurTaskRow.HP10Rate1ON;
- ep.Hp10Rate1Off = CurTaskRow.HP10Rate1ON;
- ep.Hp10Rate2On = CurTaskRow.HP10Rate2ON;
- ep.Hp10Rate2Off = CurTaskRow.HP10Rate2ON;
- ep.Hp10THDose1 = CurTaskRow.Hp10Dose1;
- ep.Hp10THDose2 = CurTaskRow.Hp10Dose2;
- ep.Hp07THDose = CurTaskRow.Hp07Dose;
- int? kx = null;
- if (!CurTaskRow.IsFNGain_ANGainValueNull()) kx = (int)CurTaskRow.FNGain_ANGainValue;
- if (kx != null && (ep.K3 != kx || ep.K4 != kx))
- {
- ep.K3 = ep.K4 = kx.Value;
- if (!ep.isBG)
+ ep.Hp07RateOn = CurTaskRow.HP07RateON;
+ ep.Hp07RateOff = CurTaskRow.HP07RateOFF;
+ ep.Hp10Rate1On = CurTaskRow.HP10Rate1ON;
+ ep.Hp10Rate1Off = CurTaskRow.HP10Rate1ON;
+ ep.Hp10Rate2On = CurTaskRow.HP10Rate2ON;
+ ep.Hp10Rate2Off = CurTaskRow.HP10Rate2ON;
+ ep.Hp10THDose1 = CurTaskRow.Hp10Dose1;
+ ep.Hp10THDose2 = CurTaskRow.Hp10Dose2;
+ ep.Hp07THDose = CurTaskRow.Hp07Dose;
+ int? kx = null;
+ if (!CurTaskRow.IsFNGain_ANGainValueNull()) kx = (int)CurTaskRow.FNGain_ANGainValue;
+ if (kx != null && (ep.K3 != kx || ep.K4 != kx))
{
- if (ep.K6 != 1310)
+ ep.K3 = ep.K4 = kx.Value;
+ if (!ep.isBG)
{
- MessageBox.Show("Alarm");
- }
- else
- {
- ep.WriteCalibration();
+ if (ep.K6 != 1310)
+ {
+ MessageBox.Show("Alarm");
+ }
+ else
+ {
+ ep.WriteCalibration();
+ }
}
}
- }
#if DummyData
ep.Hp07THDose = 70;
ep.Hp10THDose1 = 11;
@@ -236,34 +305,32 @@ namespace eDosStation
ep.WriteCalibration();
#endif
-
- rv = ep.SetIssued();
- if (rv != 1)
- {
- MessageBox.Show($"SetIssued error {ep.SetIssuedError}");
+ rv = ep.SetIssued();
+ if (rv != 1)
+ {
+ MessageBox.Show($"SetIssued error {ep.SetIssuedError}");
+ }
+ panelDone.Visibility = bEpdDone.Visibility = Visibility.Visible;
+ panelWait.Visibility = Visibility.Collapsed;
}
- panelDone.Visibility= bEpdDone.Visibility = Visibility.Visible;
- panelWait.Visibility = Visibility.Collapsed;
}
- else
- ep.Close();
-
}
- private void GetEPD()
+
+ private void SearchEPD()
{
EpdFound = false;
if (_User == null || CurTaskRow == null) return;
- int ok = ep.Connect(false,thisStation.EPDTimeOut);
- if (ok != 1)
- {
- statusEPD.Text= $"GetEpd {ok} Connect Error: {ep.ConnectError}";
- }
+ ep.Wait(10000, 1);
+ return;
+ }
- if (ep.DeviceCount == 1 && ep.b.CurrentDeviceID > 0)
+ private void GetEPD()
+ {
+ if (ep.DeviceCount == 1 && ep.EpdID> 0)
{
statusEPD.Text = string.Empty;
EpdFound = true;
- DoEPD();
+ DoEPD();
}
if (!EpdFound)
{
@@ -423,20 +490,27 @@ namespace eDosStation
{
try
{
+ if (ep != null)
+ {
+ ep.WaitEnd();
+ ep.Dispose();
+ }
if (dfReader != null)
{
dfReader.WaitEnd();
dfReader.Dispose();
}
}
- catch { }
+ catch (System.Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine(ex.Message);
+ }
this.Close();
}
private void bClose_Click(object sender, RoutedEventArgs e)
{
- dfReader?.Dispose(); dfReader = null;
- this.Close();
+ endPage();
}
private void BClear_Click(object sender, RoutedEventArgs e)
@@ -480,7 +554,7 @@ namespace eDosStation
panelDone.Visibility = bEpdDone.Visibility = Visibility.Collapsed;//1
panelWait.Visibility = Visibility.Visible;
statusEPD.Text = "Waiting for EPD (max 10 seconds)";
- Dispatcher.InvokeAsync(new Action(() => { GetEPD(); }),DispatcherPriority.Background);
+ Dispatcher.InvokeAsync(new Action(() => { SearchEPD(); }),DispatcherPriority.Background);
}
}
}
diff --git a/eDosStation/EpdExit.xaml.cs b/eDosStation/EpdExit.xaml.cs
index a1b3dd4..3f32778 100644
--- a/eDosStation/EpdExit.xaml.cs
+++ b/eDosStation/EpdExit.xaml.cs
@@ -34,37 +34,65 @@ namespace eDosStation
#if SimulateEPD
public SimulateData simulData = new SimulateData();
#endif
- public EpdExit(EpdBaseClr.Epd2 curEP, Station curStation)
+ public EpdExit( Station curStation)
{
InitializeComponent();
- ep = curEP;
+ //ep = curEP;
+ ep = new EpdBaseClr.Epd2(curStation.ComPort);
+ ep.SetFeedbackSound(curStation.useBeep);
+
+ ep.EpdRead += Ep_EpdRead;
+ ep.EpdError += Ep_EpdError;
+ ep.EpdTO += Ep_EpdTO;
thisStation = curStation;
dataInterface = curStation.dataInterface;
}
+ private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => {
+ MessageBox.Show("Time out");
+ endPage();
+ });
+
+ }
+
+ private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => {
+ MessageBox.Show("EPD error");
+ endPage();
+ });
+ }
+
+ private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => LoadDoses());
+ }
+
private void ShowAlarm()
{
}
private void LoadDoses()
{
- //Zet timeout op dit scherm
- if (dispatcherTimer == null)
- {
- dispatcherTimer = new DispatcherTimer();
- dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
- } else
- {
- dispatcherTimer.Stop();
- dispatcherTimer.Tick -= DispatcherTimer_IsEPDFound;
- }
- dispatcherTimer.Tick += DispatcherTimer_WindowTimeoutAndClose; ;
- int rv= ep.GetStatus();
- if (rv != 1)
- {
- int er= ep.GetStatusError;
- MessageBox.Show($"GetStatus {rv} error {er}");
- }
+ ////Zet timeout op dit scherm
+ //if (dispatcherTimer == null)
+ //{
+ // dispatcherTimer = new DispatcherTimer();
+ // dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
+ //} else
+ //{
+ // dispatcherTimer.Stop();
+ // dispatcherTimer.Tick -= DispatcherTimer_IsEPDFound;
+ //}
+ //dispatcherTimer.Tick += DispatcherTimer_WindowTimeoutAndClose; ;
+ //int rv = 1; //ep.GetStatus();
+ //if (rv != 1)
+ //{
+ // int er= ep.GetStatusError;
+ // MessageBox.Show($"GetStatus {rv} error {er}");
+ //}
#if SimulateEPD
ep.epdType = simulData.EdpType;
@@ -80,34 +108,33 @@ namespace eDosStation
if (!ep.Issued)
{
(new InstMessage("This EPD is not issued")).ShowDialog();
- //MessageBox.Show("This EPD is not issued","EDP",MessageBoxButton.OK,MessageBoxImage.Hand,MessageBoxResult.OK,MessageBoxOptions.ServiceNotification);
- this.Close();
+ endPage();
return;
} else if (ep.EpdID==0)
{
(new InstMessage("The EPD is not found")).ShowDialog();
- //MessageBox.Show("This EPD is not read", "EDP", MessageBoxButton.OK, MessageBoxImage.Hand, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
+ endPage();
}
- bool NoTimeout = false;
+ //bool NoTimeout = false;
if (ep.alarmStatus != 0)
{
DosePanel.Background = AlarmBrush;
Alarm.IsSelected = true;
- NoTimeout = true;
+ //NoTimeout = true;
}
else if ((ep.otherAlarms & 0x7f) != 0)
{
DosePanel.Background = AlarmBrush;
OtherAlarm.IsSelected = true;
- NoTimeout = true;
+ //NoTimeout = true;
} else
{
DosePanel.Background = GreenBrush;
ok.IsSelected = true;
}
- rv = ep.ReadExtraStatus(); //D1 BaseD1 ...
+ int rv = ep.ReadExtraStatus(); //D1 BaseD1 ...
if (rv != 1)
{
MessageBox.Show($"ReadExtraStatus {rv}");
@@ -127,7 +154,7 @@ namespace eDosStation
HpDose10.Text = $"Hp10: {ep.Hp10:0.00} µSv";
if (int.TryParse(ep.WearerID, out int EpdVisitID))
{
- bool isBG = (ep.epdType == 3);
+ bool isBG = ep.isBG;
rv = ep.SetDeIssued(); //includes close
if (rv != 1)
{
@@ -151,28 +178,29 @@ namespace eDosStation
l.Dispose();
}
- if (!NoTimeout) dispatcherTimer.Start(); //Knop hide
+ //if (!NoTimeout) dispatcherTimer.Start(); //Knop hide
return;
}
private void DispatcherTimer_WindowTimeoutAndClose(object sender, EventArgs e)
{
dispatcherTimer.Stop();
- this.Close();
+ endPage();
}
private void StartScan()
{
EpdFound = false;
+ ep.Wait(10000, 2);
int rv = ep.Connect(false,thisStation.EPDTimeOut);
- if (rv == 1 && ep.DeviceCount > 0 && ep.b.CurrentDeviceID > 0)
- {
- EpdFound = true;
- statusEPD.Content = $"StartScan : EPD: {ep.b.CurrentDeviceID}";
- LoadDoses();
- }
- else this.Close();
+ //if (rv == 1 && ep.DeviceCount > 0 && ep.EpdID> 0)
+ //{
+ // EpdFound = true;
+ // statusEPD.Content = $"StartScan : EPD: {ep.EpdID}";
+ // LoadDoses();
+ //}
+ //else this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
@@ -188,10 +216,10 @@ namespace eDosStation
EpdFound = false;
int rv = ep.Connect(false,thisStation.EPDTimeOut);
- if (rv==1 && ep.DeviceCount > 0 && ep.b.CurrentDeviceID>0)
+ if (rv==1 && ep.DeviceCount > 0 && ep.EpdID>0)
{
EpdFound = true;
- statusEPD.Content = $"EPD: {ep.b.CurrentDeviceID}";
+ statusEPD.Content = $"EPD: {ep.EpdID}";
LoadDoses();
}
if (!EpdFound)
@@ -209,18 +237,29 @@ namespace eDosStation
private void BCloseExit_Click(object sender, RoutedEventArgs e)
{
- this.Close();
+ endPage();
}
private void BConfirmAlarm_Click(object sender, RoutedEventArgs e)
{
- this.Close();
+ endPage();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
- if (dispatcherTimer?.IsEnabled == true) dispatcherTimer.IsEnabled = false;
- dispatcherTimer = null;
+ //if (dispatcherTimer?.IsEnabled == true) dispatcherTimer.IsEnabled = false;
+ //dispatcherTimer = null;
+ }
+
+ public void endPage()
+ {
+ try
+ {
+ dispatcherTimer = null;
+ if (ep != null) { ep.WaitEnd(); ep.Dispose(); }
+ }
+ catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); }
+ this.Close();
}
}
}
diff --git a/eDosStation/InstMessage.xaml.cs b/eDosStation/InstMessage.xaml.cs
index caf7a66..c124ea3 100644
--- a/eDosStation/InstMessage.xaml.cs
+++ b/eDosStation/InstMessage.xaml.cs
@@ -34,6 +34,15 @@ namespace eDosStation
AddComment(tbComments);
}
+ public static Line GetFullWidthLine()
+ {
+ Line line = new Line() { Stroke = System.Windows.Media.Brushes.Blue };
+ Binding binding = new Binding("ActualWidth");
+ binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(TextBlock) };
+ BindingOperations.SetBinding(line, Line.X2Property, binding);
+ return line;
+ }
+
private void BMsg_Click(object sender, RoutedEventArgs e)
{
Close();
diff --git a/eDosStation/MainWindow.xaml.cs b/eDosStation/MainWindow.xaml.cs
index c717edd..b0dcbe6 100644
--- a/eDosStation/MainWindow.xaml.cs
+++ b/eDosStation/MainWindow.xaml.cs
@@ -23,7 +23,6 @@ namespace eDosStation
{
public DataInterface dataInterface;
public Station thisStation;
- public EpdBaseClr.Epd2 ep = null;
DispatcherTimer bgTimer;
#if SimulateEPD
@@ -36,13 +35,13 @@ namespace eDosStation
private void Button_Click(object sender, RoutedEventArgs e)
{
- var w = new ShowEPDDose(ep, thisStation);
+ var w = new ShowEPDDose( thisStation);
w.ShowDialog();
}
private void BEntry_Click(object sender, RoutedEventArgs e)
{
- var w = new EntryBadge(ep, thisStation);
+ var w = new EntryBadge(thisStation);
w.ShowDialog();
#if SimulateEPD
simulData = w.simulData;
@@ -52,7 +51,7 @@ namespace eDosStation
private void BExit_Click(object sender, RoutedEventArgs e)
{
- var w = new EpdExit(ep, thisStation);
+ var w = new EpdExit(thisStation);
#if SimulateEPD
w.simulData = simulData;
#endif
@@ -132,8 +131,8 @@ namespace eDosStation
#if SimulateEPD
thisStation.ComPort = 0;
#endif
- ep = new EpdBaseClr.Epd2(thisStation.ComPort);
- ep.SetFeedbackSound(thisStation.useBeep);
+ //ep = new EpdBaseClr.Epd2(thisStation.ComPort);
+ //ep.SetFeedbackSound(thisStation.useBeep);
}
catch (System.Exception ex)
{
diff --git a/eDosStation/ShowEPDDose.xaml b/eDosStation/ShowEPDDose.xaml
index b41ea35..a2974ca 100644
--- a/eDosStation/ShowEPDDose.xaml
+++ b/eDosStation/ShowEPDDose.xaml
@@ -33,20 +33,20 @@
-
+
-
+
-
+
-
+
diff --git a/eDosStation/ShowEPDDose.xaml.cs b/eDosStation/ShowEPDDose.xaml.cs
index 1f0c4d6..f9b571f 100644
--- a/eDosStation/ShowEPDDose.xaml.cs
+++ b/eDosStation/ShowEPDDose.xaml.cs
@@ -22,20 +22,44 @@ namespace eDosStation
{
Station thisStation;
EpdBaseClr.Epd2 ep;
- bool EpdFound = false;
- DispatcherTimer dispatcherTimer;
- int Search;
+ //bool EpdFound = false;
+ //DispatcherTimer dispatcherTimer;
+ //int Search;
- public ShowEPDDose(EpdBaseClr.Epd2 curEP, Station curStation)
+ public ShowEPDDose( Station curStation)
{
InitializeComponent();
- ep = curEP;
+ //ep = curEP;
+ ep = new EpdBaseClr.Epd2(curStation.ComPort);
+ ep.SetFeedbackSound(curStation.useBeep);
+
+ ep.EpdRead += Ep_EpdRead;
+ ep.EpdError += Ep_EpdError;
+ ep.EpdTO += Ep_EpdTO;
thisStation = curStation;
}
+ private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => endPage());
+ }
+
+ private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => {
+ MessageBox.Show($"Error {e.returnValue}");
+ endPage();
+ });
+ }
+
+ private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e)
+ {
+ Dispatcher.InvokeAsync(() => LoadDoses());
+ }
+
private void LoadDoses()
{
- ep.GetStatus();
+ //ep.GetStatus();
isIssued.Text = ep.Issued ? "Yes" : "no";
Wearer.Text = ep.WearerName;
EpdVisit.Text = ep.WearerID.ToString();
@@ -70,23 +94,25 @@ namespace eDosStation
private void GetEPD()
{
- EpdFound = false;
- int ConnectRV = 0;
- try
- {
- ConnectRV = ep.Connect(false, thisStation.EPDTimeOut);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show($"Error loading dll's {ex.Message}");
- }
- if (ConnectRV == 1 && ep.DeviceCount == 1)
- {
- EpdFound = true;
- statusEPD.Content = $"EPD: {ep.b.CurrentDeviceID}";
- LoadDoses();
- }
- else endPage();
+ //EpdFound = false;
+ ep.Wait(10000, 1);
+
+ //int ConnectRV = 0;
+ //try
+ //{
+ // ConnectRV = ep.Connect(false, thisStation.EPDTimeOut);
+ //}
+ //catch (System.Exception ex)
+ //{
+ // MessageBox.Show($"Error loading dll's {ex.Message}");
+ //}
+ //if (ConnectRV == 1 && ep.DeviceCount == 1)
+ //{
+ // EpdFound = true;
+ // statusEPD.Content = $"EPD: {ep.EpdID}";
+ // LoadDoses();
+ //}
+ //else endPage();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
@@ -96,18 +122,28 @@ namespace eDosStation
private void endPage()
{
- dispatcherTimer?.Stop();
- if (ep!=null) ep.Close();
+ //dispatcherTimer?.Stop();
+ try
+ {
+ if (ep != null)
+ {
+ ep.WaitEnd();
+ ep.Dispose();
+ }
+ } catch (System.Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine(ex.Message);
+ }
this.Close();
}
private void DispatcherTimer_Tick(object sender, EventArgs e)
{
- dispatcherTimer.Stop();
+ //dispatcherTimer.Stop();
ep.Connect(false, thisStation.EPDTimeOut);
if (ep.DeviceCount == 1)
{
- EpdFound = true;
- statusEPD.Content = $"EPD: {ep.b.CurrentDeviceID}";
+ //EpdFound = true;
+ statusEPD.Content = $"EPD: {ep.EpdID}";
LoadDoses();
}
else endPage();
diff --git a/eDosStation/eDosStation.csproj b/eDosStation/eDosStation.csproj
index 310e66b..feaf223 100644
--- a/eDosStation/eDosStation.csproj
+++ b/eDosStation/eDosStation.csproj
@@ -42,7 +42,7 @@
full
false
bin\Debug\
- TRACE;DEBUG;noSimulateEPD,DummyData
+ TRACE;DEBUG;noSimulateEPD,noDummyData
prompt
4
true