private void btnTake3DC_Click(object sender, System.EventArgs e) { double[] dNum = new double[3]; ioDmm.WriteString("CONF:VOLT:DC 10, 0.1;:SAMP:COUN 3", true); ioDmm.WriteString("READ?", true); dNum = (double[])ioDmm.ReadList(IEEEASCIIType.ASCIIType_R8, ","); this.txtReading1.Text = dNum[0].ToString(); this.txtReading2.Text = dNum[1].ToString(); this.txtReading3.Text = dNum[2].ToString(); }
public void Readings(ref ArrayList reading, ref ArrayList timestamp, ref ArrayList channelnum) //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" // This function triggers the instrument and takes readings. //YJW: 函数,读取安捷伦测量值 //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" { string Dateval, // Returns the date value //YJW: 日期 Timeval; // Returns the time value //YJW: 时间 int i; // Used for a loop //YJW: 循环计数器 object[] rdgs = new object[3]; // Returns reading from memory //YJW: OBJ容器, // Check for exceptions //YJW: 放在TRY里面捕获异常 try { // Trigger instrument //YJW: 开始测量 data_logger.WriteString("INITiate", true); // Get the date at which the scan was started //YJW: 从主机读测量开始的日期 data_logger.WriteString("SYSTem:DATE?", true); Dateval = data_logger.ReadString(); // Remove cr and or linefeed character //YJW: 去掉末尾标记用于显示 if (Globls.addrtype == "ASRL") { Dateval = Dateval.Remove((Dateval.Length - 2), 2); } else { Dateval = Dateval.Remove((Dateval.Length - 1), 1); } // Get the time at which the scan was started //YJW: 从主机读测量开始的时间 data_logger.WriteString("SYSTem:TIME?", true); Timeval = data_logger.ReadString(); // Remove cr and or lf character //YJW:去掉末尾标记用于显示 if (Globls.addrtype == "ASRL") { Timeval = Timeval.Remove((Timeval.Length - 2), 2); } else { Timeval = Timeval.Remove((Timeval.Length - 1), 1); } // Wait until instrument is finished taken readings. The instrument is queried // until all channels are measured. //YJW: 等待主机测量完毕,主机内存中的数据记录数目等于设定应有的记录数目 do { data_logger.WriteString("DATA:POINTS?", true); i = (Convert.ToInt16((double)data_logger.ReadNumber(IEEEASCIIType.ASCIIType_R8, true))); }while (i != Globls.NumRdgs); // Check for errors //YJW: 错误处理函数 Check_Error("Readings"); // Take readings out of memory one reading at a time. The "FETCh?" can also be used. // It reads all readings in memory, but leaves the readings in memory. The // "DATA:REMove?" command removes and erases the readings in memory. //YJW: 使用DATA:REMove?逐条从主机内存中读取并擦除记录,也可以使用FETCh,但是FETCh只读取不擦除 reading.Clear(); timestamp.Clear(); channelnum.Clear(); //YJW: 清空用来装测量数据的各个ARRAYLIST for (i = 0; i < Globls.NumRdgs; i++) //YJW: 逐条地 { data_logger.WriteString("DATA:REMove? 1", true); //READ AND REMOVE THE DATA FROM THE MENORY //YJW: 发送命令读取并且删除一条数据 rdgs = (object[])data_logger.ReadList(IEEEASCIIType.ASCIIType_BSTR, ","); //YJW: 用rdgs这个对象指针指向data_logger.Readlist这个对象 // Get reading //YJW: 读取测量值 reading.Add(Convert.ToDouble(rdgs[0].ToString())); //----------YJW CODE BEGIN---------- //YJW: 读取测量值的时间戳,时间戳是分散的,要拼起来 string temptimestamp = ""; for (int ind = 1; ind < rdgs.Length - 2; ind++) { temptimestamp += rdgs[ind].ToString(); } timestamp.Add(temptimestamp); //----------YJW CODE END---------- // Get channel number //YJW: 读取测量值对应的通道号 channelnum.Add(Convert.ToInt16(rdgs[rdgs.Length - 1].ToString().Substring(0, 3))); } } catch (Exception)//YJW: 异常捕获处理块 { //MessageBox.Show(e.Message + "\nin function: Readings", "VISACom"); //End_Prog(); } }
/* The following example uses CONFigure with the dBm math operation * The CONFigure command gives you a little more programming flexibility * than the MEASure? command. This allows you to 'incrementally' * change the multimeter's configuration. * Be sure to set the instrument address and Initialize before * caliing this method. */ private void btnConfigure_Click(object sender, System.EventArgs e) { try { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; btnConfigure.Enabled = false; btnMeasure.Enabled = false; //Reset the dmm ioDmm.WriteString("*RST", true); //Clear the dmm registers ioDmm.WriteString("*CLS", true); //Set 50 ohm reference for dBm ioDmm.WriteString("CALC:DBM:REF 50", true); /*CONFigure command sets range and resolution for AC. * all other AC function parameters are defaulted but can be * set before a READ? */ // Set dmm to 1 amp ac range ioDmm.WriteString("Conf:Volt:AC 1, 0.001", true); // Select the 200 Hz (fast) ac filter ioDmm.WriteString(":Det:Band 200", true); //dmm will accept 5 triggers ioDmm.WriteString("Trig:Coun 5", true); //Trigger source is IMMediate ioDmm.WriteString("Trig:Sour IMM", true); //Select dBm function ioDmm.WriteString("Calc:Func DBM", true); //Enable math and request operation complete ioDmm.WriteString("Calc:Stat ON", true); //Take readings; send to output buffer ioDmm.WriteString("Read?", true); // Get readings and parse into array of doubles // Enter will wait until all readings are completed //' print to Text box double[] Readings = new double[5]; string sText = ""; txtResult.Text = ""; Readings = (double[])ioDmm.ReadList(IEEEASCIIType.ASCIIType_R8, ","); for (int iIndex = 0; iIndex < Readings.Length; iIndex++) { sText = sText + Readings[iIndex].ToString() + " dBm" + "\r\n"; } txtResult.Text = sText; btnConfigure.Enabled = true; btnMeasure.Enabled = true; System.Windows.Forms.Cursor.Current = Cursors.Default; } catch (SystemException ex) { btnConfigure.Enabled = true; btnMeasure.Enabled = true; MessageBox.Show("Configure command failed. " + ex.Source + " " + ex.Message, "GPIBMeasConfig", MessageBoxButtons.OK, MessageBoxIcon.Error); } }