How to properly use Ranger Shutdown()

How to properly use Ranger Shutdown()

Why can't we call Shutdown() in every Ranger state?

Many low-level scanner drivers require that they be shutdown in a specific orderly sequence. If they are abruptly disconnected, it can leave the scanner and/or device driver in an unexpected, and often hung state.

As far as programming documentation goes, the description of a Ranger call in the programming guide mentions the Ranger states that a particular call can be made in.  The state diagram in the manual also graphically describes this.

In the case of Shutdown(), it can be called when Ranger is in the ChangeOptions and ReadyToFeed states.  So the application is responsible for putting Ranger into one of these states before calling Shutdown(). 

When I write applications, I handle it this way:
  1. When the application decides it will call Shutdown(), it checks the current Ranger state.
  2. If Ranger is in a state where Shutdown() is allowed, the application calls Shutdown().

When Ranger is in a state where Shutdown() cannot be called yet, then the application will:
  1. Set a variable to tell itself that it is preparing to shutdown (ex: PreparingToShutdown = true)
  2. Then the application will call the Ranger function(s) required to bring Ranger into the target state, then let Ranger run unimpeded until the target state is reached. 
  3. The application code that handles the Ranger state changing events tests the value of PreparingToShutdown to determine if it is trying to shutdown.
  4. Shutdown() can then be called once Ranger reaches the target state.
Never use a loop that checks the Ranger state.  The OS message pump needs to run normally for the Ranger state transitions to complete properly.

There are a few scenarios which may require a couple of state transitions to end up in a state where Shutdown() is allowed.
For example, if Ranger is handling an exception.
So more than one state changing functions, may be required to bring Ranger into the target state.

One of the easiest ways to avoid problems is to disable the ability for the user to exit the application when Ranger is in a state where Shutdown() cannot be called.  So if items are feeding for example, they user would not be given the ability to exit (by as disabling the "exit" button).  However, once feeding has stopped, and Ranger is in the ReadyToFeed state, then the option to exit the application can be enabled.


Ranger® - The universal check scanner interface
Copyright © 2023 Silver Bullet Technology
www.sbullet.com
    • Related Articles

    • How do I use Ranger with Java?

      Using Ranger with Java (not Javascript) There is a Java interface, JNI, for Ranger called JRanger. It can be found on our website after logging in and selecting the "Ranger SDK" link. Because Ranger and the drivers that Ranger uses are 32 bit you ...
    • Can I use Ranger in my web-based application?

      Yes. Many Ranger users have web-based applications. Some application developers use our JavaScript library. Others use a Ranger browser plug-in, DLL or ActiveX control. Ranger® - The universal check scanner interface Copyright © 2023 Silver Bullet ...
    • How do I properly unlock Ranger when using Ranger Remote?

      In most cases, Ranger should be unlocked before installation of Ranger Remote: Install Ranger by running the Ranger installer Unlock Ranger using RangerFlex. Reference the following link for unlocking Ranger: How do I unlock my Ranger software? ...
    • Must I use Image File Sets to store images captured using Ranger?

      You do not need to save images into Image File Sets unless you need Ranger compatibility with large Unisys check scanner/sorters. You can access the images in the Ranger "InPocket" event via the GetImageAddress() and GetImageByteCount() functions. If ...
    • How do I use Ranger in a C# or VB.NET web application?

      How do I use Ranger in a C# or VB.NET web application? Ranger cannot be added to a .NET web application in the same way as the sample apps. This is because the C# or VB.NET code is run on the server, and the Ranger ActiveX control must be run ...