Connect timeout !!

This commit is contained in:
Luc Vandenbroucke 2022-05-04 07:53:20 +02:00
parent e2656f9d0d
commit 5797105c55
8 changed files with 79 additions and 40 deletions

View file

@ -55,16 +55,19 @@ DWORD EpdBase::Epd2U::StartCom()
}
void EpdBase::Epd2U::EndCom()
{
if (port > 0 && CommsInitialized==1) DeinitComms(port);
if (port > 0 && CommsInitialized == 1) {
DeinitComms(port);
Sleep(300);
}
CommsInitialized = 0;
}
EpdBase::Epd2U::~Epd2U()
{
EndCom();
}
int EpdBase::Epd2U::StartDiscover( int EpdTimeout)
int EpdBase::Epd2U::StartDiscover( int EpdTimeoutms)
{
maxDiscoverTime = EpdTimeout;
maxDiscoverTime = EpdTimeoutms;
if (port == 0) {
DeviceCount = 1;
DeviceIDs[0] = 768;
@ -82,7 +85,8 @@ int EpdBase::Epd2U::StartDiscover( int EpdTimeout)
LARGE_INTEGER wt; //100 nanoseconds *10000 = millisec
//union { LARGE_INTEGER li; FILETIME ft; LONGLONG ll; } t1, t2;
//wt.QuadPart = -300000000LL;
wt.QuadPart = Int32x32To64(maxDiscoverTime, -15000); //15 seconden proberen
INT64 t = maxDiscoverTime+1000; t *= (INT64)-10000;
wt.QuadPart = t; // Int32x32To64(maxDiscoverTime, -10000); //15 seconden proberen
SetWaitableTimer(hWaitTimer, &wt, 0, NULL, NULL, 0);
while (DeviceCount == 0 && wo != 0) //tries-- > 0 &&
{
@ -597,14 +601,14 @@ int EpdBase::Epd2U::GetAll(bool Closeconnection)
/// </summary>
/// <param name="tokenSourceTimeout"></param>
/// <returns>0=success 1=connect error, 2 = no devices, 3= error reading status</returns>
int EpdBase::Epd2U::ConnectAndStatus(int tokenSourceTimeout)
int EpdBase::Epd2U::ConnectAndStatus(int tokenSourceTimeoutms)
{
WORD dllStatus;
int rv = 1;
if (CommsInitialized == 0) StartCom();
if (CommsInitialized == 0) rv = 1;
else {
dllStatus = StartDiscover(tokenSourceTimeout);
dllStatus = StartDiscover(tokenSourceTimeoutms);
if (dllStatus != 1) rv = 1; //Connect error
else if (DeviceCount < 1) rv = 2; //TO
else if (ReadStatus() != 0) rv = 1; //Read Error

View file

@ -146,6 +146,7 @@ void Epd3Base::Epd3U::EndCom()
int Epd3Base::Epd3U::StartDiscover(int tokentimeout)
{
int32_t rv=1;
int32_t rv2 = 0;
Error = 0;
if (port == 0) {
DeviceCount = 1;
@ -153,19 +154,22 @@ int Epd3Base::Epd3U::StartDiscover(int tokentimeout)
DeviceIDs[0] = 768;
return 0;
}
Dll3RV = SetDiscoveryCacheTimeout(epdComsHandle, tokentimeout);
//Dll3RV = Commit3(epdComsHandle);
DeviceCount = 0; ConnectTries = 1;
//rv2 = Cancel(epdComsHandle); Cancel bestaat niet
ResetEvent(hCompletion);
ConnectTimerFired = 0;
current = this;
Dll3RV = StartDiscovery(epdComsHandle, discovery);
if (Dll3RV == 0) {
Dll3RV = WaitForSingleObject(hCompletion, tokentimeout);
Dll3RV = WaitForSingleObject(hCompletion, tokentimeout+1000);
if (Dll3RV == WAIT_OBJECT_0) rv = 1;
else if (Dll3RV == WAIT_TIMEOUT) {
rv = 1; ConnectTimerFired = 1;
rv2= StopDiscovery(epdComsHandle);
DeviceCount = 0;
} else rv = 2;
}
if ( DeviceCount > 0) {
@ -445,7 +449,7 @@ error:
/// discover, connect and read status
/// </summary>
/// <param name="tokenSourceTimeout"></param>
/// <returns>0=success 1=connect error, 2 = no devices, 3= error reading status</returns>
/// <returns>0=success 1=connect error, 2 = time out , no devices, 3= error reading status</returns>
int Epd3Base::Epd3U::ConnectAndStatus(int tokenSourceTimeout)
{
WORD dllStatus;

View file

@ -810,7 +810,7 @@ int EpdBaseClr::Epd2::ConnectAndStatus()
int rv = 1;
if (!onlyMK2) epd->EndCom(); //indien Mk2
InitData();
Sleep(100);
//Sleep(100);
if (onlyMK2)
rv = epd->ConnectAndStatus(tokenSourceTimeout);
else
@ -867,7 +867,7 @@ void EpdBaseClr::Epd2::WaitEpd()
_EpdRead(this, gcnew EpdEventArgs(EpdID, EPDIssued, isBG, isMK3));
}
else if (rv == 2 && _EpdTO != nullptr) {
_EpdTO(this, gcnew EpdTOEventArgs(epd3->ConnectTries, epd3->ConnectTimerFired));
_EpdTO(this, gcnew EpdTOEventArgs(0, 0)); // epd3->ConnectTries, epd3->ConnectTimerFired));
}
else if (rv > 0 && _EpdError != nullptr) {
_EpdError(this, gcnew EpdErrorEventArgs(rv));
@ -892,16 +892,21 @@ void EpdBaseClr::Epd2::WaitEnd()
{
if (waitTask != nullptr)
{
//if (epd3->hWaitTimer!= nullptr)
// SetEvent(epd3->hWaitTimer);
waitTask->Wait(750);
if (waitTask->Status == System::Threading::Tasks::TaskStatus::Running) {
waitTask->Wait(1000);
int tries = 5;
while (tries-->0 && waitTask->Status == System::Threading::Tasks::TaskStatus::Running) {
tokenSource->Cancel();
waitTask->Wait(1000);
}
delete waitTask;
waitTask = nullptr;
delete tokenSource;
if (
waitTask->Status == System::Threading::Tasks::TaskStatus::RanToCompletion
|| waitTask->Status == System::Threading::Tasks::TaskStatus::Canceled
|| waitTask->Status == System::Threading::Tasks::TaskStatus::Faulted
) {
delete waitTask;
waitTask = nullptr;
}
delete tokenSource;
tokenSource = nullptr;
Close();
}

View file

@ -296,7 +296,7 @@
<StackPanel Grid.Row="0" Name="panelWait" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Vertical" >
<StackPanel Orientation="Horizontal">
<Image Source="/Images/Mannetjet.png" Width="87" HorizontalAlignment="Left"/>
<TextBlock Text="Waiting for EPD" Margin="10,100,10,100" FontWeight="Bold" >
<TextBlock Name="tWaitFor" Text="Waiting for EPD" Margin="10,100,10,100" FontWeight="Bold" >
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource sckcP}"/>
</TextBlock.Foreground>

View file

@ -13,6 +13,7 @@ namespace eDosStation
/// </summary>
public partial class EntryBadge : Window
{
bool taskLoading = false;
const int PageTimeout = 10000;
bool initialising = true;
@ -29,6 +30,8 @@ namespace eDosStation
eDosStation.DataSet1 dataSet1;
private DateTime ResultTime;
private bool EpdReading=false;
enum eCOE { quiz = 1 };
#if SimulateEPD
public SimulateData simulData = new SimulateData();
@ -40,15 +43,18 @@ namespace eDosStation
thisStation = curStation;
_User = null;
taskLoading = false;
EpdReading = false;
}
private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdTOEventArgs e)
{
System.Diagnostics.Debug.WriteLine("TIME OUT");
Dispatcher.InvokeAsync(() => {
endPage();
});
}
private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e)
{
Dispatcher.InvokeAsync(() => {
MessageBox.Show($"EPD Error {e.returnValue}");
endPage();
@ -56,6 +62,7 @@ namespace eDosStation
}
private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e)
{
EpdReading = false;
Dispatcher.InvokeAsync(() => GetEPD());
}
private bool LoadDoses()
@ -233,18 +240,18 @@ namespace eDosStation
simulData.WearerName = ep.WearerName;
#endif
ep.Hp07RateOn = CurTaskRow.HP07RateON;
ep.Hp07RateOff = CurTaskRow.HP07RateOFF;
ep.Hp07RateOn = CurTaskRow.HP07RateON;
ep.Hp07RateOff = CurTaskRow.HP07RateOFF;
ep.Hp10Rate1On = CurTaskRow.HP10Rate1ON;
ep.Hp10Rate1Off = CurTaskRow.HP10Rate1OFF;
ep.Hp10Rate1On = CurTaskRow.HP10Rate1ON;
ep.Hp10Rate1Off = CurTaskRow.HP10Rate1OFF;
ep.Hp10Rate2On = CurTaskRow.HP10Rate2ON;
ep.Hp10Rate2Off = CurTaskRow.HP10Rate2OFF;
ep.Hp10Rate2On = CurTaskRow.HP10Rate2ON;
ep.Hp10Rate2Off = CurTaskRow.HP10Rate2OFF;
ep.Hp10THDose1 = CurTaskRow.Hp10Dose1;
ep.Hp10THDose2 = CurTaskRow.Hp10Dose2;
ep.Hp07THDose = CurTaskRow.Hp07Dose;
ep.Hp10THDose1 = CurTaskRow.Hp10Dose1;
ep.Hp10THDose2 = CurTaskRow.Hp10Dose2;
ep.Hp07THDose = CurTaskRow.Hp07Dose;
////voor Neutron K3, K4
//int? kx = null;
@ -281,9 +288,9 @@ namespace eDosStation
ep.WriteCalibration();
#endif
float gain = 100.0F;
if (!CurTaskRow.IsFNGain_ANGainValueNull()) gain= (int)CurTaskRow.FNGain_ANGainValue;
float gain = 100.0F;
if (!CurTaskRow.IsFNGain_ANGainValueNull()) gain = (int)CurTaskRow.FNGain_ANGainValue;
int rv = ep.IssueAndCheck(gain);
if (rv != 0)
{
@ -296,6 +303,8 @@ namespace eDosStation
panelWait.Visibility = Visibility.Collapsed;
}
}
else
System.Diagnostics.Debug.WriteLine("Not loaded");
}
private void GetEPD()
{
@ -304,6 +313,9 @@ namespace eDosStation
statusEPD.Text = string.Empty;
DoEPD();
}
else
System.Diagnostics.Debug.WriteLine("Not loaded");
}
private void SetFilter(bool isAlara)
{
@ -491,6 +503,11 @@ namespace eDosStation
}
public void endPage()
{
if (EpdReading)
{
//MessageBox.Show("Fout bij initialiseren EPD! ");
}
EpdReading = false;
dispatcherTimer?.Stop();
dispatcherTimer = null;
this.Close();
@ -545,12 +562,17 @@ namespace eDosStation
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(thisStation.EPDTimeOut / 10);
dispatcherTimer.Tick += CountDown;
ResultTime = DateTime.Now.AddMilliseconds(thisStation.EPDTimeOut);
pWaitEpd.Value = pWaitEpd.Maximum = thisStation.EPDTimeOut / 1000;
dispatcherTimer.Start();
pWaitEpd.Value = pWaitEpd.Maximum = thisStation.EPDTimeOut/1000;
Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, 1); }),DispatcherPriority.Background);
startEPDRead();
}
}
}
private void startEPDRead()
{
EpdReading = true;
Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, thisStation.EPDRetries); }), DispatcherPriority.Background);
}
private void CountDown(object sender, EventArgs e)
{
double v = (ResultTime - DateTime.Now).TotalSeconds;
@ -559,7 +581,11 @@ namespace eDosStation
else
{
dispatcherTimer.Stop();
endPage();
pWaitEpd.Value = 0;
pWaitEpd.Background = System.Windows.Media.Brushes.Red;
statusEPD.Text = "Time out";
tWaitFor.Text = "Lezer niet gevonden !";
bEpdCancel.IsEnabled = false;
}
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@ -709,6 +735,7 @@ namespace eDosStation
private void Window_Loaded(object sender, RoutedEventArgs e)
{
initialising = true;
EpdReading = false;
tbEntry.IsSelected = true;
panelDone.Visibility= Visibility.Collapsed;
panelWait.Visibility = Visibility.Visible;

View file

@ -85,7 +85,6 @@ namespace eDosStation
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string eDosCom = devcon.FindEdosCom();
try
{

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LSWLib.3.0.14\build\LSWLib.props" Condition="Exists('..\packages\LSWLib.3.0.14\build\LSWLib.props')" />
<Import Project="..\packages\LSWLib.3.1.3\build\LSWLib.props" Condition="Exists('..\packages\LSWLib.3.1.3\build\LSWLib.props')" />
<Import Project="..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.props" Condition="Exists('..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@ -336,13 +336,13 @@
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SlowCheetah.4.0.8\build\Microsoft.VisualStudio.SlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SlowCheetah.4.0.8\build\Microsoft.VisualStudio.SlowCheetah.targets'))" />
<Error Condition="!Exists('..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.props'))" />
<Error Condition="!Exists('..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.targets'))" />
<Error Condition="!Exists('..\packages\LSWLib.3.0.14\build\LSWLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWLib.3.0.14\build\LSWLib.props'))" />
<Error Condition="!Exists('..\packages\LSWLib.3.0.14\build\LSWLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWLib.3.0.14\build\LSWLib.targets'))" />
<Error Condition="!Exists('..\packages\LSWLib.3.1.3\build\LSWLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWLib.3.1.3\build\LSWLib.props'))" />
<Error Condition="!Exists('..\packages\LSWLib.3.1.3\build\LSWLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LSWLib.3.1.3\build\LSWLib.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>"C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe" sign /sha1 857150b64ef7d3e679c8cbde425d2a0b5e58ffaa /fd sha256 /d "Integrity &amp; Authenticity" /tr "http://timestamp.digicert.com" $(TargetPath)</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Microsoft.VisualStudio.SlowCheetah.4.0.8\build\Microsoft.VisualStudio.SlowCheetah.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.SlowCheetah.4.0.8\build\Microsoft.VisualStudio.SlowCheetah.targets')" />
<Import Project="..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.targets" Condition="Exists('..\packages\LSWDesfirePublic.1.3.9\build\LSWDesfirePublic.targets')" />
<Import Project="..\packages\LSWLib.3.0.14\build\LSWLib.targets" Condition="Exists('..\packages\LSWLib.3.0.14\build\LSWLib.targets')" />
<Import Project="..\packages\LSWLib.3.1.3\build\LSWLib.targets" Condition="Exists('..\packages\LSWLib.3.1.3\build\LSWLib.targets')" />
</Project>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LSWDesfirePublic" version="1.3.9" targetFramework="net48" />
<package id="LSWLib" version="3.0.14" targetFramework="net48" />
<package id="LSWLib" version="3.1.3" targetFramework="net48" />
<package id="Microsoft.VisualStudio.SlowCheetah" version="4.0.8" targetFramework="net48" developmentDependency="true" />
<package id="SharpDX" version="4.2.0" targetFramework="net48" />
<package id="SharpDX.D3DCompiler" version="4.2.0" targetFramework="net48" />