Ejemplo n.º 1
0
 // received when something is wrong with Socket Mobile Companion
 // or when aborting Capture Helper (result is no error in that case)
 private void mCapture_Terminate(object sender, CaptureHelper.TerminateArgs e)
 {
     // if there is an error then Socket Mobile Companion
     // is not responding anymore
     if (!SktErrors.SKTSUCCESS(e.Result))
     {
         timerOpenCapture.Start();
     }
 }
Ejemplo n.º 2
0
        // Report Capture SDK errors on the console

        void OnError(object sender, CaptureHelper.ErrorEventArgs e)
        {
            Console.WriteLine(String.Format("OnError(): {0}", e.Message));
            if (SktErrors.SKTSUCCESS(e.Result))
            {
                Console.WriteLine("Result is SUCCESSFUL");
            }
            else
            {
                Console.WriteLine("Result is FAILURE");
            }
        }
Ejemplo n.º 3
0
        // Initialize the CaptureHelper object here

        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // Assign event handlers for the Capture events we're interested in

            Console.WriteLine("ViewDidAppear: Assigning handlers");
            capture.DeviceArrival += OnDeviceArrival;
            capture.DeviceRemoval += OnDeviceRemoval;
            capture.DecodedData   += OnDecodedData;
            capture.Errors        += OnError;

            long result = await OpenCaptureClient(capture);

            if (!SktErrors.SKTSUCCESS(result))
            {
                Console.WriteLine("OpenCaptureClient failed!");
            }
        }
Ejemplo n.º 4
0
        private async void timerOpenCapture_Tick(object sender, EventArgs e)
        {
            timerOpenCapture.Stop();

            long Result = await mCapture.OpenAsync("windows:com.socketmobile.singleentry",
                                                   "08de99c4-5baa-481f-8547-8d0ef9724630",
                                                   "i6tgDN2aO14WuVHMaCrq3VR4nEz+zL5dfePpNvmGeN2kZeLIWmfKmw==");

            if (SktErrors.SKTSUCCESS(Result))
            {
                // ask for the version
                CaptureHelper.VersionResult version = await mCapture.GetCaptureVersionAsync();

                if (version.IsSuccessful())
                {
                    labelVersion.Text = "Capture version: " + version.ToStringVersion();
                }
            }
            else
            {
                labelVersion.Text = "Unable to connect to Socket Mobile Companion";
                DialogResult dialogResult = MessageBox.Show(
                    "Unable to open Capture, is Socket Mobile Companion Service running?",
                    "Error",
                    MessageBoxButtons.RetryCancel,
                    MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Retry)
                {
                    timerOpenCapture.Start();
                }
                else
                {
                    Close();
                }
            }
        }
