using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { System.Collections.ArrayList instrlist; int j; float ymult, yzero, yoff, xincr, timepoint; string response; bool status; TekVISANet.VISA TVA = new TekVISANet.VISA(); // Print list of VISA resources TVA.FindResources("?*", out instrlist); Console.WriteLine("Visa Resources"); for (j = 0; j < instrlist.Count; j++) { Console.WriteLine(j.ToString() + " : " + instrlist[j]); } Console.WriteLine("\n"); // Connect to a known instrument and print its IDN TVA.Open("USB0::0x0699::0x0425::CQ010017::INSTR"); TVA.Write("*IDN?"); status = TVA.Read(out response); if (status) { Console.WriteLine(response); } // Get curve data for channel 1, and scale to volts. byte[] rawwave; float[] wave; TVA.Write("DATA:SOU CH1"); TVA.Write("DATA:WIDTH 1"); TVA.Write("DATA:ENC RPB"); TVA.Query("WFMPRE:YMULT?", out response); ymult = float.Parse(response); TVA.Query("WFMPRE:YZERO?", out response); yzero = float.Parse(response); TVA.Query("WFMPRE:YOFF?", out response); yoff = float.Parse(response); TVA.Query("WFMPRE:XINCR?", out response); xincr = float.Parse(response); TVA.Write("CURVE?"); TVA.ReadBinary(out rawwave); Console.WriteLine("Number of Points " + rawwave.Count()); Console.WriteLine(rawwave[0].ToString()); Console.WriteLine(rawwave[1].ToString()); wave = new float[rawwave.Count()]; for (j = 0; j < rawwave.Count(); j++) { wave[j] = (rawwave[j] - yoff) * ymult + yzero; } //print the first 100 scaled waveform values to the screen for (j=0; j < 100; j++) { Console.Write(wave[j].ToString() + ","); } //write waveform to a csv file System.IO.StreamWriter file = new System.IO.StreamWriter("test.csv"); file.WriteLine("V,S"); for (j = 0; j < wave.Count(); j++) { timepoint = j * xincr; file.WriteLine(wave[j].ToString() + "," + timepoint.ToString()); } file.Close(); Console.WriteLine("\nPress Enter to exit"); Console.ReadLine(); TVA.Close(); } } }