timeout handling search epd

This commit is contained in:
Luc 2021-05-03 09:56:58 +02:00
parent e176beb922
commit 90f7b2ca8e
8 changed files with 115 additions and 93 deletions

View file

@ -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)

View file

@ -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;;
};
}

View file

@ -128,12 +128,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\MK3\CommonEpdTypes.h" />
<ClInclude Include="..\MK3\Epd2.h" />
<ClInclude Include="..\MK3\Epd3.h" />
<ClInclude Include="..\MK3\EpdCommon.h" />
<ClInclude Include="..\MK3\Mk3Types.h" />
<ClInclude Include="..\MK3\TimeFunctions.h" />
<ClInclude Include="EpdBase.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />

View file

@ -15,36 +15,18 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="EpdBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EpdBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TimeFunctions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\CommonEpdTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\Epd2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\Epd3.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\EpdCommon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\Mk3Types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MK3\TimeFunctions.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="EpdBase.cpp">

View file

@ -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);
}
}
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;
}

View file

@ -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);
};

View file

@ -17,7 +17,7 @@
</Window.Resources>
<DockPanel>
<TabControl Name="tb" TabStripPlacement="Top" >
<TabControl Name="tb" TabStripPlacement="Top" SelectionChanged="tb_SelectionChanged" >
<TabItem Name="tbEntry" >
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Border Background="AliceBlue" TextBlock.FontSize="24" TextBlock.LineHeight="30px" Padding="20,20,20,20" CornerRadius="10" BorderThickness="2" BorderBrush="Blue" >
@ -44,7 +44,6 @@
<StackPanel Orientation="Horizontal" Margin="0,50,0,0" Name="pTestButtons">
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Name="tbUser" >
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical">
@ -65,7 +64,6 @@
<ProgressBar.Effect>
<DropShadowEffect/>
</ProgressBar.Effect>
</ProgressBar>
<TextBlock x:Name="tUserSeconds" Text="10" TextAlignment="Center" HorizontalAlignment="Stretch" />
<Button Content="OK" Name="bUserRead" Click="BUserRead_Click"/>
@ -218,20 +216,23 @@
</StackPanel>
</Grid>
</TabItem>
<TabItem Name="tbEPD">
<Grid>
<TabItem Name="tbEPD" FontSize="25" FontFamily="Comic Sans MS" >
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="50" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" FontSize="25" FontFamily="Comic Sans MS">
<Run Text="Issuing EPD:" />
<Run Name="statusEPD" Text="" />
<LineBreak/>
<TextBlock Grid.Row="0" FontSize="25" FontFamily="Comic Sans MS" Name="epdWait" Text="w" HorizontalAlignment="Center" TextAlignment="Center" />
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" FontSize="25" FontFamily="Comic Sans MS">
<Run Text="Issuing EPD:" />
<Run Name="statusEPD" Text="" /><LineBreak/>
</TextBlock>
<Image Grid.Row="1" Source="{StaticResource iBG}"/>
<Button Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" Background="LawnGreen" Padding="10,10,10,10" Content="OK" Name="bEpdDone" Visibility="Hidden" Click="bClose_Click" />
<Image Grid.Row="2" Source="{StaticResource iBG}"/>
<Button Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" Background="LawnGreen" Padding="10,10,10,10" Content="OK" Name="bEpdDone" Visibility="Hidden" Click="bClose_Click" />
</Grid>
</TabItem>
<TabItem Name="tbNotAllowed">

View file

@ -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");
}
/// <summary>
@ -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()));