Exemple #1
0
        private static void Instance_DataReceived(object sender, BarcodeScanEventArgs e)
        {
            _lastScanned = e.Data;
            var raw = Encoding.Default.GetString(e.RawData);

            Console.WriteLine("Barcode type: " + e.BarcodeType.GetDescription());
            Console.WriteLine("Data: " + e.Data);
        }
Exemple #2
0
 private static void OnDataReceived(object sender, BarcodeScanEventArgs e)
 {
     Console.WriteLine("Scan Successful - Data: " + e.Data);
     using (TextWriter textWriter = File.CreateText(e.Data.Replace(" ", "_")))
     {
         textWriter.WriteLine(e.Data);
     }
 }
Exemple #3
0
        private static void OnDataReceived(object sender, BarcodeScanEventArgs e)
        {               // Modify logging depending on if in multipoint mode - can get better info from prefix
            Console.WriteLine("Barcode scan detected from scanner id=" + e.ScannerId + ": " + e.Data);
            _log.Debug("Barcode scan detected from scanner id=" + e.ScannerId + ": " + e.Data);

            // get prefix identifier and convert from char to int
            int prefix = Convert.ToInt32(e.Data[0]);

            Console.WriteLine("PREFIX:" + prefix);
            int scannerId = prefixes[prefix];

            // chop prefix off barcode, and convert to uppercase and strip any whitespace
            string      barcode     = e.Data.Substring(1).ToUpper().Trim();
            BarcodeType barcodeType = CheckBarcode(barcode);

            if (barcodeType == BarcodeType.None)
            {
                _log.Error("Barcode " + e.Data + " not recognized as location or NID");
                // **** FIX *****
                SendNotification(scannerId, notifications["barcodeFailure"]);
            }
            else
            {
                // if successful scan, then either stop timer or restart start it, so stop here.
                // stopping timer avoids potential race condition
                //if (_scanTimer != null)
                //{
                //	_scanTimer.Stop();
                //}
                //if (timers[scannerId] != null)
                //{
                //	timers[scannerId].Stop();
                //}
                if (scanners[scannerId].timer != null)
                {
                    scanners[scannerId].timer.Stop();
                }
                scanners[scannerId].timer = new ScannerTimer
                {
                    Interval  = 5000,
                    AutoReset = false,
                    scannerId = scannerId,
                    ledOff    = null
                };
                scanners[scannerId].timer.Elapsed += OnScanTimerElapsed;
                //_scanTimer.Elapsed += OnScanTimerElapsed;
                //_scanTimer = new ScannerTimer
                //{
                //	Interval = 5000,
                //	AutoReset = false,
                //	scannerId = e.ScannerId,
                //	ledOff = null
                //};
                //_scanTimer.Elapsed += OnScanTimerElapsed;

                //timers[scannerId] = new ScannerTimer
                //{
                //	Interval = 5000,
                //	AutoReset = false,
                //	scannerId = scannerId,
                //	ledOff = null
                //};
                //timers[scannerId].Elapsed += OnScanTimerElapsed;

                _log.Debug("Barcode " + barcode + " recognized as type " + barcodeType);
                Console.WriteLine("Barcode " + barcode + " recognized as type " + barcodeType);

                // case 1: prevScan: null		current: nid1       -> prevScan: nid1		timer: start	()
                // case 2: prevScan: null		current: location1	-> prevScan: location1	timer: start	()
                // case 3: prevScan: nid1		current: nid1		-> prevScan: null		timer: stop		(remove nid's location from database)
                // case 4: prevScan: nid1		current: nid2		-> prevScan: nid2		timer: start	(overwrite previous nid with new prevScan nid)
                // case 5: prevScan: nid1		current: location1	-> prevScan: location1	timer: start	(nid scanned first - overwrite with location)
                // case 6: prevScan: location1	current: location1	-> prevScan: location1	timer: start	(overwrite same location)
                // case 7: prevScan: location1	current: location2  -> prevScan: location2	timer: start	(overwrite new location)
                // case 8: prevScan: location1	current: nid1       -> prevScan: null		timer: stop		(update nid's location in database)

                // cases 1 and 2
                if (scanners[scannerId].prevScan == null)
                {
                    //_scanTimer.Start();
                    //timers[scannerId].Start();
                    scanners[scannerId].timer.Start();
                    scanners[scannerId].prevScan = Tuple.Create(barcode, barcodeType);
                    //prevScan = Tuple.Create(barcode, barcodeType);
                }
                // cases 5,6,7
                else if (barcodeType == BarcodeType.location)
                {
                    //_scanTimer.Start();
                    //timers[scannerId].Start();
                    scanners[scannerId].timer.Start();
                    //prevScan = Tuple.Create(barcode, barcodeType);
                    scanners[scannerId].prevScan = Tuple.Create(barcode, barcodeType);
                }
                else
                {
                    if (scanners[scannerId].prevScan.Item2 == BarcodeType.nid)
                    {
                        // case 3
                        if (barcode.Equals(scanners[scannerId].prevScan.Item1))
                        {
                            SendNotification(scannerId, notifications["tryDatabase"]);
                            //UpdateDatabase(e.ScannerId, barcode);
                            //prevScan = null;
                            scanners[scannerId].prevScan = null;
                        }
                        // case 4
                        else
                        {
                            //_scanTimer.Start();
                            //timers[scannerId].Start();
                            scanners[scannerId].timer.Start();

                            //prevScan = Tuple.Create(barcode, barcodeType);
                            scanners[scannerId].prevScan = Tuple.Create(barcode, barcodeType);
                        }
                    }
                    // case 8
                    else
                    {
                        SendNotification(scannerId, notifications["tryDatabase"]);
                        //string location = prevScan.Item1;
                        //UpdateDatabase(e.ScannerId, barcode, location);
                        scanners[scannerId].prevScan = null;
                    }
                }
            }
        }
