Changing instrument parameters

Hi,

I’m writing a simple Gui to interact with OpenTap. One of items is to read and change some parameters in registered instruments
First I call

instrumentList = InstrumentSettings.Current.ToList();

to obtain a list of registered instruments. Then I load parameters of an instrument with

instrument = instrumentList[1]
var annotations = AnnotationCollection.Annotate(instrument);
var members = annotations?.Get<IMembersAnnotation>()?.Members.ToList();

First member is “Address”.
In source file I read that VisaAddress has two attributes:

        [Display("Address", Groups: new []{"VISA"}, Order: 1, Description: "The VISA address of the instrument e.g. 'TCPIP::1.2.3.4::INSTR' or 'GPIB::14::INSTR'")]
        [VisaAddress]
        public string VisaAddress { get; set; }

My question is:
how to obtain a list of available Visa Adresses to change actual address. I think that solution is to query [VisaAddress] Attribute, but I don’t understand how.

Thank in advance for answer.
Ralph

1 Like

Please try the below code,

var members = annotation.Get<IMembersAnnotation>()?.Members.ToList();
            foreach (var item in members)
            {
                bool isVisa = item.Get<IMemberAnnotation>()?.Member.HasAttribute<VisaAddressAttribute>() ?? false;
                if (isVisa)
                {
                    item.Get<IMemberAnnotation>()?.Member.SetValue(item.Source, "127.0.0.1");
                }
            }

Hi,
thanks for answer, but in this case I would set address with 127.0.0.1.
I need to fill a combo box with all available Visa addresses, and then choose one of them

Greetings
Ralph

Hi Ralph,

I understand like , you have multiple properties in Instrument class with [VisaAttribute]

    [VisaAddress]
    public string VisaAddress { get; set; }

    [VisaAddress]
    public string VisaAddress1 { get; set; }

    [VisaAddress]
    public string VisaAddress2 { get; set; }

and you need to display all VisaAddress 's in a Combo box,
While selecting the combo box you need to set the selected value to actual address(VisaAddress )?
Is this your use case?

             var instrumentList = InstrumentSettings.Current.ToList();
            var instrument = instrumentList[0];
            var annotations = AnnotationCollection.Annotate(instrument);

            // Combobox to display in the UI.
            List<string> comboboxVisaAddress = new List<string>();

            // To hold Actual Visa Address
            KeyValuePair<object, IMemberData> orgAddressObject = new KeyValuePair<object, IMemberData>();

            var members = annotations.Get<IMembersAnnotation>()?.Members.ToList();
            if (members != null)
            {
                foreach (var item in members)
                {
                    bool isVisa = item.Get<IMemberAnnotation>()?.Member.HasAttribute<VisaAddressAttribute>() ?? false;
                    if (isVisa)
                    {
                        var visaMemeber = item.Get<IMemberAnnotation>()?.Member;
                        if (visaMemeber.Name == "VisaAddress")
                        {
                            orgAddressObject = new KeyValuePair<object, IMemberData>(item.Source, item.Get<IMemberAnnotation>()?.Member);
                        }

                        comboboxVisaAddress.Add(visaMemeber.GetValue(item.Source).ToString());
                    }
                }

                // While Selecting Comobobox, Set Selected value to Actual Address.
                if (orgAddressObject.Key != null)
                {                                                          // Selelcted Combobox Value
                    orgAddressObject.Value.SetValue(orgAddressObject.Key, comboboxVisaAddress.FirstOrDefault());
                }
            }
1 Like

Hi,
it’s a little bit different. My target is to assign to an instrument one of the available visa address, find in the system
Looking in the source code I wrote this code to scan visa address in the system

IEnumerable<AnnotationCollection> suggestedValues = null;
var suggestedValuesList = new List<string>();
try
{
    bool isVisa = member.Get<IMemberAnnotation>()?.Member.HasAttribute<VisaAddressAttribute>() ?? false;
    if (isVisa)
    {
        suggestedValues = member.Get<ISuggestedValuesAnnotationProxy>()?.SuggestedValues;
        foreach (var item in suggestedValues)
        {
            suggestedValuesList.Add(item.Source.ToString());
        }
    }
}
catch { }

What do you think about?
And now, how I catch the type of SCPI instrument? I’m reading this part of XML

  <Keysight34465A type="MyDriver.Instruments.Keysight34465A" Source="">
    <VisaAddress>USB0::0x0957::0x0607::MY53007686::INSTR</VisaAddress>
    <IoTimeout>2000</IoTimeout>
    <FinegrainedLock>false</FinegrainedLock>
    <Lock>false</Lock>
    <LockRetries>5</LockRetries>
    <LockHoldoff>0.1</LockHoldoff>
    <QueryErrorAfterCommand>false</QueryErrorAfterCommand>
    <SendClearOnConnect>true</SendClearOnConnect>
    <VerboseLoggingEnabled>true</VerboseLoggingEnabled>
    <Name>DMM_KS34465A</Name>
  </Keysight34465A>

and I want capture “type” “MyDriver.Instruments.Keysight34465A” or directly instrument Keysight34465A

Thank
Ralph

I think you can cast to ScpiInstrument and set value accordingly.

var instrument = instrumentList[0] as ScpiInstrument;

Or you can try reflection

         var instrument = instrumentList[0];
            if (instrument != null)
            {
                var visaProperty = instrument.GetType().GetProperty("VisaAddress");
                var visaValue = visaProperty.GetValue(instrument);
            }
1 Like