public static double ReadDB(string addr, string window, string m1)
        {
            int resourceManager = 0, viError;
            int session = 0;


            viError = AgVisa32.viOpenDefaultRM(out resourceManager);

            viError = AgVisa32.viOpen(resourceManager, addr.ToString(),
                                      AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
            System.Threading.Thread.Sleep(100);

            viError = AgVisa32.viPrintf(session, "CALC:PAR:SEL '" + window + "'" + "\n");

            viError = AgVisa32.viPrintf(session, "CALC:" + m1 + ":Y?" + "\n");
            string res = "";

            AgVisa32.viRead(session, out res, 100);

            System.Threading.Thread.Sleep(100);
            AgVisa32.viClose(session);
            AgVisa32.viClose(resourceManager);
            double dtmp = double.Parse(res.ToString().Split(',')[0]);

            return(dtmp);
        }
Beispiel #2
0
        /// <summary>
        /// Open the underlying driver (VISA, Eiger, whatever)
        ///
        /// If you need a shared session (VI_SHARED_LOCK), call Open() with exclusive==false then call LockSession.
        /// </summary>
        /// <param name="resource">the VISA resource descriptor.  Ignored if simulated is true</param>
        /// <param name="timeout">I/O timeout in ms ... not all drivers/sessions use this</param>
        /// <param name="simulated">if true, no connection to hardware will be made</param>
        /// <param name="exclusive">if true opens session exclusively (VI_EXCLUSIVE_LOCK).  if false opens session with no lock (VI_NO_LOCK)</param>
        public void Open(string resource, int timeout, bool simulated, bool exclusive)
        {
            // If already open, report an error...
            if (IsSimulated || mSession != 0)
            {
                throw new IOException("VisaSession is already open");
            }

            mViDesc  = resource;
            mTimeout = timeout;

            // Cache the resource descriptor -- may be used to open additional sessions to the same resource
            ResourceDescriptor = resource;
            Timeout            = timeout;
            mDefaultTimeout    = timeout;

            if (simulated)
            {
                // NOTE: if you want control of these values, use MockSession
                IsSimulated = true;
                mSlot       = 1;
                mModelCode  = 0x1234;
                mModelName  = resource;
                mSession    = resource.GetHashCode();
                return;
            }

            // Make sure cached values are cleared
            mSlot      = -1;
            mModelCode = -1;
            mModelName = string.Empty;

            CheckStatus(AgVisa32.viOpen(
                            mResourceManager,
                            resource,
                            (exclusive) ? AgVisa32.VI_EXCLUSIVE_LOCK : AgVisa32.VI_NO_LOCK,
                            timeout,
                            out mSession));

            // Cache the locked status
            IsSessionLocked = exclusive;

            // Use the supplied timeout as the default timeout for I/O operations
            CheckStatus(AgVisa32.viSetAttribute(mSession, AgVisa32.VI_ATTR_TMO_VALUE, timeout));

            // NOTE: DMA default settings ... For Agilent IOLS 16.3.16603 these are
            //    VI_ATTR_DMA_ALLOW_EN 0
            //    VI_ATTR_SRC_INCREMENT 1
            //    VI_ATTR_DEST_INCREMENT 1
            //    VI_AGATTR_DMA_WRITE_THRESHOLD 512
            //    VI_AGATTR_DMA_READ_THRESHOLD 48
            //    VI_AGATTR_DMA_CHANNEL -1
        }
Beispiel #3
0
        /// <summary>
        /// 建立连接
        /// </summary>
        public virtual void VisaOpen()
        {
            _ViError = AgVisa32.viOpenDefaultRM(out _ResourceManager);
            if (_ViError != 0)
            {
                throw new Exception("error:" + _InstrAddr);
            }

            _ViError = AgVisa32.viOpen(_ResourceManager, _InstrAddr,
                                       AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out _Session);
            if (_ViError != 0)
            {
                throw new Exception("error:" + _InstrAddr);
            }
        }
        public void VisaOpen(string addr)
        {
            viError = AgVisa32.viOpenDefaultRM(out resourceManager);
            if (viError != 0)
            {
                throw new Exception("error:" + addr);
            }

            viError = AgVisa32.viOpen(resourceManager, addr,
                                      AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
            if (viError != 0)
            {
                throw new Exception("error:" + addr);
            }
        }
        public static void VisaWrite(string ip, string command)
        {
            StringBuilder gpib = new StringBuilder();

            gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", ip);

            int resourceManager = 0, viError;
            int session = 0;


            viError = AgVisa32.viOpenDefaultRM(out resourceManager);

            viError = AgVisa32.viOpen(resourceManager, gpib.ToString(),
                                      AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
            System.Threading.Thread.Sleep(100);
            viError = visa32.viPrintf(session, command + "\n");
            System.Threading.Thread.Sleep(100);
            AgVisa32.viClose(session);
            AgVisa32.viClose(resourceManager);
        }
        public static void SetMark(string p, string m1, double value)
        {
            StringBuilder gpib = new StringBuilder();

            gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", p);

            int resourceManager = 0, viError;
            int session = 0;


            viError = AgVisa32.viOpenDefaultRM(out resourceManager);

            viError = AgVisa32.viOpen(resourceManager, gpib.ToString(),
                                      AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
            System.Threading.Thread.Sleep(100);
            viError = visa32.viPrintf(session, "CALC:" + m1 + ":X " + value + "MHz" + "\n");
            System.Threading.Thread.Sleep(100);
            AgVisa32.viClose(session);
            AgVisa32.viClose(resourceManager);
        }
        public static void OpenPWR(string p, int dbm)
        {
            StringBuilder gpib = new StringBuilder();

            gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", p);

            int resourceManager = 0, viError;
            int session = 0;


            viError = AgVisa32.viOpenDefaultRM(out resourceManager);

            viError = AgVisa32.viOpen(resourceManager, gpib.ToString(),
                                      AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
            System.Threading.Thread.Sleep(100);
            viError = visa32.viPrintf(session, ":OUTPut ON" + "\n");
            viError = visa32.viPrintf(session, ":POWer " + dbm + " dBm" + "\n");
            System.Threading.Thread.Sleep(100);
            AgVisa32.viClose(session);
            AgVisa32.viClose(resourceManager);
        }
        public static bool MmemLoad(string addr, string filename)
        {
            try
            {
                int resourceManager = 0, viError;
                int session = 0;


                viError = AgVisa32.viOpenDefaultRM(out resourceManager);

                viError = AgVisa32.viOpen(resourceManager, addr.ToString(),
                                          AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session);
                System.Threading.Thread.Sleep(100);
                viError = visa32.viPrintf(session, "MMEM:LOAD '" + filename + "'" + "\n");
                System.Threading.Thread.Sleep(100);
                AgVisa32.viClose(session);
                AgVisa32.viClose(resourceManager);
                return(true);
            }
            catch
            {
                return(false);
            }
        }