string deviceProtocol = "com.app.myprotocol";          // MRI device-specific protocol

        private bool ConnectToDevice(string accessoryId)
        {
            _streamDelegate = StreamDelegate.SharedController();

            _accessoryList = EAAccessoryManager.SharedAccessoryManager.ConnectedAccessories;

            foreach (EAAccessory accessory in _accessoryList)
            {
                var accId         = accessory.ValueForKey((NSString)"connectionID");
                var accessoryName = accessory.ValueForKey((NSString)"name");
                var accString     = accId.ToString();

                if (DeviceName.Contains(accessoryName.ToString()))
                {
                    _selectedAccessory = accessory;
                    _streamDelegate.SetupController(accessory, deviceProtocol);
                    _streamDelegate.OpenSession();

                    Console.WriteLine("Already connected via bluetooth");

                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
    public static void onChoseToConnectDevice(string key)
    {
        if (DeviceName.Contains(key))
        {
            int temp = DeviceName.IndexOf(key);
//			if(temp==-1)
//				return;
            Debug.Log("!!!!!!!!   onChoseToConnectDevice in unity" + temp + "   " + key);
            _onChoseToConnectDevice(temp);
        }
    }
Beispiel #3
0
        private void button14_Click(object sender, EventArgs e)
        {
            string DeviceName;


            if (comboBox4.Text.Trim() != "")
            {
                try
                {
                    label12.Text    = "";
                    myport.PortName = comboBox4.Text.Trim();
                    if (!myport.IsOpen)
                    {
                        myport.Open();
                    }
                    myport.DiscardOutBuffer();     //خالی کردن بافر
                    myport.WriteLine("AT+cgmm\r"); //دستور شناخت مدل دستگاه
                    Thread.Sleep(1000);
                    DeviceName = myport.ReadExisting();
                    if (DeviceName.Contains("ERROR"))
                    {
                        MsgBox.ShowMessage(this.Handle.ToInt32(), "Device does not support this command or any other problem...", "خطا ", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                    }

                    else
                    {
                        //دستورات زیر برای بیرون کشیدن نام دستگاه از رشته خوانده شده از پورت هست
                        //(char)13 کاراکتر اینتر!
                        DeviceName = DeviceName.Remove(0, DeviceName.IndexOf((char)13)).Trim();
                        DeviceName = DeviceName.Substring(0, DeviceName.IndexOf((char)13));

                        MsgBox.ShowMessage(this.Handle.ToInt32(), "شناسایی با موفقیت انجام شد :" + Environment.NewLine + "Device Name:" + Environment.NewLine + DeviceName, "  ", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);


                        label12.Text = "نام دستگاه : " + DeviceName;
                        //button1.Enabled = true;
                    }
                    myport.DiscardOutBuffer();
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(this.Handle.ToInt32(), ex.Message.ToString(), " خطا", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                }
                finally
                {
                    //  myport.Close();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Resolves the following properties for both back and front camera:
        /// Flash and (auto) focus support and both photo and video capture
        /// resolutions.
        /// </summary>
        private async void ResolveCameraInfoAsync()
        {
            HasBackCamera               = false;
            HasFrontCamera              = false;
            HasBackCameraFlash          = false;
            HasFrontCameraFlash         = false;
            HasBackCameraAutoFocus      = false;
            HasFrontCameraAutoFocus     = false;
            BackCameraPhotoResolutions  = new List <Size>();
            BackCameraVideoResolutions  = new List <Size>();
            FrontCameraPhotoResolutions = new List <Size>();
            FrontCameraVideoResolutions = new List <Size>();

            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
                Windows.Devices.Enumeration.DeviceClass.VideoCapture);

            DeviceInformation backCameraDeviceInformation = devices.FirstOrDefault(x => x.EnclosureLocation != null &&
                                                                                   x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            DeviceInformation frontCameraDeviceInformation = devices.FirstOrDefault(x => x.EnclosureLocation != null &&
                                                                                    x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);

            string backCameraId  = null;
            string frontCameraId = null;
            var    cameraIds     = new List <string>();

            if (backCameraDeviceInformation != null)
            {
                backCameraId  = backCameraDeviceInformation.Id;
                HasBackCamera = true;
                cameraIds.Add(backCameraId);
            }

            if (frontCameraDeviceInformation != null)
            {
                frontCameraId  = frontCameraDeviceInformation.Id;
                HasFrontCamera = true;
                cameraIds.Add(frontCameraId);
            }

            foreach (string cameraId in cameraIds)
            {
                if (_mediaCapture == null)
                {
                    _mediaCapture = new MediaCapture();

                    try
                    {
                        await _mediaCapture.InitializeAsync(
                            new MediaCaptureInitializationSettings
                        {
                            VideoDeviceId = cameraId
                        });
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(DebugTag + "ResolveCameraInfoAsync(): Failed to initialize camera: " + e.ToString());
                        _mediaCapture = null;
                        continue;
                    }
                }

                if (_mediaCapture.VideoDeviceController == null)
                {
                    Debug.WriteLine(DebugTag + "ResolveCameraInfoAsync(): No video device controller!");
                    continue;
                }

                bool hasFlash = _mediaCapture.VideoDeviceController.FlashControl.Supported;

                Windows.Media.Devices.MediaDeviceControlCapabilities focusCaps = _mediaCapture.VideoDeviceController.Focus.Capabilities;
#if !NETFX_CORE
                bool focusChangedSupported = _mediaCapture.VideoDeviceController.FocusControl.FocusChangedSupported;
#endif
                bool autoAdjustmentEnabled = false;
                _mediaCapture.VideoDeviceController.Focus.TryGetAuto(out autoAdjustmentEnabled);

                Debug.WriteLine(DebugTag + "ResolveCameraInfoAsync(): Focus details of the "
                                + (cameraId.Equals(backCameraId) ? "back camera:" : "front camera:")
                                + "\n\t- Focus.Capabilities.AutoModeSupported: " + focusCaps.AutoModeSupported
                                + "\n\t- Focus.Capabilities.Max: " + focusCaps.Max
                                + "\n\t- Focus.Capabilities.Min: " + focusCaps.Min
                                + "\n\t- Focus.Capabilities.Step: " + focusCaps.Step
                                + "\n\t- Focus.Capabilities.Supported: " + focusCaps.Supported
                                + "\n\t- Focus.TryGetAuto() (automatic adjustment enabled): " + autoAdjustmentEnabled
#if !NETFX_CORE
                                + "\n\t- FocusControl.FocusChangedSupported: " + focusChangedSupported
#endif
                                );

                if (cameraId.Equals(backCameraId))
                {
                    HasBackCameraFlash = hasFlash;
#if !NETFX_CORE
                    HasBackCameraAutoFocus = focusChangedSupported;
#endif
                    BackCameraPhotoResolutions = ResolveCameraResolutions(_mediaCapture, MediaStreamType.Photo);
                    BackCameraVideoResolutions = ResolveCameraResolutions(_mediaCapture, MediaStreamType.VideoRecord);
                }
                else if (cameraId.Equals(frontCameraId))
                {
                    HasFrontCameraFlash = hasFlash;
#if !NETFX_CORE
                    HasFrontCameraAutoFocus = focusChangedSupported;
#endif
                    FrontCameraPhotoResolutions = ResolveCameraResolutions(_mediaCapture, MediaStreamType.Photo);
                    FrontCameraVideoResolutions = ResolveCameraResolutions(_mediaCapture, MediaStreamType.VideoRecord);
                }

                _mediaCapture.Dispose();
                _mediaCapture = null;
            }

            // Auto focus fix for older phones
            foreach (string model in WP80PhoneModelsWithAutoFocus)
            {
                if (DeviceName.Contains(model))
                {
                    Debug.WriteLine(DebugTag + "ResolveCameraInfoAsync(): Auto focus fix applied");
                    HasBackCameraAutoFocus = true;
                    break;
                }
            }

            // Sort resolutions from highest to lowest
            SortSizesFromHighestToLowest(BackCameraPhotoResolutions);
            SortSizesFromHighestToLowest(FrontCameraPhotoResolutions);
            SortSizesFromHighestToLowest(BackCameraVideoResolutions);
            SortSizesFromHighestToLowest(FrontCameraVideoResolutions);

            Debug.WriteLine(DebugTag + "ResolveCameraInfoAsync(): "
                            + "\n\t- Back camera ID: " + backCameraId
                            + "\n\t- Front camera ID: " + frontCameraId
                            + "\n\t- Back camera flash supported: " + HasBackCameraFlash
                            + "\n\t- Front camera flash supported: " + HasFrontCameraFlash);

            AsyncOperationComplete();
        }