Chapter 6
Reporting KTx Scanner Status
6-8
Suppose that your program crashes, either because of logic errors or because
of operator intervention. Or suppose that through logic errors your program
gets into an infinite loop. In these cases the program is no longer sending
meaningful information to the scanner. Your application can configure the
scanner to detect these situations and to gracefully shut itself down when
this condition is detected. This is done by enabling the scanner watchdog.
When the scanner watchdog is enabled, the host and the scanner must
periodically handshake through the dual port to indicate they are operating
normally. Not only can the scanner detect a ‘dead’ host, the host can detect
a ‘dead’ scanner. The steps for configuring the scanner watchdog are
described below and example code follows.
The host enables and sets the period for the scanner watchdog by writing a
non-zero value in
host_dead_counter
in the dual port. Writing a zero to this
location will disable the watchdog. The period is determined by the value
written to
host_dead_counter
according to the formula:
Watchdog period = 20ms * value in
host_dead_counter
After enabling the scanner watchdog, the host must handshake with the
scanner before the watchdog timer expires. The handshake will cause the
scanner to reset the watchdog timer and begin timing again. The host’s
handshake with the scanner consists of writing 00h in
alive_flag
in the dual
port. The scanner returns the handshake by writing a 02h in
alive_flag
in the
dual port every 20ms. The host can check the contents of
alive_flag
for 02h
before writing to
alive_flag
and verify the scanner changed the value from
00h (the host’s handshake) to 02h (the scanner’s handshake).
show you how to enable the Watchdog and
how to write an interrupt service routine that performs the Watchdog
handshake at regular intervals. The interrupt service routine is activated by
the PC’s clock interrupt.
, the host configures the period of the scanner watchdog to
1000ms by writing 50 into
host_dead_counter
. The host performs a
watchdog handshake with the scanner every 500ms. This wide margin of
error was chosen to illustrate that the programmer must take into
consideration that MS-DOS does not offer reliable real-time response.
The personal computer’s clock interrupt occurs at approximately 50ms
intervals. The scanner’s clock interrupt occurs at approximately 20ms
intervals. Set the
host_dead_counter
value to (wdg_preset * 5).
In
, after 10 PC ticks (~500ms), the PC clears the
alive_flag
.
The scanner tests the
alive_flag
after 50 KTx ticks (1000ms). This margin of
error is intentionally high since PCs are not known to be very accurate
at timing tasks.
Scanner Watchdog