public void Read(ref List <double> RtnList) { string strReturn = "0"; RtnList.Clear(); try { strReturn = myVISA.ReadString(); string[] RtnArray = strReturn.Split(new string[] { "," }, StringSplitOptions.None); double dblTemp = 0; int i = 0; int z = RtnArray.GetUpperBound(0); for (i = 0; i <= z; i++) { dblTemp = Convert.ToDouble(RtnArray[i]); RtnList.Add(dblTemp); } } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Handles the Click event of the btnReadGPIB control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnReadGPIB_Click(object sender, EventArgs e) { switch (cbInterfaceType.Text) { case "GPIB": { try { device.BeginRead(new AsyncCallback(OnReadComplete), null); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } case "USB": { answer = mbSession.ReadString(); break; } default: break; } }
public int ReadStrFromDevice(out string responseString) { var num = 0; responseString = ""; try { if ((m_connectType == 1) || (m_connectType == 2)) { responseString = mbSession.ReadString(); } else if (m_connectType == 0) { responseString = m_SerialPort.ReadExisting(); Delay(50); } } catch (Exception) { MessageBox.Show("Read string result from device has problem,please check the device"); num = -1; } if (responseString == "") { MessageBox.Show("Read string result from device is null,please check the device or device setting "); num = -1; } return(num); }
public string ReceiveDeviceAnswer() { lock (sendCommandRequestLocker) lock (requestQueryLocker) lock (receiveDeviceAnswerLocker) { return(mbSession.ReadString().TrimEnd(delim)); } }
/// <summary> /// get all set test parameters /// </summary> /// <param name="channel"></param> /// <returns></returns> private string GetNameList(string channel, bool isDiff) { string ret = null; string strGetChannelTraces = ":CALC" + channel + ":PAR:CAT?"; try { mbSession.Write(strGetChannelTraces); string strTemp = mbSession.ReadString(200).Trim('\n').Trim('"'); // strTemp = strTemp.Substring(1, strTemp.Length - 3); string[] tempNames = strTemp.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int cycleCount = tempNames.Length / 2; string[] chNames = new string[cycleCount]; string[] itemNames = new string[cycleCount]; for (int i = 0; i < cycleCount; i++) { chNames[i] = tempNames[i * 2]; itemNames[i] = tempNames[i * 2 + 1]; } int singleIndex = -1; for (int i = 0; i < cycleCount; i++) { if (FindTargetParameter(isDiff, itemNames[i])) { singleIndex = i; ret = chNames[singleIndex]; break; } } if (singleIndex == -1) { throw new VnaException("Not Find Any Single Parameter, please open a \"S21\" or \"S11\" parameter, and Try Again! "); } } catch (Exception e) { throw new VnaException("get name list from N5224 fail", e); } return(ret); }
public string Read() { if (mbSession == null) { return(null); } return(mbSession.ReadString()); }
public string read() { try { return(mSession.ReadString()); } catch (VisaException ex) { throw ex; } }
private string ReadParameter(string responseString, string targetParameter, TextBox targetTextBox) { try { //Send target Query command mbSession.Write(":u:f f ; :R:" + targetParameter + " 1 \n"); //Read the response responseString = mbSession.ReadString(); targetTextBox.Text = responseString; } catch (VisaException v_exp) { MessageBox.Show(v_exp.Message); } catch (Exception exp) { MessageBox.Show(exp.Message); } return(responseString); }
public string Read( ) { try { return(connect.ReadString()); } catch (Exception) { return("Fail"); } }
/// <summary> /// get all set test parameters /// </summary> /// <param name="channel"></param> /// <returns></returns> private List <string> GetNameList(string channel, bool nextByTrace) { //refer to SCPI.CALCulate(Ch).PARameter.COUNt List <string> retList = new List <string>(); string strGetChannelTraces = ":CALC" + channel + ":PAR:COUN?"; _mbSession.Write(strGetChannelTraces); int traceCount = int.Parse(_mbSession.ReadString(100).Trim()); try { for (int i = 0; i < traceCount; i++) { string strGetChannelTraceSelected = nextByTrace ? ":CALC" + channel + ":FSIM:BAL:PAR" + (i + 1) + ":BBAL?" : ":CALC" + channel + ":PAR" + (i + 1) + ":DEF?"; _mbSession.Write(strGetChannelTraceSelected); retList.Add(_mbSession.ReadString(100).Trim()); } } catch (Exception e) { throw new VnaException("get name list from E5071C fail", e); } return(retList); }
/// <summary> /// 读取返回值函数 /// </summary> /// <returns></returns> public string Read() { try { if (mbSession != null) { return(mbSession.ReadString()); } } catch (NationalInstruments.VisaNS.VisaException) { return(Convert.ToString(0)); } return(Convert.ToString(0)); }
private void read_Click(object sender, System.EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { string responseString = mbSession.ReadString(); readTextBox.Text = InsertCommonEscapeSequences(responseString); } catch (Exception exp) { MessageBox.Show(exp.Message); } finally { Cursor.Current = Cursors.Default; } }
private void cmdStartTest_Click(object sender, EventArgs e) { System.DateTime CurveTime; float wfmPerSec = 0; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); string temp; string SaveDirectory = txtSaveDirectory.Text; byte[] DataBuffer; int AcqLength = 0; int CurveCount = 0; int DataLength; int BytesRemaining; // Curve data conversion parameters int pt_off; float xinc; float xzero; float ymult; float yoff; float yzero; float xvalue; float yvalue; cmdStartTest.Enabled = false; lblCurveCount.Text = CurveCount.ToString(); lblWfmPerSec.Text = wfmPerSec.ToString("f"); Application.DoEvents(); // Allow the front panel to redraw // Check that the save directory is valid if (!System.IO.Directory.Exists(SaveDirectory)) { MessageBox.Show("Invalid save directory. Please enter a valid directory then try again.", "Error: Invalid Directory", MessageBoxButtons.OK, MessageBoxIcon.Error); cmdStartTest.Enabled = true; return; } // Prompt the user to prep the scope if (MessageBox.Show("Please setup the scope then press OK to start Curve Streaming. Once Curve Streaming has started you will not be able to control the scope until Curve Streaming is ended.", "Setup Scope", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel) { cmdStartTest.Enabled = true; return; } // Open a connection to the instrument try { TekScope = new MessageBasedSession(txtVisaResourceName.Text.Trim()); TekScope.Clear(); } catch (Exception ex) { // Show and error message then exit if the connection fails MessageBox.Show(ex.Message, "Error Opening Connection to Instrument", MessageBoxButtons.OK, MessageBoxIcon.Error); TekScope = null; cmdStartTest.Enabled = true; return; } GatherCurves = true; cmdEndTest.Enabled = true; // Setup the waveform transfer TekScope.Write("*CLS"); TekScope.Write("*CLE"); TekScope.Write("DATa:SOUrce CH1"); TekScope.Write("DATa:ENCdg RIBinary"); TekScope.Write("DATa:STARt 0"); TekScope.Write("HORizontal:ACQLENGTH?"); temp = TekScope.ReadString().Trim(); AcqLength = Int32.Parse(temp); TekScope.Write(String.Format("DATa:STOP {0}", AcqLength)); TekScope.Write("WFMOutpre:ENCdg BINary"); TekScope.Write("WFMOutpre:BYT_Nr 1"); // Get the needed values from the scope to scale the data TekScope.Write("WFMOutpre:PT_Off?"); temp = TekScope.ReadString().Trim(); pt_off = Int32.Parse(temp); TekScope.Write("WFMOutpre:XINcr?"); temp = TekScope.ReadString().Trim(); xinc = Single.Parse(temp); TekScope.Write("WFMOutpre:XZEro?"); temp = TekScope.ReadString().Trim(); xzero = Single.Parse(temp); TekScope.Write("WFMOutpre:YMUlt?"); temp = TekScope.ReadString().Trim(); ymult = Single.Parse(temp); TekScope.Write("WFMOutpre:YOFf?"); temp = TekScope.ReadString().Trim().TrimEnd('0').TrimEnd('.'); yoff = Single.Parse(temp); TekScope.Write("WFMOutpre:YZEro?"); temp = TekScope.ReadString().Trim(); yzero = Single.Parse(temp); // Turn on curve streaming TekScope.Write("CURVEStream?"); stopWatch.Reset(); stopWatch.Start(); // While still collecting curves. Ends when the user clicks End Test while (GatherCurves) { int NumBytesCharCount = 0; string BlockHeader = ""; TekScope.Timeout = 200; // Loop until the block header is found while (BlockHeader.Length == 0) { try { // Read the length of the string that contains the length of the data // Note: If this times out it just means that no curve has been sent out yet so need to wait again BlockHeader = TekScope.ReadString(2); if (BlockHeader == ";\n") // Then it's the terminator from the previous curve so throw it out and try again. { BlockHeader = ""; } } catch (VisaException ex) { if (ex.ErrorCode != VisaStatusCode.ErrorTimeout) // Then still waiting on another curve to come in { MessageBox.Show(ex.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } wfmPerSec = (float)CurveCount / ((float)stopWatch.ElapsedMilliseconds / (float)1000); lblWfmPerSec.Text = wfmPerSec.ToString("f"); Application.DoEvents(); if (!GatherCurves) { break; } } if (!GatherCurves) { break; } // Create a file with the current date and time as the name CurveTime = System.DateTime.Now; string FileName = String.Format("{0}{1}-{2:D2}-{3:D2}_{4:D2}{5:D2}{6:D2}.{7:D3}.csv", txtSaveDirectory.Text, CurveTime.Year, CurveTime.Month, CurveTime.Day, CurveTime.Hour, CurveTime.Minute, CurveTime.Second, CurveTime.Millisecond); StreamWriter SaveFile = new StreamWriter(FileName, false, Encoding.ASCII, BUFFER_SIZE * 10); // Calculate the xvalue for the first point in the record xvalue = (float)(-pt_off * (xinc + xzero)); // Get the number of bytes that make up the data length string NumBytesCharCount = Int32.Parse(BlockHeader.TrimStart('#'), System.Globalization.NumberStyles.HexNumber); // Read the data length string temp = TekScope.ReadString(NumBytesCharCount); DataLength = int.Parse(temp); BytesRemaining = DataLength; // Read the back the data, process it and save it to the file TekScope.Timeout = 5000; while (BytesRemaining > 0) { // Read bytes from scope if (BytesRemaining >= BUFFER_SIZE) { DataBuffer = TekScope.ReadByteArray(BUFFER_SIZE); BytesRemaining -= BUFFER_SIZE; } else { DataBuffer = TekScope.ReadByteArray(BytesRemaining); BytesRemaining = 0; } // Convert byte values to floating point values then write to .csv file foreach (byte DataPoint in DataBuffer) { yvalue = (float)((Convert.ToSingle((sbyte)DataPoint) - yoff) * (ymult + yzero)); SaveFile.WriteLine(xvalue.ToString() + "," + yvalue.ToString()); // Note: Converting to .CSV is very time consuming operation. // Save in a binary format to maximize speed. Highly recommended for waveforms >= 1 Million points. xvalue += xinc; } } SaveFile.Close(); CurveCount++; wfmPerSec = (float)CurveCount / ((float)stopWatch.ElapsedMilliseconds / (float)1000); lblWfmPerSec.Text = wfmPerSec.ToString("f"); lblCurveCount.Text = CurveCount.ToString(); Application.DoEvents(); } // Send Device Clear to stop the curve streaming TekScope.Clear(); TekScope.Dispose(); TekScope = null; cmdStartTest.Enabled = true; cmdEndTest.Enabled = false; }
public string Read() { return(Connector.ReadString().Replace("\n", "")); }