Skip to content

Commit

Permalink
Добавил событие ошибок(разрыв соединения с купюроприемником)
Browse files Browse the repository at this point in the history
  • Loading branch information
Кирилл committed Apr 1, 2019
1 parent accc6bb commit b7e31c8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 26 additions & 1 deletion CashCode.Net/CashCode.Net/CashCodeBillValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public enum BillCassetteStatus { Inplace, Removed };
// Делегат события в процессе отправки купюры в стек (Здесь можно делать возврат)
public delegate void BillStackingHandler(object Sender, BillStackedEventArgs e);

// Делегат события ошибок
public delegate void BillExceptionHandler(object Sender, BillExceptionEventArgs e);

public sealed class CashCodeBillValidator : IDisposable
{
#region Закрытые члены
Expand Down Expand Up @@ -563,6 +566,16 @@ private void OnBillStacking(BillStackedEventArgs e)
}
}

public event BillExceptionHandler BillException;

private void OnBillException(BillExceptionEventArgs e)
{
if (BillException != null)
{
BillException(this, new BillExceptionEventArgs(e.Message));
}
}

#endregion

#region Обработчики событий
Expand Down Expand Up @@ -711,7 +724,9 @@ private void _Listener_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
}
}
catch
{}
{
OnBillException(new BillExceptionEventArgs("Связь с купюроприемником потеряна"));
}
finally
{
// Если таймер выключен, то запускаем
Expand Down Expand Up @@ -763,5 +778,15 @@ public BillStackedEventArgs(int value)
this.Cancel = false;
}
}

public class BillExceptionEventArgs : EventArgs
{
public string Message { get; set; }

public BillExceptionEventArgs(string message)
{
Message = message;
}
}
}

6 changes: 6 additions & 0 deletions CashCode.Net/CashCode.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static void Main(string[] args)
c.BillReceived += new BillReceivedHandler(c_BillReceived);
c.BillStacking += new BillStackingHandler(c_BillStacking);
c.BillCassetteStatusEvent += new BillCassetteHandler(c_BillCassetteStatusEvent);
c.BillException += new BillExceptionHandler(c_BillException);
c.ConnectBillValidator();

if (c.IsConnected)
Expand Down Expand Up @@ -73,6 +74,11 @@ static void c_BillReceived(object Sender, BillReceivedEventArgs e)
}
}

static void c_BillException(object Sender, BillExceptionEventArgs e)
{
Console.WriteLine(e.Message);
}


}
}

0 comments on commit b7e31c8

Please sign in to comment.