示例#1
0
        /// <summary>
        /// <c>openPort</c> connects to the instrument addressed to
        /// <c>busAddress</c> and set the <c>STATe</c> of the 
        /// instrument to <c>ON</c>, from this point the instruments are ready
        /// to start communicating.
        /// </summary>
        /// <returns>true</returns> is returned if the connection is succeded,
        /// <c>isConnected</c> is set to <c>true</c> to be used as flag during the
        /// experiment.
        public virtual void OpenPort()
        {
            object[] idnItems;
            string caption = "Alert - Open Port";
            string menssagem = "";
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            try
            {

                dmm.IO = (IMessage)mgr.Open(instrInfo.busAddress.ToUpper(),
                                AccessMode.NO_LOCK, 2000, this.IO_Options);

                dmm.IO.SendEndEnabled = true;
                dmm.IO.TerminationCharacter = 0x0A;
                dmm.IO.TerminationCharacterEnabled = true;

                dmm.WriteString("\n", true); // termination caracter
            }
            catch (Exception e)
            {
                Ivi.Visa.Interop.GPIBAddressState GPIBState = new Ivi.Visa.Interop.GPIBAddressState();
                Ivi.Visa.Interop.VisaStatusCode VISAStatus = new Ivi.Visa.Interop.VisaStatusCode();
                MessageBox.Show("Error :" + e.Message + " VISA Status :" + VISAStatus + " - " + instrInfo.busAddress.ToUpper(), caption, buttons);
               // System.Console.Out.WriteLine("An error occurred: " + e.Message + GPIBState);
            }
              /* finally
            {
                if (dmm.IO != null)
                  this.ClosePort();
            }*/
        }
示例#2
0
        /// <summary>
        /// <c>openPort</c> connects to the instrument addressed to
        /// <c>busAddress</c> and set the <c>STATe</c> of the 
        /// instrument to <c>ON</c>, from this point the instruments are ready
        /// to start communicating.
        /// </summary>
        /// <returns>true</returns> is returned if the connection is succeded,
        /// <c>isConnected</c> is set to <c>true</c> to be used as flag during the
        /// experiment.
        public virtual bool OpenPort()
        {
            string caption = "Alert - Open Port";
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            try
            {

                dmm.IO = (IMessage)mgr.Open(instrInfo.busAddress.ToUpper(),
                                AccessMode.NO_LOCK, 2000, this.IO_Options);

                DisposeResources TestObj = new DisposeResources(dmm);

                // Use the resource.
                TestObj.DoSomethingWithResource();

                // Dispose the resource.
                TestObj.Dispose();

            }
            catch (Exception e)
            {
                Ivi.Visa.Interop.GPIBAddressState GPIBState = new Ivi.Visa.Interop.GPIBAddressState();
                Ivi.Visa.Interop.VisaStatusCode VISAStatus = new Ivi.Visa.Interop.VisaStatusCode();
                MessageBox.Show("Error :" + e.Message + " VISA Status :" + VISAStatus + " - " + instrInfo.busAddress.ToUpper(), caption, buttons);
               // System.Console.Out.WriteLine("An error occurred: " + e.Message + GPIBState);
                return false;
            }
               finally
            {
                if (dmm.IO != null)
                  this.ClosePort();
            }
            return true;
        }