eDosStation/EpdBaseClr/EpdBaseClr.cpp

293 lines
7.1 KiB
C++
Raw Normal View History

2019-02-01 17:35:18 +01:00
#include "stdafx.h"
#include "EpdBaseClr.h"
EpdBaseClr::Epd2::Epd2(int port)
{
2019-02-26 16:54:57 +01:00
//HANDLE hMod = LoadLibrary(L"Reader2.dll");
2019-02-01 17:35:18 +01:00
b = gcnew sEpdBase();
2021-03-26 17:20:57 +01:00
epd = new EpdBase::Epd2U(port);
2019-02-01 17:35:18 +01:00
this->InitRV = epd->InitRv;
2020-02-18 14:06:52 +01:00
epd->StartCom();
2019-02-01 17:35:18 +01:00
}
2019-02-04 11:48:08 +01:00
EpdBaseClr::Epd2::~Epd2()
{
delete b;
2019-02-25 09:12:08 +01:00
delete epd;
2019-02-04 11:48:08 +01:00
this->!Epd2();
}
EpdBaseClr::Epd2::!Epd2()
{
}
int EpdBaseClr::Epd2::SetFeedbackSound(byte sound)
{
epd->EndSessionControl = sound;
return 0;
}
2021-05-12 12:35:50 +02:00
/// <summary>
/// find Epd
/// </summary>
/// <param name="reinit"></param>
/// <returns>0 = no discovery 1=ok </returns>
int EpdBaseClr::Epd2::Connect(bool reinit, int EPDTimeout)
2019-02-01 17:35:18 +01:00
{
2020-02-05 14:21:53 +01:00
ConnectError = 0;
2019-02-01 17:35:18 +01:00
b->CurrentDeviceID = 0;
2021-05-12 12:35:50 +02:00
2020-02-18 14:06:52 +01:00
DeviceCount = 0;
2021-03-26 17:20:57 +01:00
DiscRV = 0;
if (epd != nullptr) {
if (epd->CommsInitialized == 0) epd->StartCom();
2021-05-12 12:35:50 +02:00
DiscRV = epd->StartDiscover(EPDTimeout);
2021-03-26 17:20:57 +01:00
if (DiscRV == 1)
{
DeviceCount = epd->DeviceCount;
if (epd->DeviceCount >= 0) b->CurrentDeviceID = epd->DeviceIDs[0];
}
else {
ConnectError = epd->Error;
}
2020-02-05 14:21:53 +01:00
}
2019-02-01 17:35:18 +01:00
return DiscRV;
}
2019-02-04 11:48:08 +01:00
int EpdBaseClr::Epd2::Close()
{
b->CurrentDeviceID = 0;
2021-03-26 17:20:57 +01:00
if (epd!=nullptr) epd->Close();
2019-02-04 11:48:08 +01:00
return 0;
}
2020-02-18 14:06:52 +01:00
int EpdBaseClr::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;
}
2019-02-01 17:35:18 +01:00
int EpdBaseClr::Epd2::GetStatus()
{
2020-02-05 14:21:53 +01:00
GetStatusError = 0; StatusRV = 0; Issued = false;
2019-02-11 11:34:52 +01:00
WearerID = String::Empty;
WearerName = String::Empty;
2020-02-05 14:21:53 +01:00
StatusRV = epd->ReadStatus();
if (StatusRV != 1 ) GetStatusError=epd->Error;
2019-02-01 17:35:18 +01:00
Issued = epd->EPDIssued;
WearerID = gcnew String((char *)epd->WearerID);
WearerName = gcnew String((char *)epd->WearerName);
isOn = (epd->DetectorsOn != 0);
2019-02-04 11:48:08 +01:00
epdType = epd->EpdType;
2021-05-20 16:13:23 +02:00
isBG = (epd->EpdType == 0 || epd->EpdType==4); //MK2 BG=0 or MK3 BG=4 3=MK2 Neuruon 7=MK3 neutron
2019-02-04 11:48:08 +01:00
alarmStatus = epd->AlarmStatus;
otherAlarms = epd->OtherAlarms;
errorStatus = epd->ErrorStatus;
operatingStatus = epd->OperatingStatus;
2020-02-18 14:06:52 +01:00
2019-02-04 11:48:08 +01:00
EpdID = epd->EpdID;
HardVersion = epd->HardVersion;
SoftVersion = epd->SoftVersion;
FunctionFlags = epd->FunctionFlags;
2021-04-22 16:52:44 +02:00
CountsClock = epd->EpdClock;
2020-02-18 14:06:52 +01:00
DecodeStatus();
2019-02-01 17:35:18 +01:00
return StatusRV;
}
int EpdBaseClr::Epd2::GetDoses()
{
Hp10 = Hp07 = 0.0;
2019-02-04 11:48:08 +01:00
ReadDosesRV = epd->ReadDoses();
if (ReadDosesRV == 1) {
2020-02-05 14:21:53 +01:00
GetDosesError = 0;
2019-02-04 11:48:08 +01:00
Hp10 = (double)epd->Hp10Dose / 64.0;
Hp07 = (double)epd->Hp07Dose / 64.0;
Hp07Peak = (double)epd->Hp07Peak / 64.0;
Hp10Peak = (double)epd->Hp10Peak / 64.0;
2019-02-11 11:34:52 +01:00
Hp07Total = epd->Hp07Total / 64.0;
Hp10Total = epd->Hp10Total / 64.0;
2020-02-05 14:21:53 +01:00
}
else {
GetDosesError = epd->Error;
2019-02-04 11:48:08 +01:00
}
2021-04-16 10:38:48 +02:00
if (epd->Hp10Time > 0) {
double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
Hp10PeakTime = System::DateTime::Now.AddSeconds(x);
}
else
2019-02-12 07:33:18 +01:00
Hp10PeakTime = System::Nullable<System::DateTime>();;
2021-04-16 10:38:48 +02:00
if (epd->Hp07Time > 0) {
double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
Hp07PeakTime = System::DateTime::Now.AddSeconds(x);
}
2019-02-12 07:33:18 +01:00
else
Hp10PeakTime = System::Nullable<System::DateTime>();
2019-02-11 11:34:52 +01:00
QualityData = epd->QualityData;
K1 = epd->K1;
K2 = epd->K2;
K3 = epd->K3;
K4 = epd->K4;
2019-02-14 15:56:23 +01:00
K5 = epd->K5;
K6 = epd->K6;
SG = epd->SG;
2019-02-11 11:34:52 +01:00
BC = epd->SG;
FB = epd->FB;
HG = epd->HG;
2019-02-04 11:48:08 +01:00
return ReadDosesRV;
}
2019-02-01 17:35:18 +01:00
int EpdBaseClr::Epd2::SetDeIssued()
{
return epd->DeIssue();
}
int EpdBaseClr::Epd2::PrepareForIssue()
{
2020-02-05 14:21:53 +01:00
PrepareForIssueError = 0;
int rv= epd->PrepareForIssue();
if (rv != 1) PrepareForIssueError = epd->Error;
return rv;
}
2019-02-01 17:35:18 +01:00
int EpdBaseClr::Epd2::SetIssued()
{
2020-02-05 14:21:53 +01:00
SetIssuedError = 0;
2021-04-16 10:38:48 +02:00
epd->Hp07THDose = (DWORD)(Hp07THDose*64.0);
epd->Hp10THDose1 = (DWORD)(Hp10THDose1*64.0);
epd->Hp10THDose2 = (DWORD)(Hp10THDose2*64.0);
epd->Hp10Rate1On = (DWORD)(Hp10Rate1On);
epd->Hp10Rate2On = (DWORD)(Hp10Rate2On);
epd->Hp07RateOn = (DWORD)(Hp07RateOn);
epd->Hp10Rate1Off = (DWORD)(Hp10Rate1Off);
epd->Hp10Rate2Off = (DWORD)(Hp10Rate2Off);
epd->Hp07RateOff = (DWORD)(Hp07RateOff);
2019-02-01 17:35:18 +01:00
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);
2019-02-01 17:35:18 +01:00
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
memset(epd->WearerName, 0, WearerNameLength + 1);
char* str2 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerName);
2019-02-11 11:34:52 +01:00
l = strlen(str2);
if (l > WearerNameLength) l = WearerNameLength;
_memccpy(epd->WearerName, str2, l, WearerNameLength);
2019-02-01 17:35:18 +01:00
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
2021-05-21 16:22:20 +02:00
2020-02-05 14:21:53 +01:00
int rv = epd->Issue();
if (rv != 1) SetIssuedError = epd->Error;
return rv;
2019-02-04 11:48:08 +01:00
}
2019-02-12 16:01:47 +01:00
int EpdBaseClr::Epd2::WriteCalibration()
{
2019-02-14 15:56:23 +01:00
epd->K1 = K1;
epd->K2 = K2;
2019-02-12 16:01:47 +01:00
epd->K3 = K3;
epd->K4 = K4;
2019-02-14 15:56:23 +01:00
epd->K5 = K5;
epd->K6 = K6;
//epd->K1 = 903;
//epd->K2 = 613;
//epd->K5 = 13100;
//epd->K6 = 1310;
int rv = epd->WriteCal();
2019-02-12 16:01:47 +01:00
return rv;
}
2019-02-04 11:48:08 +01:00
int EpdBaseClr::Epd2::ReadTresholds()
{
2020-02-05 14:21:53 +01:00
ReadTresholdsError = 0;
int rv= epd->ReadTresHolds();
if (rv != 0) ReadTresholdsError = epd->Error;
2019-02-04 11:48:08 +01:00
Hp10THDose1 = (double)epd->Hp10THDose1 / 64.0;
Hp10THDose2 = (double)epd->Hp10THDose2 / 64.0;
Hp07THDose = (double)epd->Hp07THDose / 64.0;
2019-02-11 11:34:52 +01:00
Hp10Total = (double)epd->Hp10Total / 64.0;
Hp07Total = (double)epd->Hp07Total / 64.0;
2019-02-04 11:48:08 +01:00
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;
2021-04-22 16:52:44 +02:00
2019-02-04 11:48:08 +01:00
2020-02-05 14:21:53 +01:00
return rv;
2019-02-12 16:01:47 +01:00
}
int EpdBaseClr::Epd2::ReadExtraStatus()
{
int rv = epd->EPDReadExtraStatus();
BatADC = epd->byBatADC;
SupplyADC = epd->bySupplyADC;
2019-02-14 15:56:23 +01:00
D1 = epd->D1 - epd->BaseD1;
D2 = epd->D2 - epd->BaseD2;
D3 = epd->D3 - epd->BaseD3;
D4 = epd->D4 - epd->BaseD4;
CountsClock = epd->CountsClock;
2021-04-22 16:52:44 +02:00
CountsClockBase = epd->BaseCountsClock;
2019-02-14 15:56:23 +01:00
2019-02-12 16:01:47 +01:00
return rv;
2019-02-01 17:35:18 +01:00
}