Exemple #1
0
        static void Main(string[] args)
        {
            double FreqStart = 1000000000;
            double FreqStop  = 2000000000;

            var vi = new MessageSession(null).WithErrorsCheck();

            try
            {
                // Reset the analyzer to instrument preset
                vi.Print("SYSTem:FPRESET");

                // Create S11 measurement
                vi.Print("CALCulate1:PARameter:DEFine:EXT 'My_S11',S11");

                // Turn on Window #1
                vi.Print("DISPlay:WINDow1:STATe {0}", true);

                // Put a trace (Trace #1) into Window #1 and 'feed' it from the measurement
                vi.Print("DISPlay:WINDow1:TRACe1:FEED 'My_S11'");

                // Setup the channel for single sweep trigger
                vi.WithTimeout(1000).Query <int>("INITiate1:CONTinuous OFF;*OPC?");

                vi.Print("SENSe1:SWEep:TRIGger:POINt OFF");

                // Set channel parameters
                vi.Print("SENSe1:SWEep:POINts {0}", 11);
                vi.Print("SENSe1:FREQuency:STARt {0}", FreqStart);
                vi.Print("SENSe1:FREQuency:STOP {1}", FreqStop);

                // Send a trigger to initiate a single sweep
                vi.WithTimeout(1000).Query <int>("INITiate1;*OPC?");

                // Must select the measurement before we can read the data
                vi.Print("CALCulate1:PARameter:SELect 'My_S11'");

                // Read the measurement data into the "result" string variable
                vi.Print("FORMat ASCII");
                var data = vi.Query <double[]>("CALCulate1:DATA? FDATA");
            }
            catch (ScpiErrorException e)
            {
                System.Console.WriteLine("SCPI error occured for command \"{0}\": {1}", e.Context, e.Message);
            }
        }
Exemple #2
0
        public void TestFormatString()
        {
            var parameters = new List <string>();
            var mock       = new VisaviTest.VisaSessionMock();
            var responses  = new Queue <string>(new string[] { "any string", "+0, No error" });

            mock.FormattedIO.Setup(x => x.WriteLine(It.IsAny <string>())).Callback <string>(param => parameters.Add(param));

            var session = new MessageSession(mock.Session);

            session.Print(":SOUR1:TRAC:DATA {0}; :OUTP {1}; VALUE {2}", new double[] { 0.5, 0.1, 7 }, true, 5);
            Assert.That(parameters, Is.EqualTo(new[] { ":SOUR1:TRAC:DATA 0.5,0.1,7; :OUTP 1; VALUE 5" }));
            Assert.Pass();
        }
Exemple #3
0
        public void TestPrintReadArrayGeneric()
        {
            var mock      = new VisaviTest.VisaSessionMock();
            var responses = new Queue <string>(new string[] { "5.5,3.1, 1.64", "+0, No error" });

            mock.FormattedIO.Setup(x => x.ReadLine()).Returns(responses.Dequeue);

            var session = new MessageSession(mock.Session);

            session.Print("LIST?");
            var array = session.Read <double[]>();

            Assert.AreEqual(array, new double[] { 5.5, 3.1, 1.64 });
            Assert.Pass();
        }
Exemple #4
0
        public void TestLog()
        {
            var mock      = new VisaviTest.VisaSessionMock();
            var responses = new Queue <string>(new string[] { "-123, Error message" });

            mock.FormattedIO.Setup(x => x.ReadLine()).Returns(responses.Dequeue);
            mock.MessageBasedSession.Setup(x => x.ResourceName).Returns("TCPIP::instrument::INSTR");

            var session   = new MessageSession(mock.Session).WithErrorsCheck().Log(LogHandler);
            var exception = Assert.Catch <ScpiErrorException>(() => session.Print("FREQ {0}", 100), "Error message");

            Assert.AreEqual(-123, exception.HResult);
            Assert.AreEqual("FREQ 100", exception.Context);

            Assert.Pass();
        }
Exemple #5
0
        public void TestErrorException()
        {
            var mock      = new VisaviTest.VisaSessionMock();
            var responses = new Queue <string>(new string[] { "-321, Error message" });

            mock.FormattedIO.Setup(x => x.ReadLine()).Returns(responses.Dequeue);

            var session   = new MessageSession(mock.Session).WithResourceName("ANALYZER").WithErrorsCheck();
            var exception = Assert.Catch <ScpiErrorException>(() => session.Print("POW {0}", 10), "Error message");

            Assert.AreEqual(-321, exception.HResult);
            Assert.AreEqual("POW 10", exception.Context);
            Assert.AreEqual("ANALYZER", exception.ResourceName);
            var stackTrace = exception.StackTrace;

            Assert.IsNotNull(stackTrace);
            Assert.IsTrue(stackTrace.Contains(nameof(TestErrorException)));
            Assert.IsFalse(stackTrace.Contains(nameof(MessageSessionContext)));

            Assert.Pass();
        }