163 lines
4.6 KiB
C++
163 lines
4.6 KiB
C++
// TestMK3.cpp : This file contains the 'main' function. Program execution begins and ends there.
|
|
//
|
|
#include <wtypes.h>
|
|
#include <synchapi.h>
|
|
#include <iostream>
|
|
#include "EpdCommon.h"
|
|
#include "Epd3.h"
|
|
|
|
#include "TimeFunctions.h"
|
|
|
|
|
|
|
|
char comPort[] = "COM6";
|
|
CommsHandle epdComsHandle;
|
|
uint32_t EpdID;
|
|
EpdGeneration EpdGen;
|
|
DiscoveryId Epd;
|
|
int DeviceCount;
|
|
|
|
HANDLE Ev1 = INVALID_HANDLE_VALUE;
|
|
CompletionToken token;
|
|
StatusData_t status;
|
|
MeasValue_t doses[4];
|
|
uint8_t numDoses;
|
|
uint32_t utc,utc2;
|
|
uint8_t EC[]{ 0xE7 ,0xD3 ,0xE7 ,0x69 ,0xF3 ,0xF5 ,0x93 ,0xDA ,0xDC ,0xB8 ,0x63 ,0x4C ,0xC5 ,0xB0 ,0x9F ,0xC9 ,0x0D ,0xD3 ,0xA6 ,0x1C ,0x4A ,0x06 ,0xA7 ,0x9C ,0xB0 ,0x92 ,0x36 ,0x62 ,0xFE ,0x6F ,0xAE ,0x6B };
|
|
|
|
|
|
void WINAPI discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_t count)
|
|
{
|
|
EpdID = 0;
|
|
DeviceCount = count;
|
|
if (count > 0) {
|
|
EpdID = discovered[0].Id;
|
|
EpdGen = discovered[0].Gen;
|
|
}
|
|
memcpy(&Epd,&discovered[0],sizeof(DiscoveryId));
|
|
SetEvent(Ev1);
|
|
}
|
|
|
|
void WINAPI completion(CommsHandle hComms, CompletionToken token)
|
|
{
|
|
SetEvent(Ev1);
|
|
}
|
|
|
|
|
|
void ReadTime()
|
|
{
|
|
DWORD r;
|
|
DWORD EpdClock;
|
|
utc = 0;
|
|
token = BeginReadRTC(epdComsHandle, nullptr);
|
|
r = Commit(epdComsHandle);
|
|
if (!r)
|
|
r = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2
|
|
EpdClock = utc;
|
|
utc2 = TimeFunctions::NowToEpdTime(false);
|
|
|
|
}
|
|
|
|
int SetTime() //Only R3
|
|
{
|
|
int r = 0;
|
|
if (Epd.Gen == EpdGeneration::Mk3)
|
|
{
|
|
|
|
utc = TimeFunctions::NowToEpdTime(false);
|
|
token = BeginWriteRTC_R3(epdComsHandle, utc, nullptr);
|
|
r = Commit(epdComsHandle);
|
|
if (!r)
|
|
r = EndWriteRTC_R3(epdComsHandle, token); //EpdClock for MK2
|
|
|
|
}
|
|
return r;
|
|
}
|
|
|
|
void GetEPD()
|
|
{
|
|
epdComsHandle = CreateReaderInterface();
|
|
int r = OpenReader(epdComsHandle, comPort);
|
|
Ev1 = CreateEvent(
|
|
NULL, // default security attributes
|
|
TRUE, // manual-reset event
|
|
FALSE, // initial state is nonsignaled
|
|
TEXT("WriteEvent") // object name
|
|
);
|
|
|
|
int tries = 5; DeviceCount = 0;
|
|
while (tries-- > 0 && DeviceCount == 0)
|
|
{
|
|
//memset(DevceIDs, 0, sizeof(DeviceIDs));
|
|
r = StartDiscovery(epdComsHandle, discovery);
|
|
if (r == 0) r = WaitForSingleObject(Ev1, 10000);
|
|
}
|
|
|
|
|
|
std::cout << "wacht effen!\n";
|
|
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
|
|
|
|
std::cout << "ok!\n";
|
|
|
|
|
|
|
|
|
|
r = Connect(epdComsHandle,Epd, true);
|
|
// -9 = r_OperationTimeout
|
|
std::cout << "Connect rv " << r << "\n";
|
|
ResetEvent(Ev1);
|
|
|
|
|
|
|
|
|
|
std::cout << "get status\n";
|
|
token = BeginReadStatus(epdComsHandle, completion);
|
|
r = Commit(epdComsHandle);
|
|
r = WaitForSingleObject(Ev1, 1000); // no time-out interval
|
|
r = EndReadStatus(epdComsHandle, token, &status);
|
|
std::cout << "got status "<<r<<"\n";
|
|
|
|
ReadTime();
|
|
SetTime();
|
|
ReadTime();
|
|
|
|
//r = Connect(epdComsHandle, Epd, true);
|
|
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Admin, EC, 32, nullptr);
|
|
r = Commit(epdComsHandle);
|
|
//-7 r_InvalidState
|
|
r = EndWriteAccessLevel(epdComsHandle, token);
|
|
std::cout << "EndWriteAccessLevel rv " << r << "\n";
|
|
|
|
numDoses = 0; utc = 0;
|
|
ResetEvent(Ev1);
|
|
//token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion);
|
|
token = BeginReadDoses(epdComsHandle, nullptr, 0 , completion);
|
|
r = Commit(epdComsHandle);
|
|
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
|
|
r = EndReadDoses(epdComsHandle, token, doses, 2, &numDoses, &utc);
|
|
std::cout << "got doses " << r << "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
|
|
|
|
GetEPD();
|
|
std::cout << "Hello World!\n";
|
|
std::getchar();
|
|
}
|
|
|
|
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
|
|
// Debug program: F5 or Debug > Start Debugging menu
|
|
//C:\Program Files (x86)\Thermo Scientific\Unmanaged HtmlFiles
|
|
//
|
|
// Tips for Getting Started:
|
|
// 1. Use the Solution Explorer window to add/manage files
|
|
// 2. Use the Team Explorer window to connect to source control
|
|
// 3. Use the Output window to see build output and other messages
|
|
// 4. Use the Error List window to view errors
|
|
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
|
|
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
|