I’m currently adding Python plugins for multiple test & measurement devices and I was wondering if I could create a simple straightforward HAL in OpenTAP.
Let’s say I have two oscilloscopes coming from different vendors but both capable of doing certain things and I’d like to have them interchangeable within OpenTAP. To achieve that, I created an Oscilloscope
instrument class and two child implementations. In my test step I specified that it requires a resource of the Oscilloscope
type hoping that it would accept any of its child classes. Unfortunately it doesn’t seem to be the case as the list of available resources in the Editor is empty. That being said, everything works as expected if I couple my step to a specific child class.
Am I overlooking something?
1 Like
@tatiana.boye welcome to the OpenTAP community!
This should all be possible, however, I only have an example of doing this in .NET. Are you able to share a code snip of what you are trying? @rolf_madsen , @ivan.diep , or @kaushik.santhanam I think would be able to help.
1 Like
Thanks @brennen_direnzo!
Here’s a simplified example of what I’m trying to do:
import OpenTap
from PythonTap import Instrument, TestStep
@Attribute(BrowsableAttribute, False)
class Oscilloscope(Instrument):
pass
@Attribute(OpenTap.DisplayAttribute, "My Scope 1", "Scope 1.", "Oscilloscopes")
class MyScope1(Oscilloscope):
pass
@Attribute(OpenTap.DisplayAttribute, "My Scope 2", "Scope 2.", "Oscilloscopes")
class MyScope2(Oscilloscope):
pass
@Attribute(OpenTap.DisplayAttribute, "My Scope Test Step", "My scope test step.", "Signal Processing")
class MyScopeTestStep(TestStep):
def __init__(self):
super().__init__()
self.AddProperty("scope", None, Oscilloscope)\
.AddAttribute(OpenTap.DisplayAttribute, "Oscilloscope", "The oscilloscope to use in the step.", "Resources")
1 Like
Hi Tatiana,
In your MyScope1
and MyScope2
class, you should inherit from Oscilloscope
instead of Instrument
to get your desired behavior. All the other code in your example can be left as is.
@Attribute(BrowsableAttribute, False)
class Oscilloscope(Instrument):
pass
@Attribute(OpenTap.DisplayAttribute, "My Scope 1", "Scope 1.", "Oscilloscopes")
class MyScope1(Oscilloscope):
pass
@Attribute(OpenTap.DisplayAttribute, "My Scope 2", "Scope 2.", "Oscilloscopes")
class MyScope2(Oscilloscope):
pass
1 Like
@ivan.diep Thanks for checking that and sorry for the confusion–it was just a typo I made when preparing the “simplified example”. In the original code the inheritance is correct, I’ve just edited my previous post.
That said, the example seems to work properly. I’ll need to see what could be wrong with the original code, it must be something on my end. Thanks again @ivan.diep and @brennen_direnzo.
1 Like
Let us know if you are still having issues and we can dive in deeper.
1 Like