Trouble Using Abstract Class from .NET Assembly

조회 수: 3 (최근 30일)
Kian Milani
Kian Milani 2020년 1월 5일
답변: Andrew Janke 2020년 1월 31일
I am trying to communicate with a piezoelectric driver made by Thorlabs, which operates with their Kinesis software. I need to use the ThorlabsGenericPiezoCLI class within the Thorlabs.MotionControl.GenericPiezoCLI assembly, however, I get an error when I try to create an instance of the class. The code is
% Define the path to the assembly
thorlabs_asm_path = 'C:\Program Files\Thorlabs\Kinesis\';
genPiezo_asm_name = 'Thorlabs.MotionControl.GenericPiezoCLI.dll';
% Add the assembly
genPiezo_asm = NET.addAssembly(fullfile(thorlabs_asm_path,genPiezo_asm_name));
% define the class from th assembly
genPiezo_cls = Thorlabs.MotionControl.GenericPiezoCLI.Piezo.ThorlabsGenericPiezoCLI;
The error is
Error using Thorlabs.MotionControl.GenericPiezoCLI.Piezo.ThorlabsGenericPiezoCLI
Abstract classes cannot be instantiated. Class 'Thorlabs.MotionControl.GenericPiezoCLI.Piezo.ThorlabsGenericPiezoCLI' defines abstract methods and/or properties.
I guess my first question is how would I use the methods and properties that are within this class when it can't be instatiated? Or, if I use other subclasses that are from a different assembly but inherit from this abstract class, then do I need to instantiate this abstract class at all?

답변 (1개)

Andrew Janke
Andrew Janke 2020년 1월 31일
You do not need to, and in fact cannot, directly instantiate this abstract class. That's what an abstract class is: a class with an incomplete definition that cannot be instantiated on its own. You need to instantiate a "concrete" subclass of it that provides a complete implementation. Check the Thorlabs doco to find out which subclass you should be using in this case.

카테고리

Help CenterFile Exchange에서 Get Started with Microsoft .NET에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by