Ejemplo n.º 5
0
        // Callback for Capture, when a scanner connects

        async void OnDeviceArrival(object sender, CaptureHelper.DeviceArgs arrivedDevice)
        {
            Console.WriteLine("Start ScannerConnect()");
            if (CurrentDevice == null)
            {
                CurrentDevice = arrivedDevice.CaptureDevice;

                // Friendly name is available immediately
                InvokeOnMainThread(() =>
                {
                    scannerLabel.Text = CurrentDevice.GetDeviceInfo().Name;
                    Console.WriteLine("Device friendly name is: " + CurrentDevice.GetDeviceInfo().Name);
                });

                // Get the Bluetooth address of the connected device
                Console.WriteLine("Requesting the Bluetooth address.");
                CaptureHelperDevice.BluetoothAddressResult resultBdAddr = await CurrentDevice.GetBluetoothAddressAsync(".");

                // Put the BdAddr out there
                if (SktErrors.SKTSUCCESS(resultBdAddr.Result))
                {
                    Console.WriteLine("Got the Bluetooth address.");
                    InvokeOnMainThread(() =>
                    {
                        Console.WriteLine("BdAddr is: " + resultBdAddr.BluetoothAddress);
                        bdaddrLabel.Text = resultBdAddr.BluetoothAddress;
                    });
                }
                else
                {
                    Console.WriteLine("Error retrieving the Bluetooth address!");
                }

                // Get the current battery level
                Console.WriteLine("Requesting the battery level.");
                CaptureHelperDevice.BatteryLevelResult resultBattery = await CurrentDevice.GetBatteryLevelAsync();

                // Put the Battery Level out there
                if (SktErrors.SKTSUCCESS(resultBattery.Result))
                {
                    Console.WriteLine("Got the battery level.");
                    InvokeOnMainThread(() =>
                    {
                        battLevelLabel.Text = resultBattery.Percentage;
                    });
                }
                else
                {
                    Console.WriteLine("Error retrieving the battery level!");
                }

                var result = await CurrentDevice.SetDecodeActionAsync(false, false, false);

                if (!result.IsSuccessful())
                {
                    Console.WriteLine("SetDecodeAction() failed with " + result.Result + "!");
                }

                result = await capture.SetDataConfirmationModeAsync(ConfirmationMode.kApp);

                if (!result.IsSuccessful())
                {
                    Console.WriteLine("SetDataConfigurationMode() failed with " + result.Result + "!");
                }

                Connected = true;

                while (Connected)
                {
                    resultBattery = await CurrentDevice?.GetBatteryLevelAsync();

                    if (!SktErrors.SKTSUCCESS(resultBattery?.Result ?? -1))
                    {
                        Console.WriteLine("GetBatteryLevel() failed with " + resultBattery.Result + "!");
                    }
                    InvokeOnMainThread(() => battLevelLabel.Text = resultBattery.Percentage);
                    await Task.Delay(TimeSpan.FromSeconds(1));
                }

                // This section causing problems on some scanners

#if false
                CaptureHelperDevice.PowerStateResult powerState = await CurrentDevice.GetPowerStateAsync();

                if (SktErrors.SKTSUCCESS(powerState.Result))
                {
                    string strPowerState;

                    switch (powerState.State)
                    {
                    case CaptureHelper.PowerState.AC:
                        strPowerState = "On AC";
                        break;

                    case CaptureHelper.PowerState.Battery:
                        strPowerState = "On Battery";
                        break;

                    case CaptureHelper.PowerState.Cradle:
                        strPowerState = "In Cradle";
                        break;

                    default:
                        strPowerState = "Unknown";
                        break;
                    }
                    InvokeOnMainThread(() =>
                    {
                        powerStatusLabel.Text = strPowerState;
                    });
                }
                else
                {
                    Console.WriteLine("Error retrieving the power state!");
                }

                //See if we can register for live battery status updates

                //Should assign a handler for battery status changes up where
                //the capture openAsyc() happens.

                Console.WriteLine("Requesting notifications.");

                CaptureHelperDevice.NotificationsResult resultNotifications = await CurrentDevice.GetNotificationsAsync();

                Console.WriteLine("Got the notifications.");
                if (resultNotifications.IsSuccessful())
                {
                    if ((!resultNotifications.Notifications.BatteryLevel) || (!resultNotifications.Notifications.PowerState))
                    {
                        resultNotifications.Notifications.BatteryLevel = true;
                        resultNotifications.Notifications.PowerState   = true;
                        CaptureHelper.AsyncResult result = await CurrentDevice.SetNotificationsAsync(resultNotifications.Notifications);

                        if (!result.IsSuccessful())
                        {
                            Console.WriteLine("Unable to set the power notifications.");
                        }
                        else
                        {
                            CurrentDevice.DeviceBatteryLevel += OnDeviceBatteryLevel;
                            CurrentDevice.DevicePowerState   += OnDevicePowerState;
                        }
                    }
                    else
                    {
                        CurrentDevice.DeviceBatteryLevel += OnDeviceBatteryLevel;
                        CurrentDevice.DevicePowerState   += OnDevicePowerState;
                    }
                }
                else
                {
                    // display an error message...
                    Console.WriteLine("Device.GetNotificationsAsync did not work.");
                }
                //DoScannerConnect();
#endif
            }
            else
            {
                // Maybe a new scanner has arrived, but the simple act of
                // assigning the DeviceArrival handler will cause Capture
                // to notify us if a scanner is connected.

                Console.WriteLine("We already have a scanner connected!! Closing...");
                await arrivedDevice.CaptureDevice.CloseAsync();
            }

            Console.WriteLine("End ScannerConnect()");
        }