// Read current configuration from the instrument // TO-DO: Pull configuration-statements that is not returned with "*LRN?" - Ex ROSC // If instrument does not support "*LRN", query each setting separately public void LearnConfig(string state) { string tmp; string[] key_val = new string[2]; string[] settings = state.Split(';'); foreach (string str in settings) { tmp = str.Trim(); key_val = tmp.Split(new char[] { ' ' }, 2); Setting s = GetBySCPI(key_val[0]); if (s == null) { continue; } if (s is ListSetting) { ListSetting l = s as ListSetting; int index = Array.IndexOf(l.AllowableValues, key_val[1]); if (index == -1) { throw new ArgumentException("Error! Value \'" + key_val[1] + "\' is not allowed for setting \'" + key_val[0] + "\'"); } l.SelectedIndex = index; } else if (s is NumericSetting) { NumericSetting n = s as NumericSetting; double val = 0; if (!Double.TryParse(key_val[1], NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture, out val)) { throw new ArgumentException("Error! Could not parse numeric value \'" + key_val[1] + "\' for setting \'" + key_val[0] + "\'"); } n.value = val; } else { // Setting is not defined in the instrument model } } ClearChangedFlags(); }
// Set up the (default) configuration public Configuration() { // Start with only the relevant settings, add on as we go.. // Function section // Func ListSetting l = new ListSetting(); l.ID = SettingID.func; l.DisplayName = "Function"; l.SCPI = ":FUNC"; l.ToolTip = "Selects instrument measurement function."; l.AllowableValues = new string[] { "\"FREQ\"", "\"FREQ 2\"", "\"FREQ 3\"", "FREQ:RAT 1,2", "FREQ:RAT 1,3", "FREQ:RAT 1,3", "FREQ:RAT 2,1", "FREQ:RAT 2,3", "FREQ:RAT 3,1", "FREQ:RAT 3,2", "PER 1", "PER 2", "PER 3", "FTI 1", "FTI 2", "NDUT 1", "NDUT 2", "PDUT 1", "PDUT 2", "NWID 1", "NWID 2", "PWID 1", "PWID 2", "PHA 1,2", "PHA 2,1", "RTIM 1", "RTIM 2", "SPER 1", "SPER 2", "\"TINT\"", "\"TINT 2,1\"", "\"TINT 1\"", "TINT \"2\"", "TOT 1", "TOT 2", "TST 1", "TST 2", "TST 3", "FREQ:BURS", "FREQ:PRF", "FREQ:PRI", "NWIDth:BURS", "PWIDth:BURS" }; this.Add(l); // Trigger section // Trigger source l = new ListSetting(); l.ID = SettingID.trig_sour; l.DisplayName = "Trigger source"; l.SCPI = ":TRIG:SOUR"; l.ToolTip = "Selects instrument trigger source."; l.AllowableValues = new string[] { "IMM", "EXT", "BUS" }; this.Add(l); // Trigger slope l = new ListSetting(); l.ID = SettingID.trig_slop; l.DisplayName = "Trigger slope"; l.SCPI = ":TRIG:SLOP"; l.ToolTip = "Selects trigger slope, POSitive or NEGative."; l.AllowableValues = new string[] { "POS", "NEG" }; l.IsActive = delegate() { return(this.GetListByID(SettingID.trig_sour).SelectedIndex == 2); }; // Only active if ext trigger selected this.Add(l); // Number of triggers to accept NumericSetting n = new NumericSetting(); n.ID = SettingID.trig_coun; n.DisplayName = "Trigger count"; n.SCPI = ":TRIG:COUN"; n.ToolTip = "Number of triggers to accept. Total number of Readings = Sample Count x Trigger Count."; n.MaxValue = 1e6; n.MinValue = 1; //n.IsActive = null; // To do. Ignored if func = freq 1|2|3, and :freq:mode = CONT | RCON this.Add(n); // Trigger delay n = new NumericSetting(); n.ID = SettingID.trig_del; n.DisplayName = "Trigger delay"; n.SCPI = ":TRIG:DEL"; n.ToolTip = "Sets the delay time in seconds between the trigger signal and enabling the gate open for the first measurement. This may be useful in applications where the signal you want to measure is delayed with respect to the trigger."; n.MaxValue = 3600; n.MinValue = 0; this.Add(n); // Samples per trigger n = new NumericSetting(); n.ID = SettingID.samp_coun; n.DisplayName = "Sample count"; n.SCPI = ":SAMP:COUN"; n.ToolTip = "Number of samples to take per trigger-event."; n.MaxValue = 1e6; n.MinValue = 1; //n.IsActive = null; // To do this.Add(n); // Format l = new ListSetting(); l.ID = SettingID.form; l.DisplayName = "Data format"; l.SCPI = ":FORM"; l.ToolTip = "Defines if data is returned in 15-character printable ascii strings, or 64-bit binary values."; l.AllowableValues = new string[] { "ASC,15", "REAL,64" }; this.Add(l); // Big or little endian l = new ListSetting(); l.ID = SettingID.form_bord; l.DisplayName = "Byte order"; l.SCPI = ":FORM:BORD"; l.ToolTip = "Defines if 64-bit binary values are returned big- or little-endian. Intel is little endian, SWAP"; l.AllowableValues = new string[] { "NORM", "SWAP" }; n.IsActive = delegate() { return(GetListByID(SettingID.form).SelectedIndex == 2); }; this.Add(l); }