Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Change this variable to the address of your instrument
            string VISA_ADDRESS = "Your instrument's VISA address goes here!";

            // Create a connection (session) to the TCP/IP socket on the instrument.
            // Change VISA_ADDRESS to a SOCKET address, e.g. "TCPIP::169.254.104.59::5025::SOCKET"
            IMessageBasedSession session = GlobalResourceManager.Open(VISA_ADDRESS) as IMessageBasedSession;

            // The first thing you should do with a SOCKET connection is enable the Termination Character. Otherwise all of your read's will fail
            session.TerminationCharacterEnabled = true;

            // We can find out details of the connection
            ITcpipSocketSession socket = session as ITcpipSocketSession;

            Console.WriteLine("IP: {0}\r\nHostname: {1}\r\nPort: {2}\r\n",
                              socket.Address,
                              socket.HostName,
                              socket.Port);

            // Send the *IDN? and read the response as strings
            MessageBasedFormattedIO formattedIO = new MessageBasedFormattedIO(session);

            formattedIO.WriteLine("*IDN?");
            string idnResponse = formattedIO.ReadLine();

            Console.WriteLine("*IDN? returned: {0}", idnResponse);

            // Close the connection to the instrument
            session.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            string VISA_ADDRESS = listBox1.GetItemText(listBox1.SelectedItem);
            // Create a connection (session) to the instrument
            IMessageBasedSession session;

            session = GlobalResourceManager.Open(VISA_ADDRESS) as IMessageBasedSession;

            // Create a formatted I/O object which will help us format the data we want to send/receive to/from the instrument
            MessageBasedFormattedIO formattedIO = new MessageBasedFormattedIO(session);

            // For Serial and TCP/IP socket connections enable the read Termination Character, or read's will timeout
            if (session.ResourceName.Contains("ASRL") || session.ResourceName.Contains("SOCKET"))
            {
                session.TerminationCharacterEnabled = true;
            }

            formattedIO.WriteLine(":SYSTem:SECurity:ERASeall");
            formattedIO.WriteLine(":SYSTem:SECurity:SANitize");
            formattedIO.WriteLine(":SYSTem:FILesystem:STORage:FSDCard ON|OFF|1|0");
            formattedIO.WriteLine(":SYSTem:PRESet: PERSistent");
            formattedIO.WriteLine(":SYSTem:COMMunicate:LAN:DEFaults");
            formattedIO.WriteLine(":CAL:IQ:DEF");
            session.Dispose();
            MessageBox.Show("Очистка заврешена");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // Change this variable to the address of your instrument
            string VISA_ADDRESS = "Your instrument's VISA address goes here!";

            // Create a connection (session) to the RS-232 device.
            // Change VISA_ADDRESS to a serial address, e.g. "ASRL1::INSTR"
            IMessageBasedSession session = GlobalResourceManager.Open(VISA_ADDRESS) as IMessageBasedSession;

            // The first thing you should do with a serial port is enable the Termination Character. Otherwise all of your read's will fail
            session.TerminationCharacterEnabled = true;

            // If you've setup the serial port settings in Connection Expert, you can remove this section.
            // Otherwise, set your connection parameters
            ISerialSession serial = session as ISerialSession;

            serial.BaudRate    = 9600;
            serial.DataBits    = 8;
            serial.Parity      = SerialParity.None;
            serial.FlowControl = SerialFlowControlModes.DtrDsr;

            // Send the *IDN? and read the response as strings
            MessageBasedFormattedIO formattedIO = new MessageBasedFormattedIO(session);

            formattedIO.WriteLine("*IDN?");
            string idnResponse = formattedIO.ReadLine();

            Console.WriteLine("*IDN? returned: {0}", idnResponse);

            // Close the connection to the instrument
            session.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 4
