示例#1
0
        ///<summary>
        ///Returns JyeScope object. If scope is not recognized, throws ScopeNotRecognizedException with information about returned scope type. If no scope is found, throws ScopeNotDetectedException.
        ///<param name="port">IStreamResource serial port</param>
        ///</summary>
        ///
        public static JyeScope GetScope(SerialPortAdapter port)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Restart();
            while (stopwatch.ElapsedMilliseconds < 2000)
            {
                WriteFrame(new DataFrames.ScopeControlDataFrames.EnterUSBScopeMode(), port);
                System.Threading.Thread.Sleep(100);
                try
                {
                    DataFrames.ScopeControlDataFrames.ScopeReady Ready = new DataFrames.ScopeControlDataFrames.ScopeReady(InstReadBuffer(port));
                    Config.ScopeType properScope = Ready.ScopeType;
                    switch (properScope)
                    {
                    case Config.ScopeType.DSO082:
                        throw new ScopeNotSupportedException($"Scope recognized but not supported. Returned scope type: {(int)Ready.ScopeType}.");

                    case Config.ScopeType.DSO094:
                        throw new ScopeNotSupportedException($"Scope recognized but not supported. Returned scope type: {(int)Ready.ScopeType}.");

                    case Config.ScopeType.DSO068:
                        return(new DSO068(port));

                    case Config.ScopeType.DSO112A:
                        return(new DSO112(port));

                    default:
                        throw new ScopeNotRecognizedException($"Scope not recognized. Returned scope type: {(int)Ready.ScopeType}.");
                    }
                }
                catch (InvalidDataFrameException ex)
                {
                    //try again
                }
            }
            throw new ScopeNotDetectedException("Scope not detected.");
        }
示例#2
0
        private void lblPopulateConfig_Click(object sender, EventArgs e)
        {
            SetValuesInInfoToBlank();
            var port = GetSerialPort();

            if (port != null)
            {
                var config     = new GetConfig();
                var connect    = new EnterUSBScopeMode();
                var disconnect = new ExitUSBScopeMode();

                //Getting name of scope
                WriteFrame(disconnect, port);
                System.Threading.Thread.Sleep((Convert.ToInt16(cbxReadDelay.Text)));
                WriteFrame(connect, port);
                System.Threading.Thread.Sleep((Convert.ToInt16(cbxReadDelay.Text)));
                var bytes = InstReadBuffer(port);

                ScopeReady Ready = (ScopeReady)GetResponse(connect, port);
                if (Ready != null)
                {
                    Config.ScopeType properScope = Ready.ScopeType;
                    lblModel.Text = "Detected: " + Convert.ToString(properScope) + System.Environment.NewLine + "Readed: \"" + GetScopeName(Ready.Data) + "\"";
                }
                else
                {
                    GetScopeType type = new GetScopeType();
                    Ready = (ScopeReady)GetResponse(type, port);

                    if (Ready != null)
                    {
                        Config.ScopeType properScope = Ready.ScopeType;
                        lblModel.Text = "Detected: " + Convert.ToString(properScope) + "  Readed: \"" + GetScopeName(Ready.Data) + "\"";
                    }
                    else
                    {
                        lblModel.Text = "Scope not detected:   \"" + GetScopeName(InstReadBuffer(port)) + "'";
                    }
                }
                //Getting config of scope

                DSO.Interfaces.ICurrentConfig cfg = (DSO.Interfaces.ICurrentConfig)GetResponse(config, port);
                if (cfg != null)
                {
                    lblCplChangeable.Text   = cfg.CoupleChangeableByHost.ToString();
                    lblMinMaxCpl.Text       = cfg.MinCoupleSetting + "/" + cfg.MaxCoupleSetting;
                    lblMinMaxRecLength.Text = cfg.MinRecordLength + "/" + cfg.MaxRecordLength;
                    lblMinMaxSens.Text      = cfg.MinVerticalSensitivity + "/" + cfg.MaxVerticalSensitivity;
                    lblMinMaxTb.Text        = cfg.MinTimebaseSetting + "/" + cfg.MaxTimebaseSetting;
                    lblMinMaxTrigLevel.Text = cfg.MinTriggerLevel + "/" + cfg.MaxTriggerLevel;
                    lblMinMaxTrigMode.Text  = cfg.MinTriggerModeSetting + "/" + cfg.MaxTriggerModeSetting;;
                    lblMinMaxTrigPos.Text   = cfg.MinTriggerPosition + "/" + cfg.MaxTriggerPosition;;
                    lblMinMaxTrigSlope.Text = cfg.MinSlopeModeSetting + "/" + cfg.MaxSlopeModeSetting;

                    if (cfg.Ch1Present == true && cfg.Ch2Present == true)
                    {
                        lblNoOfChannels.Text = "2";
                    }
                    else if (cfg.Ch1Present == false || cfg.Ch2Present == false)
                    {
                        lblNoOfChannels.Text = "1";
                    }

                    lblSensChangeable.Text = cfg.SensitivityChangeableByHost.ToString();
                }
                port.Dispose();
            }
        }