How to Suppress Duplicate Barcodes or RFID Tags with the Software Wedge?
The Problem:
Maybe you are familiar with this scenario: You are connecting a barcode scanner, an electronic scale or an RFID reader to your computer. When capturing data it turns out that the device is sending identical values multiple times. This happens if the user scans a barcode repeatedly, a scale sends the weight of the item periodically or if a RFID reader reports the value of a RFID tag at regular intervals.The Solution:
TWedge provides a very flexible and elegant solution to this problem. The software wedge can be customized to suppress multiple, identical values easily: Just save the last data value received from the device and compare it with the current one. Forward the device data to target application only if these values are not identical. Here is the script:The Software Wedge Script:
OnStart() is the perfect place to initialize the last received data value (sLastData) with a null value. OnStart is executed when device communication is initialized (e.g. the serial port was opened):// This script is executed whenever communication is started.
// Use it to perform one-time initializations like opening a file or a database connection.
// message informing the user what this sample is good for
MessageBox("This script demonstrates how to suppress duplicate data packets from a device.\n\nSometimes devices like barcode scanners or RFID controllers are sending the same data packet multiple times. This very useful feature just forwards unique values to the target application.");
sLastData = null; // initialize with a value which is never received from a device
nDuplicates = 0; // set the number of duplicates to 0
OnData() is executed whenever device data is received. Compare the current data value (stored in DATA) with the last one (sLastData). In this example keystrokes are only simulated if these two values are not identical:
// Check if the current device data is identical to the last one
if (DATA != sLastData)
{
SendKeyStrokes(DATA); // not identical: simulate keystrokes
sLastData = DATA; // set the last value to the current one
nDuplicates = 0; // increment the duplicate counter (for info only)
}
else
{
nDuplicates++; // duplicate received, just display an info-message
NotifyInfo ("Duplicate data received. The value " + DATA + " was suppressed " + nDuplicates + " times");
}
More information as well as the script explained in this post will be available soon on www.tec-it.com.
Comments
Post a Comment
No spam please, comments are moderated.
Thanks, TEC-IT