/// <summary> /// Values of the instrument parameters are set using <c>send</c>. /// The command to set is predefined by <c>instrInfo.sendCms</c> /// according to the instrument instantiated. /// </summary> /// <param name="val">Value to set the instrument parameter.</param> /// <returns>true</returns> is returned if everything is ok. public void Send(float val) { //if (this.mainform1 != null) // this.mainform1.setInstrumentValue(FormattedIO488 dmm, InstrumentInfo cmd, float val, bool VF); string caption = "Alert - Send Command"; //string menssagem = " "; MessageBoxButtons buttons = MessageBoxButtons.OK; try { dmm.WriteString(instrInfo.sendCmd + val + "\n", true); // string CMDvalue = instrInfo.sendCmd; //MessageBox.Show( CMDvalue, caption, buttons); } catch (Exception e) { Ivi.Visa.Interop.GPIBAddressState GPIBState = new Ivi.Visa.Interop.GPIBAddressState(); // System.Console.Out.WriteLine("An error occurred: " + e.Message); MessageBox.Show("Error :" + e.Message + " GPIB State :" + GPIBState, caption, buttons); } }
/// <summary> /// A measurement is <c>read</c> where <c>instrInfo.readCmd</c> /// is a string containing the command description to be /// executed in the instrument. The bus is read by the formatted /// string returned with <c>dmm.ReadString</c> and converted to /// <c>float</c>. /// </summary> /// <returns>val</returns> is the value measured in the instrument. public float Read() { string caption = "Alert - Read Command"; //string menssagem = " "; MessageBoxButtons buttons = MessageBoxButtons.OK; //String.Format("0.0######e+###", float.MaxValue); float val = -float.MaxValue; try { Contract.Ensures(val != -float.MaxValue); dmm.WriteString(instrInfo.readCmd, true); if (dmm.IO.ResourceName == "GPIB0::17::INSTR") { /*string sample returned by pAMETER' NI+1.228E-04,A+0000'.*/ string valor = dmm.ReadString(); string fc = valor.Substring(1,2); /* XXX+X. existem 3 caracteres antes do primeiro sinal*/ string sig = valor.Substring(3,1); string ic = valor.Substring(4,5); int pos = valor.IndexOf("E"); string sigexp = ""; if (pos == -1) sigexp = valor.Substring(10,1); else sigexp = valor.Substring(pos+1,1); string exp = valor.Substring(11,2); string sigva = valor.Substring(15,1); string va = valor.Substring(16,4); val = float.Parse(sig+ic); } else if (dmm.IO.ResourceName == "GPIB0::9::INSTR") { /*string sample returned by Data Acquisition -9.90000000E+37*/ string valor = dmm.ReadString(); float vl1; string sigvl = valor.Substring(0, 1); string vl = valor.Substring(1, 10); //val = float.Parse(sigvl + vl); string vlfull = valor.Substring(0, 15); if (float.TryParse(vlfull, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out vl1)) val = vl1; else val = float.Parse(vlfull); } //val = 20; //MessageBox.Show(val.ToString(), caption, buttons); return val; } catch (Exception e) { Ivi.Visa.Interop.GPIBAddressState GPIBState = new Ivi.Visa.Interop.GPIBAddressState(); System.Console.Out.WriteLine("An error occurred: " + e.Message); MessageBox.Show("Error :" + e.Message + " GPIB State :" + GPIBState, caption, buttons); return val; } finally { } }
/// <summary> /// A measurement is <c>read</c> where <c>instrInfo.readCmd</c> /// is a string containing the command description to be /// executed in the instrument. The bus is read by the formatted /// string returned with <c>dmm.ReadString</c> and converted to /// <c>float</c>. /// </summary> /// <returns>val</returns> is the value measured in the instrument. public float Read() { string caption = "Alert - Read Command"; //string menssagem = " "; MessageBoxButtons buttons = MessageBoxButtons.OK; float val = -float.MaxValue; try { Contract.Ensures(val != -float.MaxValue); dmm.WriteString(instrInfo.readCmd, true); val = float.Parse(dmm.ReadString()); //val = 20; MessageBox.Show(dmm.ReadString(), caption, buttons); return val; } catch (Exception e) { Ivi.Visa.Interop.GPIBAddressState GPIBState = new Ivi.Visa.Interop.GPIBAddressState(); System.Console.Out.WriteLine("An error occurred: " + e.Message); MessageBox.Show("Error :" + e.Message + " GPIB State :" + GPIBState, caption, buttons); return val; } finally { } }
/// <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(); }*/ }
/// <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; }