// TestMK3.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include #include "EpdCommon.h" #include "Epd3.h" #include "TimeFunctions.h" #include // if not already included char comPort[] = "COM3"; 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 discovery2(CommsHandle hComms, DiscoveryId const discovered[], int32_t count) { EpdID = 0; DeviceCount = count; std::cout << "Discovered " << count << "\n"; if (count > 0) { EpdID = discovered[0].Id; EpdGen = discovered[0].Gen; memcpy(&Epd, &discovered[0], sizeof(DiscoveryId)); } else { EpdID = 0;EpdGen = EpdGeneration::None; memset(&Epd, 0, sizeof(DiscoveryId)); } SetEvent(Ev1); } 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; } int startCom() { 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 ); uint32_t ms1, ms, slots; bool state = true; GetResponseTimeout(epdComsHandle, &ms1); r = GetMultipleDiscoveryMode(epdComsHandle, &state); r = GetDiscoveryTimeslots(epdComsHandle, &slots); r = GetDiscoveryTimeout(epdComsHandle, &ms); SetDiscoveryCacheTimeout(epdComsHandle, 2000); SetResponseTimeout(epdComsHandle, 500); return r; } void endCom() { CloseHandle(Ev1); Ev1 = INVALID_HANDLE_VALUE; int r = CloseReader(epdComsHandle); r = DestroyReaderInterface(epdComsHandle); } void detectepd() { using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::duration; using std::chrono::milliseconds; int r,r2; int tries = 5; DeviceCount = 0; ResetEvent(Ev1); while (tries-- > 0 && DeviceCount == 0) { auto t1 = high_resolution_clock::now(); //memset(DevceIDs, 0, sizeof(DeviceIDs)); r = StartDiscovery(epdComsHandle, discovery2); if (r == 0) { r = WaitForSingleObject(Ev1, 10000); std::cout << "EPD " << EpdID << "\n"; } else { std::cout << "StartDiscovery failed " << r << "\n"; } r2 = StopDiscovery(epdComsHandle); auto t2 = high_resolution_clock::now(); auto elapsed = duration_cast(t2 - t1); std::cout << "Elapsed time: " << elapsed.count() << " ms\n"; } //std::cout << "wacht effen!\n"; //r = WaitForSingleObject(Ev1, 10000); // no time-out interval std::cout << "ok! r=" << r << ", r2=" << r2 << "\n"; } 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 "< 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