0
 private bool openGPIB()
 {
     try
     {
         session     = GlobalResourceManager.Open(VISA_ADDRESS, AccessModes.None, 5) as IMessageBasedSession;
         formattedIO = new MessageBasedFormattedIO(session);
         MessageBox.Show("The instrument has been successfully connected on GPIB0::25", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(true);
     }
     catch (NativeVisaException visaException)
     {
         //Shell.WriteLine("Error is:\r\n{0}\r\nPress any key to exit...", visaException);
         MessageBox.Show("Please check GPIB conncetion. GPIB port of the instrument should be set as GPIB0::25", "Error: Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
Ejemplo n.º 5
0
 private bool openGPIB()
 {
     try
     {
         sessionLRC         = GlobalResourceManager.Open(LRC_VISA_ADDRESS, AccessModes.None, 50000) as IMessageBasedSession;
         formattedIOLRC     = new MessageBasedFormattedIO(sessionLRC);
         sessionTEMPCON     = GlobalResourceManager.Open(TEMPCON_VISA_ADDRESS, AccessModes.None, 50000) as IMessageBasedSession;
         formattedIOTEMPCON = new MessageBasedFormattedIO(sessionTEMPCON);
         MessageBox.Show("The instruments have been successfully connected on GPIB0::25 and GPIB0::12", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(true);
     }
     catch (NativeVisaException visaException)
     {
         MessageBox.Show("Failed to connect at least one instrument. Please check GPIB conncetion. GPIB port of the LRC Meter and Temperature Controller should be set as GPIB0::25 and GPIB0::12 respectively.", "Error: Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            // Change this variable to the address of your instrument
            string VISA_ADDRESS = "Your instrument's VISA address goes here!";

            // Create a connection (session) to the instrument
            IMessageBasedSession session;

            try
            {
                session = GlobalResourceManager.Open(VISA_ADDRESS) as IMessageBasedSession;
            }
            catch (NativeVisaException visaException)
            {
                Console.WriteLine("Couldn't connect. Error is:\r\n{0}\r\nPress any key to exit...", visaException);
                Console.ReadKey();
                return;
            }

            // Create a formatted I/O object which will help us format the data we want to send/receive to/from the instrument
            MessageBasedFormattedIO formattedIO = new MessageBasedFormattedIO(session);

            // For Serial and TCP/IP socket connections enable the read Termination Character, or read's will timeout
            if (session.ResourceName.Contains("ASRL") || session.ResourceName.Contains("SOCKET"))
            {
                session.TerminationCharacterEnabled = true;
            }

            // Send the *IDN? and read the response as strings
            formattedIO.WriteLine("*IDN?");
            string idnResponse = formattedIO.ReadLine();

            Console.WriteLine("*IDN? returned: {0}", idnResponse);

            // Close the connection to the instrument
            session.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // Change this variable to the address of your instrument
            string VISA_ADDRESS = "Your instrument's VISA address goes here!";

            IMessageBasedSession    session = null;
            MessageBasedFormattedIO formattedIO;

            // Part 1:
            //
            // Shows the mechanics of how to catch an exception (an error) in VISA.NET when it occurs.
            // To stimulate an error, the code will try to open a connection t an instrument at an invalid address...
            try
            {
                // First we'll provide an invalid address and see what error we get
                session = GlobalResourceManager.Open("BAD ADDRESS") as IMessageBasedSession;
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception has occurred!\r\n\r\n{0}\r\n", ex.ToString());

                // To get more specific information about the exception, we can check what kind of exception it is and add specific error handling code
                // In this example, that is done in the ExceptionHandler method
                ExceptionHandler(ex);
            }

            // Part 2:
            //
            // Stimulate another error by sending an invalid query and trying to read its response.
            //
            // Before running this part, don't forget to set your instrument address in the 'VISA_ADDRESS' variable at the top of this method
            session     = GlobalResourceManager.Open(VISA_ADDRESS) as IMessageBasedSession;
            formattedIO = new MessageBasedFormattedIO(session);

            // Misspell the *IDN? query as *IND?
            try
            {
                formattedIO.WriteLine("*IND?");
            }
            catch (Exception ex)
            {
                Console.WriteLine("You'll never get here, because the *IND? data will get sent to the instrument successfully, it's the instrument that won't like it.");
            }

            // Try to read the response (*IND ?)
            try
            {
                string idnResponse = formattedIO.ReadLine();

                Console.WriteLine("*IDN? returned: {0}", idnResponse);
            }
            catch (IOTimeoutException timeoutException)
            {
                Console.WriteLine("The ReadLine call will timeout, because the instrument doesn't know what to do with the command that we sent it.");

                // Check the instrument to see if it has any errors in its queue
                string rawError    = "";
                int    errorCode   = -1;
                string errorString = "";

                while (errorCode != 0)
                {
                    formattedIO.WriteLine("SYST:ERR?");
                    rawError    = formattedIO.ReadLine();
                    errorCode   = int.Parse(rawError.Split(',')[0]);
                    errorString = rawError.Split(',')[1];

                    Console.WriteLine("Error code: {0}, error message: {1}", errorCode, errorString.Trim());
                }
            }

            session.Dispose();

            Console.WriteLine("\r\nPress any key to exit...");
            Console.ReadKey();
        }
 private bool CGRmonitor(IMessageBasedSession session, MessageBasedFormattedIO formattedIO)
 {
     MeaLabelModify(1, 2.123);
     return(true);
 }
 private double RpMonitor(IMessageBasedSession session, MessageBasedFormattedIO formattedIO)
 {
     return(1.0);
 }