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 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.º 2
0
        //  public static  bool OpenScope(string name, string lastResourceString = "ASRL1::INSTR")
        public static bool OpenScope()
        {
            bool   open = false;
            string lastResourceString = "ASRL1::INSTR";

            //scopeName = name;

            if (inTestMode)
            {
                return(true);
            }

            using (sr = new SelectResource(scopeName, lastResourceString))
            {
                /*  if (lastResourceString != null)
                 * {
                 *    sr.ResourceName = lastResourceString;
                 * }*/
                DialogResult result = sr.DialogResult;
                if (result != DialogResult.OK)
                {
                    result = sr.ShowDialog();
                }
                if (result == DialogResult.OK)
                {
                    if (sr != null)
                    {
                        sr.Close();
                    }
                    lastResourceString = sr.ResourceName;
                    Cursor.Current     = Cursors.WaitCursor;
                    try
                    {
                        using (rmSession = new ResourceManager())
                        {
                            mbSession = (MessageBasedSession)rmSession.Open(lastResourceString);

                            serial = mbSession as ISerialSession;

                            serial.BaudRate = 115200;

                            serial.DataBits = 8;

                            serial.Parity = SerialParity.None;

                            serial.FlowControl = SerialFlowControlModes.RtsCts;

                            // Use SynchronizeCallbacks to specify that the object marshals callbacks across threads appropriately.
                            mbSession.SynchronizeCallbacks = true;

                            // ++++++ Reset the DMM to clear errors
                            write("*RST;*CLS\n");
                            // not supported... mbSession.WaitOnEvent(EventType.Clear);
                            Thread.Sleep(500);
                            write("*CLS\n"); //some times it takes two clears to reset a DMM error
                            Thread.Sleep(500);
                            // ------ end of reset

                            //   mbSession.ServiceRequest += MbSession_ServiceRequest;

                            //CONFigure[:VOLTage][:DC][{< range >| AUTO | MIN | MAX | DEF} [,{<resolution>|MIN|MAX|DEF}] ]
                            write("CONFigure:VOLTage:DC AUTO, (@101:316)\n");

                            // write("SENSe:VOLTage:DC:NPLC1,(@101:316)");
                            _isConnected = true;
                        }
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message);
                        _isConnected = false;
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
            // for testing
            //GetVoltages(signalList_AllSignals, 10, 888);
            return(open);
        }