98 lines
2.3 KiB
C++
98 lines
2.3 KiB
C++
|
|
#include <wtypes.h>
|
||
|
|
#include <synchapi.h>
|
||
|
|
#include <chrono>
|
||
|
|
#include <iostream>
|
||
|
|
#include <windows.h>
|
||
|
|
#include "reader2.h"
|
||
|
|
#pragma comment(lib,"Reader2.lib")
|
||
|
|
#include "TimeFunctions.h"
|
||
|
|
#include <cstdio> // if not already included
|
||
|
|
|
||
|
|
|
||
|
|
WORD port = 3;
|
||
|
|
DWORD DeviceIDs[8] = { 0,0,0,0,0,0,0,0 };
|
||
|
|
WORD Count = 0;
|
||
|
|
WORD rv,rv1,rv2,rv3,rv4,rv5,r6,r7;
|
||
|
|
|
||
|
|
DWORD EpdClock=1;
|
||
|
|
DWORD RealTime;
|
||
|
|
WORD IssueCount;
|
||
|
|
DWORD OffTime;
|
||
|
|
WORD OperatingStatus;
|
||
|
|
WORD ErrorStatus;
|
||
|
|
WORD AlarmsStatus;
|
||
|
|
WORD OtherAlarms;
|
||
|
|
WORD EEPROMBadSectors;
|
||
|
|
DWORD EpdID;
|
||
|
|
WORD HardVersion;
|
||
|
|
WORD SoftVersion;
|
||
|
|
WORD FunctionFlags;
|
||
|
|
DWORD Hp10Dose, Hp07Dose, Hp10Total, Hp07Total;
|
||
|
|
WORD Knocks, Resets, QualityData;
|
||
|
|
DWORD Hp10Peak, Hp07Peak, Hp10Time, Hp07Time;
|
||
|
|
|
||
|
|
int main()
|
||
|
|
{
|
||
|
|
std::cout << "Hello World!\n";
|
||
|
|
rv = InitComms(port, 9600, 8, 0, 0); //1=success
|
||
|
|
rv1 = Discover(port, DeviceIDs, 1, &Count);
|
||
|
|
rv2 = Connect(DeviceIDs[0]);
|
||
|
|
rv3= ReadEpdID(
|
||
|
|
|
||
|
|
&EpdID,
|
||
|
|
&HardVersion,
|
||
|
|
&SoftVersion,
|
||
|
|
&FunctionFlags);
|
||
|
|
|
||
|
|
rv4 = ReadEpdStatus(
|
||
|
|
|
||
|
|
&EpdClock,
|
||
|
|
&RealTime,
|
||
|
|
&IssueCount,
|
||
|
|
&OffTime,
|
||
|
|
&OperatingStatus,
|
||
|
|
&ErrorStatus,
|
||
|
|
&AlarmsStatus,
|
||
|
|
&OtherAlarms,
|
||
|
|
&EEPROMBadSectors);
|
||
|
|
rv5 = Commit();
|
||
|
|
|
||
|
|
|
||
|
|
//r6= ReadDosesQuality(
|
||
|
|
// &Hp10Dose, &Hp07Dose,
|
||
|
|
// &Hp10Total, &Hp07Total,
|
||
|
|
// &Knocks, &Resets, &QualityData);
|
||
|
|
//r7 = Commit();
|
||
|
|
|
||
|
|
r6 = ReadPeaks(
|
||
|
|
&Hp10Peak, &Hp07Peak,
|
||
|
|
&Hp10Time, &Hp07Time);
|
||
|
|
r7 = Commit();
|
||
|
|
|
||
|
|
FILETIME ft;
|
||
|
|
TimeFunctions::EPD2PeakTimeToFiletime(EpdClock, Hp10Time, &ft);
|
||
|
|
//TimeFunctions::Epd2TimeToFileTime(Hp10Time, &ft);
|
||
|
|
//UINT32 p = FileTime_to_POSIX(ft);
|
||
|
|
|
||
|
|
SYSTEMTIME stUtc, stLocal;
|
||
|
|
|
||
|
|
//// 1. Convert FILETIME to UTC SYSTEMTIME
|
||
|
|
FileTimeToSystemTime(&ft, &stUtc);
|
||
|
|
SystemTimeToTzSpecificLocalTime(NULL, &stUtc, &stLocal);
|
||
|
|
//char buffer[64];
|
||
|
|
//sprintf_s(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d",
|
||
|
|
// stLocal.wYear, stLocal.wMonth, stLocal.wDay,
|
||
|
|
// stLocal.wHour, stLocal.wMinute, stLocal.wSecond);
|
||
|
|
|
||
|
|
//printf("Formatted Time: %s\n", buffer);
|
||
|
|
|
||
|
|
//// 3B. Alternatively, use Windows Locale formatting (e.g., "8/9/2026 7:55:47 PM")
|
||
|
|
//wchar_t dateBuf[64], timeBuf[64];
|
||
|
|
//GetDateFormatEx(LOCALE_NAME_USER_DEFAULT, DATE_SHORTDATE, &stLocal, NULL, dateBuf, 64, NULL);
|
||
|
|
//GetTimeFormatEx(LOCALE_NAME_USER_DEFAULT, 0, &stLocal, NULL, timeBuf, 64);
|
||
|
|
|
||
|
|
//wprintf(L"Localized Time: %s %s\n", dateBuf, timeBuf);
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|