eDosStationFull/EpdBaseClr/EpdBaseClr.h

456 lines
9.3 KiB
C
Raw Permalink Normal View History

2026-08-18 12:15:26 +02:00
#pragma once
#pragma unmanaged
#include "..\EpdBase\EpdBase.h"
#pragma comment(lib,"dll2/Reader2.lib")
#undef EPDDLL_API
#pragma unmanaged
#include "../EpdBase3/Epd3Base.h"
#pragma comment(lib,"dll2/Reader32.lib")
#pragma managed
using namespace System;
using namespace System::Runtime::InteropServices;
namespace EpdBaseClr {
public enum class EpdSteps1
{
Idle = 0,
Running = 1,
Completed = 2,
Failed = 3
};
[UnmanagedFunctionPointer(CallingConvention::Cdecl)]
public delegate void ProgressCallbackDelegate(EpdSteps step, EpdStepResults result);
const char* cEpdError = "Setreader Error";
ref class Epd2;
public ref class cStepValues
{
public:
Int32 func;
Int32 commitrv;
Int32 endrv;
cStepValues();
~ cStepValues();
private:
};
cStepValues:: cStepValues()
{
func = -1; commitrv = -1; endrv = -1;
}
cStepValues::~ cStepValues()
{
}
public enum class EpdErrorCodes
{
EpdErrorNone = 0,
EpdErrorCancel = 1,
EpdErrorTimeout = 2,
EpdErrorOther = 4,
EpdErrorConnecting = 5
};
public ref class EpdEventArgs : EventArgs
{
public:
int deviceID;
bool isIssued, isBG, isMK3, retriesLeft;
EpdEventArgs(int epdID, bool epdIssued, bool isBG, bool isMK3, int retriesleft) : EventArgs()
{
this->deviceID = epdID;
this->isIssued = epdIssued;
this->isBG = isBG;
this->isMK3 = isMK3;
this->retriesLeft = retriesleft;
}
};
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;
int ErrorRV; int ErrorStep;
EpdErrorCodes ErrorEPD;
EpdErrorEventArgs(int ReturnValue) : EventArgs()
{
ErrorRV= ErrorStep = 0;
this->returnValue = ReturnValue;
}
EpdErrorEventArgs(int ReturnValue, EpdErrorCodes errorEPD, int errorStep) : EventArgs()
{
this->ErrorEPD = errorEPD;
this->ErrorRV = 99;
this->ErrorStep = errorStep;
this->returnValue = ReturnValue;
}
EpdErrorEventArgs(int ReturnValue, int errorRV, int errorStep) : EventArgs()
{
this->ErrorEPD = EpdErrorCodes::EpdErrorOther;
this->ErrorRV = errorRV;
this->ErrorStep = errorStep;
this->returnValue = ReturnValue;
}
};
public ref class EpdTOEventArgs : EventArgs
{
public:
int tries;
bool connecttimeout;
EpdTOEventArgs(int _tries, bool _connecttimeout) : EventArgs()
{
this->tries=_tries;
this->connecttimeout = _connecttimeout;
}
};
/*public ref class sEpdBase
{
public :
DateTime^ RealTime;
unsigned int CurrentDeviceID;
};*/
public ref class Epd2
{
/*private:
DateTime^ Jan2000;*/
const wchar_t* tHp07 = L"HP07";
const wchar_t* tHp10 = L"HP10";
const wchar_t* tHp07N = L"HPN";
const wchar_t* tHp10G = L"HP10G";
public:
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, EpdSteps step, EpdStepResults result);
dEpdRead^ _EpdRead;
dEpdTO^ _EpdTO;
dEpdError^ _EpdError;
dEpdProgress ^ _EpdProgress;
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;
}
}
event dEpdProgress^ EpdProgress
{
void add(dEpdProgress^ handler)
{
_EpdProgress += handler;
}
void remove(dEpdProgress^ handler)
{
_EpdProgress -= handler;
}
}
//private:
//bool hasAlarm = false;
public:
bool onlyMK2;
EpdBase::Epd2U *epd;
Epd3Base::Epd3U* epd3;
String^ Hp07Name;
String^ Hp10Name;
//System::Threading::ManualResetEvent^ cancelEvent;
void OnCancelRequested();
bool isTitleNG;
DateTime^ RealTime;
String^ WearerName;
String^ WearerID;
//bool Issued;
bool isOn;
bool isBG, isNG, VersionOK;
bool isMK3;
int InitRV;
int DiscRV;
int StatusRV;
int GetStatusError;
int GetDosesError;
int ReadTresholdsError;
int PrepareForIssueError;
int SetIssuedError;
int ConnectError;
int ReadDosesRV;
int DeviceCount = 0;
int ErrorStep=0;
int ErrorRV = 0;
EpdErrorCodes ErrorEPD;
double Hp07;
double Hp10;
double Hp07Peak;
double Hp10Peak;
System::Nullable<System::DateTime> Hp10PeakTime;
System::Nullable<System::DateTime> Hp07PeakTime;
double Hp07Total;
double Hp10Total;
double alarmHP07;
double alarmHP10;
double Hp10THDose1;
double Hp10THDose2;
double Hp07THDose;
double Hp10Rate1On;
double Hp10Rate2On;
double Hp07RateOn;
double Hp10Rate1Off;
double Hp10Rate2Off;
double Hp07RateOff;
double NGgain;
int K1;
int K2;
int K3;
int K4;
int K5;
int K6;
int SG;
int BC;
int FB;
int HG;
int QualityData;
unsigned int D1, D2, D3, D4, CountsClock, CountsClockBase;
int epdType;
int alarmStatus ;
int otherAlarms ;
int errorStatus ;
int operatingStatus ;
unsigned int EpdID ;
int HardVersion, HardVersionMinor;
int SoftVersion ;
int FunctionFlags ;
unsigned short BatADC;
unsigned short SupplyADC;
//OperatingStatus
BYTE DetectorsOn = 0;
bool EPDIssued = 0;
BYTE EPDLocked = 0;
BYTE EPDTesting = 0;
BYTE EPDProcSec = 0;
BYTE EPDFaulty = 0;
BYTE EPDTimeFault = 0;
//ERrrostatus
BYTE EPDNewFault = 0;
BYTE EPDComFault = 0;
BYTE EPDCalFault = 0;
BYTE EPDDetFault = 0;
BYTE EPDEprFault = 0;
BYTE EPDTrhFault = 0;
BYTE EPDOthFault = 0;
//AlarmStatus
BYTE AlarmDoseHP101G = 0;
BYTE AlarmDoseHP102G = 0;
BYTE AlarmDoseHP07N = 0;
BYTE AlarmRateHP101G = 0;
BYTE AlarmRateHP102G = 0;
BYTE AlarmRateHP07N = 0;
//OtherAlarm
BYTE OtherAlarmRateHp101G = 0;
BYTE OtherAlarmRateHp102G = 0;
BYTE OtherAlarmRateHp07N = 0;
BYTE OtherAlarmReturn = 0;
BYTE OtherAlarmBatLow = 0;
BYTE OtherAlarmCarrier = 0;
BYTE OtherAlarmBatVolt = 0;
//New fields
bool eDosDose07Warning =false;
bool eDosDose07Alarm = false;
bool eDosDose10Warning = false;
bool eDosDose10Alarm = false;
bool eDosRate07Warning = false;
bool eDosRate07Alarm = false;
bool eDosRate10Warning= false;
bool eDosRate10Alarm = false;
bool eDosBatteryWarning= false;
bool eDoshasAlarm = false;
bool eDosHasFault = false;
Epd2(int port, bool OnlyMK2);
~Epd2();
!Epd2();
//int StepReturnValues[50][3];
//int StepReturnMax;
//array<cStepValues^> StepReturnValues;
System::Collections::Generic::List<cStepValues^>^ StepReturnValues;
int SetFeedbackSound(byte sound, UINT16 sound3);
private:
int Connect(bool reinit, int EPDTimeout);
int Close();
int DecodeStatus(Epd3Base::Epd3U* epd);
int DecodeStatus(EpdBase::Epd2U* epd);
int GetStatus();
int GetDoses();
int GetDoses(EpdBase::Epd2U* epd);
int AfterGetDoses(Epd3Base::Epd3U* epd);
int GetDoses(Epd3Base::Epd3U* epd);
int ClearAlarms();
//int SetIssued();
int BeforeSetIssued(Epd3Base::Epd3U* epd);
//int SetIssued(Epd3Base::Epd3U* epd);
int BeforeSetIssued(EpdBase::Epd2U* epd);
//int SetIssued(EpdBase::Epd2U* epd);
int WriteCalibration();
int WriteCalibration(EpdBase::Epd2U* epd);
int WriteCalibration(Epd3Base::Epd3U* epd);
int ReadTresholds();
int AfterReadTresholds(EpdBase::Epd2U* epd);
int ReadTresholds(EpdBase::Epd2U* epd);
int AfterReadTresholds(Epd3Base::Epd3U* epd);
int ReadTresholds(Epd3Base::Epd3U* epd);
int ReadExtraStatus();
int ReadExtraStatus(EpdBase::Epd2U* epd);
int ReadExtraStatus(Epd3Base::Epd3U* epd);
int AfterGetDoses(EpdBase::Epd2U* epd);
int ConnectAndStatus();
int tokenSourceTimeout;
int readRetries;
System::Threading::Tasks::Task^ waitTask;
//int SetDeIssued();
public:
System::Threading::Tasks::Task^ Wait(int timeout, int Retries);
void WaitEnd();
int GetAll(bool close);
int GetAllDeissue(bool reconnect);
int IssueAndCheck(float gain, float ChirpRate, bool WriteConfig);
int GetSteps();
bool HasStepError();
private:
int AfterGetStatus(EpdBase::Epd2U* epd);
int AfterGetStatus(Epd3Base::Epd3U* epd);
int AfterGetStatus();
int SwitchCon();
void InitData();
void WaitEpd();
//int PrepareForIssue();
};
}
public ref class EpdHelpers
{
public:
static System::String^ EpdStepToString(EpdSteps step)
{
switch (step)
{
case EpdSteps::StepTest: return L"Test";
case EpdSteps::StepInitialized: return L"Initialized";
case EpdSteps::StepDiscovering: return L"Discovering";
case EpdSteps::StepConnecting: return L"Connecting";
case EpdSteps::StepReadStatus: return L"ReadStatus";
case EpdSteps::StepReadIdentities: return L"Read Identities";
case EpdSteps::StepReadCounts: return L"Read Counts";
case EpdSteps::StepReadRTC: return L"Read RTC";
case EpdSteps::StepReadWearerId: return L"Read WearerId";
default: return L"Unknown";
}
}
};