using System; using System.Collections; using TekVISANet; namespace TekVISAExample { class Program { static void Main(string[] args) { string response; ArrayList resources = new ArrayList(); VISA tekVISA = new VISA(); tekVISA.FindResources("?*", out resources); Console.WriteLine("RESOURCES:"); foreach (string s in resources) Console.WriteLine(s); tekVISA.Open(resources[0].ToString()); tekVISA.Write("*IDN?"); bool status = tekVISA.Read(out response); if (status) Console.WriteLine("IDN (device information): {0}", response); Console.ReadKey(); } } }
using System; using System.Collections; using TekVISANet; namespace TekVISAExample { class Program { private const string OSCILLOSCOPE = "USB0::0x0699::0x0376::C011053::INSTR"; static void Main(string[] args) { VISA tekVISA = new VISA(); ArrayList resources = new ArrayList(); tekVISA.FindResources("?*", out resources); bool opened = false; if (resources.Contains(OSCILLOSCOPE)) opened = tekVISA.Open(OSCILLOSCOPE); if (opened) { /// 2 tekVISA.Write("CH2:COUPLING AC"); tekVISA.Write("CH2:SCALE 20.000E-3"); tekVISA.Write("CH2:BANDWIDTH 20.000E+6"); /// ? tekVISA.Write("MEASUREMENT:MEAS1:TYPE RMS"); tekVISA.Write("MEASUREMENT:MEAS1:SOURCE1 CH2"); tekVISA.Write("MEASUREMENT:MEAS1:STATE ON"); /// RMS tekVISA.Write("MEASUREMENT:MEAS1:VALUE?"); string response = ""; /// tekVISA.Read(out response); Console.WriteLine("RMS CH2 VALUE: {0}", response); } Console.ReadKey(); } }
using System; using System.Linq; using System.Collections; using System.Globalization; using TekVISANet; using System.Threading; namespace TekVISAExample { class Program { private const string OSCILLOSCOPE = "USB::0x0699::0x0376::C011053::INSTR"; static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); VISA tekVISA = new VISA(); ArrayList resources = new ArrayList(); tekVISA.FindResources("?*", out resources); bool opened = false; if (resources.Contains(OSCILLOSCOPE)) opened = tekVISA.Open(OSCILLOSCOPE); if (opened) { NumberStyles styles = NumberStyles.AllowExponent | NumberStyles.Number; string response = ""; tekVISA.Write("DATA:SOU CH2"); tekVISA.Write("DATA:WIDTH 1"); tekVISA.Write("DATA:ENC ASCII"); tekVISA.Write("DATA:STOP 5208"); tekVISA.Query("WFMPRE:YMULT?", out response); response = response.Replace(":WFMPRE:YMULT ", ""); float ymult = float.Parse(response, styles); tekVISA.Query("WFMPRE:YZERO?", out response); response = response.Replace(":WFMPRE:YZERO ", ""); float yzero = float.Parse(response, styles); tekVISA.Query("WFMPRE:YOFF?", out response); response = response.Replace(":WFMPRE:YOFF ", ""); float yoff = float.Parse(response, styles); tekVISA.Query("WFMPRE:XINCR?", out response); response = response.Replace(":WFMPRE:XINCR ", ""); float xincr = float.Parse(response, styles); tekVISA.Write("CURVE?"); tekVISA.Read(out response); response = response.Replace(":CURVE ", ""); sbyte[] rawwave = response.Split(',').Select(n => Convert.ToSByte(n)).ToArray(); float[] wave = new float[rawwave.Count()]; for (int j = 0; j < rawwave.Count(); j++) wave[j] = (rawwave[j] - yoff) * ymult + yzero; System.IO.StreamWriter file = new System.IO.StreamWriter("waveform.csv"); file.WriteLine("V,S"); for (int j = 0; j < wave.Count(); j++) { float timepoint = j * xincr; file.WriteLine(wave[j].ToString() + "," + timepoint.ToString()); } file.Close(); tekVISA.Close(); } Console.ReadKey(); } } }
Source: https://habr.com/ru/post/271641/
All Articles