コード例 #1
0
ファイル: Transceiver.cs プロジェクト: UnifiedControl/PyMCE
        public void Stop()
        {
            if (_driver == null) return;

            Log.Trace("Stop()");

            try
            {
                _driver.Stop();
            }
            finally
            {
                _driver = null;
            }
        }
コード例 #2
0
ファイル: Transceiver.cs プロジェクト: UnifiedControl/PyMCE
        public void Start(InterferenceLevel[] ignore = null)
        {
            Log.Trace("Start()");

            if (_driver != null)
                throw new InvalidOperationException("MicrosoftMceTransceiver already started");

            if (_disableMceServices)
                DisableMceServices();

            var interference = InterferenceCheck();
            var interferenceError = false;
            var interferenceErrorMessage = "The following programs/services have been found to cause interference and should be closed: ";

            foreach (var item in interference)
            {
                var itemName = item.Key;
                var itemError = true;
                if (ignore != null)
                {
                    foreach (var ignoreLevel in ignore)
                    {
                        if ((item.Value & ignoreLevel) == ignoreLevel)
                        {
                            itemError = false;
                            itemName = "";
                        }
                    }
                }
                interferenceErrorMessage += itemName + ", ";
                if (!interferenceError) interferenceError = itemError;
            }

            if (interferenceError)
            {
                throw new InterferenceException(interference,
                    interferenceErrorMessage.Substring(0, interferenceErrorMessage.Length - 2));
            }

            Guid deviceGuid;
            string devicePath;

            Driver newDriver;

            if (FindDevice(out deviceGuid, out devicePath))
            {
                if (deviceGuid == MicrosoftGuid)
                {
                    if (Environment.OSVersion.Version.Major >= VistaVersionNumber)
                    {
                        newDriver = new DriverVista(deviceGuid, devicePath);
                    }
                    else
                    {
                        newDriver = new DriverXP(deviceGuid, devicePath);
                    }
                }
                else
                {
                    newDriver = new DriverReplacement(deviceGuid, devicePath);
                }
            }
            else
            {
                throw new InvalidOperationException("Device not found");
            }

            _driver = newDriver;
            _driver.StateChangedCallback = Driver_StateChangedCallback;
            _driver.CodeReceivedCallback = Driver_CodeReceivedCallback;
            _driver.Start();
        }