207 lines
No EOL
5.3 KiB
C++
207 lines
No EOL
5.3 KiB
C++
#include "pch.h"
|
|
#include "MK3Base.h"
|
|
#pragma unmanaged
|
|
|
|
MK3::Epd2U::Epd2U(int _comport)
|
|
{
|
|
port = _comport;
|
|
comPort[3] = 48 + _comport;
|
|
CommsInitialized = 0;
|
|
epdComsHandle = INVALID_HANDLE_VALUE;
|
|
//SetAutoCommit(0); alleen epd2
|
|
Error = 123;
|
|
if (_comport == 0) return;
|
|
}
|
|
|
|
WORD MK3::Epd2U::WriteConfig()
|
|
{
|
|
if (port == 0) return 1;
|
|
return 0; // WriteDisplayConfig(00, 2, 40, 10, 2, displayConfig, 56);
|
|
}
|
|
|
|
DWORD MK3::Epd2U::StartCom()
|
|
{
|
|
DWORD rv;
|
|
ErrorReason = 0;
|
|
int mx = 10;
|
|
if (port == 0) {
|
|
CommsInitialized = 1;
|
|
return 1;
|
|
}
|
|
if (CommsInitialized == 0) {
|
|
epdComsHandle = CreateReaderInterface();
|
|
rv = OpenReader(epdComsHandle, comPort);
|
|
if (InitRv == 0)
|
|
{
|
|
SetMultipleDiscoveryMode(epdComsHandle, false);
|
|
//SetRetryCount(epdComsHandle, retry);
|
|
//SetDiscoveryTimeslotPeriod(port, DiscoveryTimeslotPeriod);
|
|
//DiscoveryTimeout(epdComsHandle,DiscoveryExpirationPeriod);
|
|
CommsInitialized = 1;
|
|
}
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
MK3::Epd2U::~Epd2U()
|
|
{
|
|
if (epdComsHandle != INVALID_HANDLE_VALUE) DestroyReaderInterface(epdComsHandle);
|
|
CommsInitialized = 0;
|
|
}
|
|
|
|
void WINAPI MK3::Epd2U::discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_t count)
|
|
{
|
|
if (count > 0)
|
|
{
|
|
current->CurrentDeviceID = discovered[0].Id;
|
|
memcpy(¤t->Epd, &discovered[0], sizeof(DiscoveryId));
|
|
SetEvent(Ev1);
|
|
}
|
|
}
|
|
|
|
int MK3::Epd2U::StartDiscover()
|
|
{
|
|
int32_t rv;
|
|
|
|
//System::Diagnostics::Trace::WriteLine("StartDiscover");
|
|
Error = 0;
|
|
if (port == 0) {
|
|
DeviceCount = 1;
|
|
DeviceIDs[0] = 768;
|
|
return 1;
|
|
}
|
|
|
|
Cancel(epdComsHandle);
|
|
//FlushDiscoveryCache(port);
|
|
//FlushBuffers(port);
|
|
int tries = 25; DeviceCount = 0; DiscRV = 1;
|
|
while (tries-- > 0 && DeviceCount == 0)
|
|
{
|
|
//memset(DevceIDs, 0, sizeof(DeviceIDs));
|
|
current = this;
|
|
Ev1 = CreateEvent(NULL, TRUE,FALSE,NULL);
|
|
rv = StartDiscovery(epdComsHandle, discovery);
|
|
rv = WaitForSingleObject(Ev1, 10000);
|
|
}
|
|
//System::Diagnostics::Trace::WriteLine(System::String::Format("Discover DeviceCount = {0}", DeviceCount));
|
|
return DiscRV;
|
|
}
|
|
void MK3::Epd2U::Open(DWORD DeviceID)
|
|
{
|
|
CurrentDeviceID = DeviceID;
|
|
if (port > 0) {
|
|
ConRV = Connect(DeviceID);
|
|
if (ConRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
else {
|
|
OpenRV = OpenDevice(port, CurrentDeviceID);
|
|
if (OpenRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
}
|
|
}
|
|
else { OpenRV = ConRV = 1; }
|
|
}
|
|
void MK3::Epd2U::Close()
|
|
{
|
|
if (port > 0) CloseDevice();
|
|
//DeinitComms(port); CommsInitialized = 0;
|
|
}
|
|
|
|
void MK3::Epd2U::DecodeFunctionFlags()
|
|
{
|
|
EpdType = (FunctionFlags & 0x1F00) >> 8;
|
|
}
|
|
void MK3::Epd2U::DecodeStatus()
|
|
{
|
|
DetectorsOn = (OperatingStatus & 1) != 0;
|
|
EPDIssued = (OperatingStatus & 4) != 0;
|
|
EPDLocked = (OperatingStatus & 0x10) != 0;
|
|
EPDTesting = (OperatingStatus & 0x20) != 0;
|
|
EPDProcSec = (OperatingStatus & 0x40) != 0;
|
|
EPDFaulty = (OperatingStatus & 0x80) != 0;
|
|
|
|
EPDNewFault = (ErrorStatus & 1) != 0;
|
|
EPDComFault = (ErrorStatus & 2) != 0;
|
|
EPDCalFault = (ErrorStatus & 4) != 0;
|
|
EPDDetFault = (ErrorStatus & 8) != 0;
|
|
EPDEprFault = (ErrorStatus & 0x10) != 0;
|
|
EPDTrhFault = (ErrorStatus & 0x20) != 0;
|
|
EPDOthFault = (ErrorStatus & 0x80) != 0;
|
|
|
|
AlarmDoseHP101G = (AlarmStatus & 1) != 0;
|
|
AlarmDoseHP102G = (AlarmStatus & 2) != 0;
|
|
AlarmDoseHP07N = (AlarmStatus & 4) != 0;
|
|
AlarmRateHP101G = (AlarmStatus & 8) != 0;;
|
|
AlarmRateHP102G = (AlarmStatus & 0x10) != 0;
|
|
AlarmRateHP07N = (AlarmStatus & 0x20) != 0;
|
|
|
|
//OtherAlarm
|
|
OtherAlarmRateHp101G = (OtherAlarms & 1) != 0;
|
|
OtherAlarmRateHp102G = (OtherAlarms & 2) != 0;
|
|
OtherAlarmRateHp07N = (OtherAlarms & 4) != 0;
|
|
OtherAlarmReturn = (OtherAlarms & 8) != 0;
|
|
OtherAlarmBatLow = (OtherAlarms & 0x10) != 0;
|
|
OtherAlarmCarrier = (OtherAlarms & 0x20) != 0;
|
|
OtherAlarmBatVolt = (OtherAlarms & 0x40) != 0;
|
|
|
|
}
|
|
WORD MK3::Epd2U::ReadStatus()
|
|
{
|
|
Error = 0; ReadStatusRV = 0;
|
|
memset(WearerID, 0, WearerIDLength + 1);
|
|
memset(WearerName, 0, WearerNameLength + 1);
|
|
|
|
IssueCount = OperatingStatus = ErrorStatus = AlarmStatus = OtherAlarms = EEPROMBadSectors = 0;
|
|
RealTime = EpdClock = OffTime = EpdID = 0;
|
|
ErrorSource = ErrorReason = ErrorData = 0;
|
|
HardVersion = SoftVersion = FunctionFlags = 0;
|
|
|
|
if (port == 0) {
|
|
EpdID = 4567;
|
|
EpdType = 0;
|
|
FunctionFlags = 0x000;
|
|
return 1;
|
|
}
|
|
|
|
CommitRV = ReadEpdStatus(&EpdClock, &RealTime, &IssueCount, &OffTime, &OperatingStatus, &ErrorStatus, &AlarmStatus, &OtherAlarms, &EEPROMBadSectors);
|
|
if (port == 0) {
|
|
EpdClock = 123; ErrorStatus = 0;
|
|
};
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
if (CommitRV == 1) CommitRV = ReadEpdID(
|
|
&EpdID,
|
|
&HardVersion,
|
|
&SoftVersion,
|
|
&FunctionFlags);
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
if (CommitRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
ReadStatusRV = ErrorReason;
|
|
return 0;
|
|
}
|
|
else {
|
|
if (CurrentDeviceID == 0) CurrentDeviceID = EpdID;
|
|
time_t t = RealTime;
|
|
TimeFunctions::UnixTimeToSystemTime(t, &tRealTime);
|
|
DecodeStatus();
|
|
DecodeFunctionFlags();
|
|
}
|
|
|
|
if (CommitRV == 1 && EPDIssued == 1)
|
|
{
|
|
CommitRV = ReadWearer(
|
|
WearerID,
|
|
WearerIDLength,
|
|
WearerName,
|
|
WearerNameLength);
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
if (CommitRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
ReadStatusRV = ErrorReason;
|
|
return 0;
|
|
}
|
|
else {
|
|
for (int i = 0; i < WearerIDLength; i++)
|
|
if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30;
|
|
}
|
|
}
|
|
return CommitRV;
|
|
} |