Skip to content

Commit

Permalink
Move remaining state variable from config into the validator class
Browse files Browse the repository at this point in the history
update test app to use latest event names
  • Loading branch information
Cory Todd committed Sep 8, 2015
1 parent f639b63 commit 49f75b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
32 changes: 23 additions & 9 deletions Apex7000_BillValidator/ApexValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public partial class ApexValidator : IDisposable
// Time at which escrow starts
private DateTime escrowStart = DateTime.MinValue;

/// <summary>
/// Slave's last state
/// </summary>
public States PreviousState { get; private set; }

/// <summary>
/// Slave's last events
/// </summary>
public Events PreviousEvents { get; private set; }

/// <summary>
/// Returns true if the communication thread is running normally
/// </summary>
public bool IsRunning { get; private set; }
#endregion

/// <summary>
Expand Down Expand Up @@ -77,7 +91,7 @@ public static List<string> GetAvailablePorts()
public void Close()
{
// This will kill the comms loop
config.IsRunning = false;
IsRunning = false;

if(port != null)
port.Disconnect();
Expand Down Expand Up @@ -173,7 +187,7 @@ private void Reconnect()
private void startRS232Loop()
{

if (config.IsRunning)
if (IsRunning)
{
log.Error("Already running RS-232 Comm loop... Exiting now...");
return;
Expand All @@ -184,10 +198,10 @@ private void startRS232Loop()
Thread speakThread = new Thread((fn) =>
{

config.IsRunning = true;
IsRunning = true;

// Set toggle flag so we can kill this loop
while (config.IsRunning)
while (IsRunning)
{

if (resetRequested)
Expand Down Expand Up @@ -265,7 +279,7 @@ private void speakToSlave()

// Translate raw bytes into friendly enums
var slaveMessage = SlaveCodex.ToSlaveMessage(resp);
config.PreviousState = SlaveCodex.GetState(slaveMessage);
PreviousState = SlaveCodex.GetState(slaveMessage);


// Raise a state changed notice for clients
Expand Down Expand Up @@ -303,11 +317,11 @@ private void speakToSlave()

// Mask away rest of message to see if a note is in escrow. If this is the first
// escrow message, start the escrow timeout clock
if(!NoteIsEscrowed && config.PreviousState == States.Escrowed)
if(!NoteIsEscrowed && PreviousState == States.Escrowed)
{
escrowStart = DateTime.MinValue;
}
NoteIsEscrowed = (config.PreviousState == States.Escrowed);
NoteIsEscrowed = (PreviousState == States.Escrowed);

// Credit bits are 3-5 of data byte 3
var value = SlaveCodex.GetCredit(slaveMessage);
Expand All @@ -321,7 +335,7 @@ private void speakToSlave()
// sent by the slave. If the previous event was stacked or returned, we
// must clear the escrow command to completely release the note from
// escrow state.
switch(config.PreviousEvents)
switch(PreviousEvents)
{
case Events.Stacked:
NotifyCredit(Credit);
Expand All @@ -337,7 +351,7 @@ private void speakToSlave()
}

// Update the events aster the check for check so as to not lose a credit message
config.PreviousEvents = currentEvents;
PreviousEvents = currentEvents;

}

Expand Down
15 changes: 0 additions & 15 deletions Apex7000_BillValidator/RS232Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ public int PollRate
/// <remarks>Default value is false</remarks>
public bool IsEscrowMode { get; set; }

/// <summary>
/// Slave's last state
/// </summary>
public States PreviousState { get; internal set; }

/// <summary>
/// Slave's last events
/// </summary>
public Events PreviousEvents { get; internal set; }

/// <summary>
/// Returns true if the communication thread is running normally
/// </summary>
public bool IsRunning { get; internal set; }

/// <summary>
/// Gets or sets the timeout for escrow mode. By default, we wait indefinately but
/// you may configure this to a non-zero value to enable escrow timeouts. This has the effect
Expand Down
2 changes: 1 addition & 1 deletion Apex7000_BillValidator_Test/UsageAndRegistration_Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void btnConnect_Click(object sender, RoutedEventArgs e)
validator.OnCashboxAttached += validator_CashboxAttached;

// Required if you are in escrow mode - see CreditAndEscrow_Sample.cs
validator.OnEscrowed += validator_OnEscrow;
validator.OnEscrow += validator_OnEscrow;

// Technically optional but you probably want this event - see CreditAndEscrow_Sample.cs
validator.OnCredit += validator_OnCredit;
Expand Down

0 comments on commit 49f75b8

Please sign in to comment.