Example #1
0
        /// <summary>
        /// Load the device.
        /// </summary>
        /// <exception cref="IOException"></exception>
        public void Load()
        {
            if (this.deviceType != DeviceTypes.OPOS)
            {
                return;
            }

            NetTracer.Information("Peripheral [Scanner] - OPOS device loading: {0}", this.DeviceName ?? "<Undefined>");

            oposScanner = new OPOSScannerClass();

            // Open
            oposScanner.Open(this.DeviceName);
            Peripherals.CheckResultCode(this, oposScanner.ResultCode);

            // Claim
            oposScanner.ClaimDevice(Peripherals.ClaimTimeOut);
            Peripherals.CheckResultCode(this, oposScanner.ResultCode);

            // Enable/Configure
            oposScanner.DataEvent       += new _IOPOSScannerEvents_DataEventEventHandler(posScanner_DataEvent);
            oposScanner.DeviceEnabled    = true;
            oposScanner.AutoDisable      = true;
            oposScanner.DecodeData       = true;
            oposScanner.DataEventEnabled = true;

            IsActive = true;
        }
Example #2
0
        static void Main(string[] args)
        {
            // setup the console program to exit gracefully
            var exitEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                exitEvent.Set();
            };

            // create a scanner object
            scanner = new OPOSScannerClass();

            // subscribe to the delegate
            scanner.DataEvent += DataEvent;

            // attempt to open, claim, and enable a scanner
            // these functions are defined by OPOS
            scanner.Open(name);
            scanner.ClaimDevice(1000);
            if (scanner.Claimed)
            {
                Console.WriteLine("Connected to: " + name + " in C#");
                scanner.DeviceEnabled    = true;
                scanner.DataEventEnabled = true;
                scanner.DecodeData       = true;
            }
            else
            {
                scanner.Close();
                scanner.DataEvent -= DataEvent;
                return;
            }

            // wait for exit event
            Console.WriteLine("Press \'Ctrl + C\' to quit.");
            exitEvent.WaitOne();

            // unsubscribe to the delegate
            scanner.DataEvent -= DataEvent;

            // disable operation, release control, and close the scanner
            scanner.DataEventEnabled = false;
            scanner.ReleaseDevice();
            scanner.Close();
        }