/* * /// <summary> * /// Requests all 6 voltage measurements for the specified FEB HDMI channel. * /// <para>The voltage measurement is returned on onVoltageChanged event</para> * /// <para>onVoltageChanged returns double[6] showing all 6 HDMI values in the order Trim0-Trim3, Bias, LED</para> * /// <para>If inTestMode=true then onVoltageChanged is asserted with VoltageChangedEventArgs.Voltage = voltageDefaultValue</para> * /// </summary> * /// <param name="channelNumber">the integer number 0-15, of the FEB HDMI channel to read</param> * internal void GetVoltage(int HDMIchannelNumber = 0) * { * if (inTestMode) * { * VoltageChangedEventsArgs VoltArgs = new VoltageChangedEventsArgs(); * if (OnVoltageChanged != null) * VoltArgs.HDMIchannel = HDMIchannelNumber; * OnVoltageChanged(this, VoltArgs); * return; * } * * if (HDMIchannelNumber < 0 || HDMIchannelNumber > 15) * throw new Exception(scopeName + ": GetVoltage. channel number " + HDMIchannelNumber + " is out of bounds. Must be 0-15"); * * // For assistance with DMM VISA See: * //https://www.keysight.com/upload/cmc_upload/All/iols_15_5_visa_users_guide.pdf * //https://literature.cdn.keysight.com/litweb/pdf/34972-90001.pdf?id=1837993 * //https://www.keysight.com/upload/cmc_upload/All/34970-90003_users.pdf * best for programming * //http://instructor.physics.lsa.umich.edu/adv-labs/Tools_Resources/HP%2034970A%20quick%20reference%20guide.pdf * //http://literature.cdn.keysight.com/litweb/pdf/5989-6338EN.pdf * string range = FEB.HDMIs[HDMIchannelNumber].Trim0.myDmmId + ":" + FEB.HDMIs[HDMIchannelNumber].LED.myDmmId; * * /* bool useAsync = false; * if (useAsync == true) //use asyncornous read and write. This worked for the Tek scope but fails now that the DMM is reading ranges. * { * write("MEASure:VOLTage:DC? (@" + range + ")\n"); // AUTO ,MAX, (@101)"); //,316)"); * WriteComplete += readVoltage; * } * else //use Sync read and write Added Jan 2017 Stephen to avoid errors with ivi.VISA * { */ /* * simpleReadWrite("MEASure:VOLTage:DC? (@" + range + ")\n"); * // } * } */ private static void simpleReadWrite(string command) { try { string textToWrite = ReplaceCommonEscapeSequences(command); mbSession.RawIO.Write(textToWrite); string DMMresponse = ""; int timeout = 0; while (DMMresponse == "" && timeout < 100) { Application.DoEvents(); DMMresponse = InsertCommonEscapeSequences(mbSession.RawIO.ReadString()); timeout++; } Console.WriteLine($"simpleReadWrite timeout = {timeout}. DMM response is <{DMMresponse}>"); if (DMMresponse != "") { readArgs e = new readArgs(); e.text = InsertCommonEscapeSequences(DMMresponse); parseVoltage(null, e); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void OnReadComplete(IVisaAsyncResult result) { try { string responseString = mbSession.RawIO.EndReadString(result); if (ReadComplete != null) { readArgs e = new readArgs(); e.text = InsertCommonEscapeSequences(responseString); ReadComplete(null, e); } } catch (Exception exp) { if (ReadComplete != null) { readArgs e = new readArgs(); e.text = InsertCommonEscapeSequences(scopeName + ": OnReadComplete failed. " + exp.Message); ReadComplete(null, e); } else { //throw new Exception(scopeName + ": OnReadComplete failed. " + exp.Message); } } }
private static void parseVoltage(object sender, readArgs e) { VoltageChangedEventsArgs VoltArgs = new VoltageChangedEventsArgs(); try { ReadComplete -= parseVoltage; //expected result = :MEASUREMENT:MEAS1:VALUE 3.5414E0\n string rawResponse = RemoveCommonEscapeSequences(e.text); string[] response = rawResponse.Split(','); VoltArgs.Voltage = new double[response.Length]; for (int i = 0; i < response.Length; i++) { VoltArgs.Voltage[i] = double.Parse(response[i]); } VoltArgs.isValid = (response.Length > 0); // 9.9E37 is the scope return value for invalid measurement. } catch (Exception arg) { VoltArgs.isValid = false; } OnVoltageChanged?.Invoke(null, VoltArgs); }