Exemple #4
0
        private static void OnDataReceived(object sender, BarcodeScanEventArgs e)
        {
            Console.WriteLine("Barcode scan detected from scanner id=" + e.ScannerId + ": " + e.Data);
            log.Debug("Barcode scan detected from scanner id=" + e.ScannerId + ": " + e.Data);

            // get prefix identifier and convert from char to int
            //int prefix = Convert.ToInt32(e.Data[0]);
            int scannerId = scannerInfo.scanner.Info.ScannerId;

            // convert to uppercase and strip any whitespace
            string      barcode     = e.Data.ToUpper().Trim();
            BarcodeType barcodeType = CheckBarcode(barcode);

            if (barcodeType == BarcodeType.None)
            {
                log.Error("Barcode " + e.Data + " not recognized as location or NID");
                Console.WriteLine("Barcode " + e.Data + " not recognized as location or NID");
                SendNotification(scannerId, notifications["barcodeFailure"]);
            }
            else
            {
                // if successful scan, then either stop timer or restart start it, so stop here.
                if (scannerInfo.timer != null)
                {
                    scannerInfo.timer.Stop();
                }
                scannerInfo.timer = new ScannerTimer
                {
                    Interval  = timerInterval,
                    AutoReset = false,
                    scannerId = scannerId,
                    ledOff    = null
                };
                scannerInfo.timer.Elapsed += OnScanTimerElapsed;

                log.Debug("Barcode " + barcode + " recognized as type " + barcodeType);
                Console.WriteLine("Barcode " + barcode + " recognized as type " + barcodeType);

                // case 1: prevScan: null		current: nid1       -> prevScan: nid1		timer: start	()
                // case 2: prevScan: null		current: location1	-> prevScan: location1	timer: start	()
                // case 3: prevScan: nid1		current: nid1		-> prevScan: null		timer: stop		(remove nid's location from database)
                // case 4: prevScan: nid1		current: nid2		-> prevScan: nid2		timer: start	(overwrite previous nid with new prevScan nid)
                // case 5: prevScan: nid1		current: location1	-> prevScan: location1	timer: start	(nid scanned first - overwrite with location)
                // case 6: prevScan: location1	current: location1	-> prevScan: location1	timer: start	(overwrite same location)
                // case 7: prevScan: location1	current: location2  -> prevScan: location2	timer: start	(overwrite new location)
                // case 8: prevScan: location1	current: nid1       -> prevScan: null		timer: stop		(update nid's location in database)

                // NOTE: BarcodeType.multiLocation added. Behaves same as location except do not delete prevScan in case 8.

                // cases 1 and 2
                if (scannerInfo.prevScan == null)
                {
                    scannerInfo.timer.Start();
                    scannerInfo.prevScan = Tuple.Create(barcode, barcodeType);
                }
                // cases 5,6,7
                else if (barcodeType == BarcodeType.location || barcodeType == BarcodeType.multiLocation)
                {
                    scannerInfo.timer.Start();
                    scannerInfo.prevScan = Tuple.Create(barcode, barcodeType);
                }
                else
                {
                    if (scannerInfo.prevScan.Item2 == BarcodeType.nid)
                    {
                        // case 3
                        if (barcode.Equals(scannerInfo.prevScan.Item1))
                        {
                            SendNotification(scannerId, notifications["tryDatabase"]);
                            UpdateDatabase(scannerId, barcode);
                            scannerInfo.prevScan = null;
                        }
                        // case 4
                        else
                        {
                            scannerInfo.timer.Start();
                            scannerInfo.prevScan = Tuple.Create(barcode, barcodeType);
                        }
                    }
                    // case 8 (prevScan is location or multiLocation)
                    else
                    {
                        SendNotification(scannerId, notifications["tryDatabase"]);
                        string location = scannerInfo.prevScan.Item1;
                        UpdateDatabase(scannerId, barcode, location);
                        // if multiple items are allowed, then do not wipe location
                        if (scannerInfo.prevScan.Item2 == BarcodeType.location)
                        {
                            scannerInfo.prevScan = null;
                        }
                        // if at portapillars, location only gets wiped when scanner times out. Each NID scanned restarts timer.
                        else
                        {
                            scannerInfo.timer.Start();
                        }
                    }
                }
            }
        }