diff --git a/EpdBase/EpdBase.cpp b/EpdBase/EpdBase.cpp
index 89c4e25..7240eec 100644
--- a/EpdBase/EpdBase.cpp
+++ b/EpdBase/EpdBase.cpp
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "EpdBase.h"
-#define DiscoveryTimeslotPeriod 100
+#include "TimeFunctions.cpp"
+#define DiscoveryTimeslotPeriod 500
#define DiscoveryExpirationPeriod 6000
#define RxRetryCount 5
#define TxRetryCount 5
@@ -10,6 +11,10 @@ EpdBase::Epd2U::Epd2U(int comport)
{
port = comport;
CommsInitialized = 0;
+ Ev1 = INVALID_HANDLE_VALUE;
+ maxDiscoverTime = 10000;
+
+
if (port == 0) return;
SetAutoCommit(0);
Error = 123;
@@ -59,10 +64,15 @@ int EpdBase::Epd2U::StartDiscover()
{
//WORD rv;
//System::Diagnostics::Trace::WriteLine("StartDiscover");
+ Sleep(100);
Error = 0;
-
+ Ev1 = CreateWaitableTimer(NULL, TRUE, NULL);
+ LARGE_INTEGER wt ;
+ wt.QuadPart = Int32x32To64(maxDiscoverTime,-10000); //10 seconden proberen
+ //wt.QuadPart = -100000000LL;
+ if (Ev1!=NULL) SetWaitableTimer(Ev1, &wt, 0, NULL, NULL, FALSE);
//SetDiscoveryTimeslotCount(port, 2);
- //SetDiscoveryTimeslotPeriod(port, DiscoveryTimeslotPeriod);
+ SetDiscoveryTimeslotPeriod(port, DiscoveryTimeslotPeriod);
//SetDiscoveryExpirationPeriod(port, DiscoveryExpirationPeriod);
//rv =SetRetryCounts(RxRetryCount, TxRetryCount);
@@ -72,12 +82,13 @@ int EpdBase::Epd2U::StartDiscover()
DeviceIDs[0] = 768;
return 1;
}
-
FlushDiscoveryCache(port);
FlushBuffers(port);
- int tries = 25; DeviceCount = 0; DiscRV = 1;
- while (tries-- > 0 && DeviceCount == 0 )
+ int maxtries = 100; DeviceCount = 0; DiscRV = 1; DWORD wo = 1; // ongeveer 43 tries in 10 seconden
+ int tries = 0;
+ while (DeviceCount == 0 && wo!=0) //tries-- > 0 &&
{
+ tries++;
//memset(DeviceIDs, 0, sizeof(DeviceIDs));
DiscRV = Discover(port, DeviceIDs, MaxDevices, &DeviceCount);
//System::Diagnostics::Trace::WriteLine(System::String::Format("Discover try: {0} RV={1}", tries, DiscRV));
@@ -85,8 +96,10 @@ int EpdBase::Epd2U::StartDiscover()
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
//System::Diagnostics::Trace::WriteLine(System::String::Format("StartDiscover Error Connect Reason: {0} ErrorData {1}", ErrorReason, ErrorData));
}
+ wo = WaitForSingleObject(Ev1, 0);
}
//System::Diagnostics::Trace::WriteLine(System::String::Format("Discover DeviceCount = {0}", DeviceCount));
+ CloseHandle(Ev1); Ev1 = INVALID_HANDLE_VALUE;
return DiscRV;
}
void EpdBase::Epd2U::Open(DWORD DeviceID)
diff --git a/EpdBase/EpdBase.h b/EpdBase/EpdBase.h
index dde4b99..e50bd54 100644
--- a/EpdBase/EpdBase.h
+++ b/EpdBase/EpdBase.h
@@ -16,9 +16,9 @@ namespace EpdBase
DWORD DeviceIDs[10];
DWORD CurrentDeviceID;
- //WORD AlarmCtrl = 0b01111110;
- WORD AlarmCtrl = 0b01111010; // NO sound
- WORD EndSessionControl = 0b00010010;
+ WORD AlarmCtrl = 0b01111110;
+ //WORD AlarmCtrl = 0b01111010; // NO sound
+ WORD EndSessionControl = 0b00010110;
BYTE displayConfig[56] = { 0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
@@ -203,6 +203,8 @@ namespace EpdBase
BYTE byStatus3;
BYTE byStatus4;
+ int maxDiscoverTime = 10000;
+ LARGE_INTEGER WaitDiscovery;
int StartDiscover();
void Open(DWORD DeviceID);
void Close();
@@ -226,10 +228,9 @@ namespace EpdBase
WORD PrepareForIssue();
WORD DeIssue();
-
WORD Issue();
-
~Epd2U();
+ HANDLE Ev1 = INVALID_HANDLE_VALUE;;
};
}
diff --git a/EpdBase/EpdBase.vcxproj b/EpdBase/EpdBase.vcxproj
index a14be89..2b744cf 100644
--- a/EpdBase/EpdBase.vcxproj
+++ b/EpdBase/EpdBase.vcxproj
@@ -128,12 +128,6 @@
-
-
-
-
-
-
diff --git a/EpdBase/EpdBase.vcxproj.filters b/EpdBase/EpdBase.vcxproj.filters
index 1e03ebe..5d799cb 100644
--- a/EpdBase/EpdBase.vcxproj.filters
+++ b/EpdBase/EpdBase.vcxproj.filters
@@ -15,36 +15,18 @@
-
- Header Files
-
Header Files
Header Files
+
+ Header Files
+
Header Files
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
diff --git a/EpdBase/TimeFunctions.cpp b/EpdBase/TimeFunctions.cpp
index 0ca6217..1e53e3e 100644
--- a/EpdBase/TimeFunctions.cpp
+++ b/EpdBase/TimeFunctions.cpp
@@ -12,7 +12,7 @@ void TimeFunctions::UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
// Note that LONGLONG is a 64-bit value
LONGLONG ll;
-
+
ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = ll >> 32;
@@ -23,4 +23,12 @@ void TimeFunctions::UnixTimeToFileTime(time_t t, LPFILETIME pft)
FILETIME ft;
UnixTimeToFileTime(t, &ft);
FileTimeToSystemTime(&ft, pst);
-}
\ No newline at end of file
+}
+
+ void TimeFunctions::msToFileTime(UINT32 ms, LARGE_INTEGER &pft)
+ {
+ // Note that LONGLONG is a 64-bit value
+ LONGLONG ll;
+ ll = Int32x32To64(ms, 10000) ;
+ pft.QuadPart = ll;
+ }
diff --git a/EpdBase/TimeFunctions.h b/EpdBase/TimeFunctions.h
index 9756f33..aa837a0 100644
--- a/EpdBase/TimeFunctions.h
+++ b/EpdBase/TimeFunctions.h
@@ -8,6 +8,7 @@ public:
TimeFunctions();
static void UnixTimeToFileTime(time_t t, LPFILETIME pft);
static void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst);
+ static void msToFileTime(UINT32 ms, LARGE_INTEGER &pft);
};
diff --git a/eDosStation/EntryBadge.xaml b/eDosStation/EntryBadge.xaml
index 58ed806..238b258 100644
--- a/eDosStation/EntryBadge.xaml
+++ b/eDosStation/EntryBadge.xaml
@@ -17,7 +17,7 @@
-
+
@@ -44,7 +44,6 @@
-
@@ -65,7 +64,6 @@
-
@@ -218,20 +216,23 @@
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs
index 7f6586d..dc9209c 100644
--- a/eDosStation/EntryBadge.xaml.cs
+++ b/eDosStation/EntryBadge.xaml.cs
@@ -18,10 +18,10 @@ namespace eDosStation
Station thisStation;
EpdBaseClr.Epd2 ep;
bool EpdFound = false;
- DispatcherTimer dispatcherTimer;
+ DispatcherTimer dispatcherTimer, epdTimer;
int Search, UserSeconds;
Boolean Inst1 = false, Inst2 = false;
- private System.Threading.Tasks.Task ReaderTask =null;
+ private System.Threading.Tasks.Task ReaderTask = null;
private DataInterface dataInterface;
public LSWDesfirePublic.CCard dfReader = null;
//System.Threading.Thread t;
@@ -33,9 +33,9 @@ namespace eDosStation
static User _User;
DataSet1.GetTaskInfoRow CurTaskRow;
- enum eCOE { quiz=1} ;
-
-
+ enum eCOE { quiz = 1 };
+
+
#if SimulateEPD
public SimulateData simulData = new SimulateData();
@@ -54,7 +54,7 @@ namespace eDosStation
{
bool rv = true;
System.Diagnostics.Debug.WriteLine("LoadDoses: EPD GEt Status");
- int rva= ep.GetStatus();
+ int rva = ep.GetStatus();
#if SimulateEPD
ep.CountsClock = 12345;
ep.alarmStatus = 0;
@@ -72,10 +72,10 @@ namespace eDosStation
this.Close();
return false;
}
- if (ep.alarmStatus != 0 || (ep.otherAlarms & 0x7f)!=0)
+ if (ep.alarmStatus != 0 || (ep.otherAlarms & 0x7f) != 0)
{
StringBuilder sb = new StringBuilder("EPD is in alarm status\n\n");
- if (ep.alarmStatus>0) sb.AppendLine("- Alarm dose");
+ if (ep.alarmStatus > 0) sb.AppendLine("- Alarm dose");
if (ep.OtherAlarmBatLow > 0) sb.AppendLine("- Battery Low");
sb.AppendLine();
sb.AppendLine("Please take another");
@@ -90,7 +90,7 @@ namespace eDosStation
this.Close();
return false;
}
-
+
rva = ep.ReadTresholds();
if (rva != 1)
{
@@ -101,13 +101,15 @@ namespace eDosStation
}
private void DispatcherTimer_Tick(object sender, EventArgs e)
{
+ //Was timeout
+ //voorlopig niet meer gebruikt
EpdFound = false;
dispatcherTimer.Stop();
ep.Close();
System.Threading.Thread.Sleep(200);
- int rv= ep.Connect(false);
+ int rv = ep.Connect(false);
System.Diagnostics.Debug.WriteLine($"Connect {rv} error {ep.ConnectError}");
- if (ep.DeviceCount >0 && ep.b.CurrentDeviceID>0)
+ if (ep.DeviceCount > 0 && ep.b.CurrentDeviceID > 0)
{
System.Diagnostics.Debug.WriteLine($"Devices:{ep.DeviceCount} id:{ep.b.CurrentDeviceID} {ep.ConnectError} ");
EpdFound = true;
@@ -151,7 +153,7 @@ namespace eDosStation
dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID;
dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG;
dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock;
-
+
using (var l = new SqlLog())
try
@@ -224,31 +226,34 @@ namespace eDosStation
private void GetEPD()
{
if (_User == null || CurTaskRow == null) return;
-
int ok = ep.Connect(false);
if (ok != 1) System.Diagnostics.Debug.WriteLine($"GetEpd {ok} ConnectError: {ep.ConnectError}");
- if (ep.DeviceCount == 1 && ep.b.CurrentDeviceID>0)
+ if (ep.DeviceCount == 1 && ep.b.CurrentDeviceID > 0)
{
+ epdWait.Text = string.Empty;
EpdFound = true;
DoEPD();
}
if (!EpdFound)
{
- statusEPD.Text = $"EPD: Wait ";
- Search = 100;
- dispatcherTimer = new DispatcherTimer();
- dispatcherTimer.Tick += DispatcherTimer_Tick;
- dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
- dispatcherTimer.Start();
- return;
+ MessageBox.Show("EPD niet gevonden");
+ this.Close();
+ endPage();
+ //statusEPD.Text = $"EPD: Wait ";
+ //Search = 100;
+ //dispatcherTimer = new DispatcherTimer();
+ //dispatcherTimer.Tick += DispatcherTimer_Tick;
+ //dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
+ //dispatcherTimer.Start();
+ //return;
}
-
}
+
private void SetFilter(bool isAlara)
{
- Inst1 = (cbInst1.IsChecked ==true);
- Inst2 = (cbInst2.IsChecked ==true);
-
+ Inst1 = (cbInst1.IsChecked == true);
+ Inst2 = (cbInst2.IsChecked == true);
+
StringBuilder fi = new StringBuilder();
if (!Inst1 && !Inst2)
{
@@ -277,7 +282,7 @@ namespace eDosStation
public string getCommentUnknown()
{
StringBuilder res = new StringBuilder();
- var r = dataInterface.GetCommentOnEventRow(3);
+ var r = dataInterface.GetCommentOnEventRow(3);
res.AppendLine(r.Comment_NL).Replace("\\n", "\n");
res.AppendLine("---");
res.AppendLine(r.Comment_FR).Replace("\\n", "\n");
@@ -289,18 +294,18 @@ namespace eDosStation
public string getCommentOnEvent(string prefix, int id)
{
- string res=string.Empty;
+ string res = string.Empty;
if (!string.IsNullOrWhiteSpace(prefix)) res = prefix + "\n";
var r = dataInterface.GetCommentOnEventRow(id);
string l = _User?.Language ?? "E";
- if (r!=null)
- switch (l)
+ if (r != null)
+ switch (l)
{
- case "N": res += r.Comment_NL; break;
+ case "N": res += r.Comment_NL; break;
case "F": res += r.Comment_FR; break;
default: res += r.Comment_EN; break;
}
- return res.Replace("\\n","\n");
+ return res.Replace("\\n", "\n");
}
///
@@ -324,9 +329,9 @@ namespace eDosStation
else
{
tbUser.IsSelected = true;
- if (_User == null || _User.VisitIDLocked >0 || _User.AccessAllow == false)
+ if (_User == null || _User.VisitIDLocked > 0 || _User.AccessAllow == false)
{
- if (_User.VisitIDLocked > 0|| _User.AccessAllow == false)
+ if (_User.VisitIDLocked > 0 || _User.AccessAllow == false)
ReasonNoAccess = _User.ReasonNoAccess;
else ReasonNoAccess = getCommentOnEvent(string.Empty, 3);
}
@@ -354,7 +359,7 @@ namespace eDosStation
private void SwitchToTask(object sender, EventArgs e)
{
- if (--UserSeconds > 0 && (_User.AccessAllow!=true || !string.IsNullOrEmpty(_User.UserComment) || !string.IsNullOrEmpty(_User.ReasonNoAccess)))
+ if (--UserSeconds > 0 && (_User.AccessAllow != true || !string.IsNullOrEmpty(_User.UserComment) || !string.IsNullOrEmpty(_User.ReasonNoAccess)))
{
tUserSeconds.Text = UserSeconds.ToString();
pUserSeconds.Value = UserSeconds;
@@ -384,19 +389,18 @@ namespace eDosStation
}
public void showBadge(int persID, string csn)
{
- CSN.Text = csn;
- Site.Text = string.Empty;
- Code.Text = persID.ToString();
- Dispatcher.Invoke(CheckBadge);
+ CSN.Text = csn;
+ Site.Text = string.Empty;
+ Code.Text = persID.ToString();
+ Dispatcher.Invoke(CheckBadge);
}
-
public void endPage()
{
dfReader.WaitEnd();
dfReader.Dispose();
this.Close();
}
-
+
private void bClose_Click(object sender, RoutedEventArgs e)
{
dfReader?.Dispose(); dfReader = null;
@@ -409,6 +413,8 @@ namespace eDosStation
Code.Text = string.Empty;
}
+
+
private void TaskOK_Click(object sender, RoutedEventArgs e)
{
bool isOk = false;
@@ -429,21 +435,26 @@ namespace eDosStation
if (isOk)
{
- tbEPD.IsSelected = true;
System.Windows.Data.CollectionViewSource getTaskListViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("getTaskListViewSource")));
var rv = getTaskListViewSource.View.CurrentItem as DataRowView;
CurTaskRow = rv.Row as DataSet1.GetTaskInfoRow;
if (CurTaskRow.MinWorkerDosisMargin > _User.Margin)
{
MessageBox.Show("Margin exceeded");
+ endPage();
}
else
{
- GetEPD();
+ tb.SelectedItem = tbEPD;
+ bEpdDone.Visibility = Visibility.Hidden;//1
+ epdWait.Text = "Waiting max 10 seconds";
+ Dispatcher.Invoke(new Action(() => { GetEPD(); }),DispatcherPriority.ApplicationIdle);
}
}
}
+
+
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lb = sender as ListBox;
@@ -618,6 +629,17 @@ namespace eDosStation
endPage();
}
+
+
+
+ private void tb_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (e.AddedItems.Count>0 && e.AddedItems[0] is TabControl)
+ {
+
+ }
+ }
+
private void DfReader_BadgeTO(LSWDesfirePublic.CCard Sender, EventArgs e)
{
this.Dispatcher.Invoke(new Action(() => endPage()));