Accessing a .NET abstract classes

15 visualizaciones (últimos 30 días)
GS76
GS76 el 1 de Dic. de 2019
Editada: GS76 el 19 de En. de 2020
Hi all,
I have created the following live script to access a .NET dll for the Micromeasurements P3 strain recorder and data logger.
I do not have experience with object-orientated programming and I have just come accross the following error message (in Italics), under the line of code "MMDeviceControl.DeviceInstance.
Error using MMDeviceControlLib.DeviceInstance
Abstract classes cannot be instantiated. Class 'MMDeviceControlLib.DeviceInstance' defines abstract methods
and/or properties.
Please see the class diagram for the .NET interface:
image002 (1).png
The vendor supplies a number of samples in C#. I have attached a zipped copy of the sample that I followed and it compiled 100% and ran, but I am unable to achieve the same in Matlab student version.
I have shown and attached the Matlab code as well as the MAT file, up to the point where I received the above error. I have also shown the C# code. I have indicated in the C# code where I am getting stuck duplicating this in Matlab. I have also attached a PDF copy of the live script.
Any assistance and advice with regards the above error would be appreciated.
MATLAB code
% Creating a global .NET assembly.
% File path of the *.dll.
filepath=uigetdir('C:\','Open directory where *.dll is located');
% Creating a .NET assembly.
MM_DotNet_DLL=NET.addAssembly([filepath '\MMDeviceControlLib.dll'])
import MMDeviceControlLib.*
import MMDeviceControlLib.MMDeviceInterface.*
New_Device_Interface=MMDeviceInterface
New_Device_Interface.SetAllOpen(true); % Open all found devices
New_Device_Interface.ResetAllToFactoryDefaults(false); % Set all devices to default configuration settings (do not save to flash)
New_Device_Interface.SetAllActive(false); % Set all existing channels to inactive
New_Device_Interface.SetAllShuntCal(false); % Disable shunt calibration on all devices
MMDeviceControlLib.DeviceInstance
C# code
using MMDeviceControlLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Display_All_Channels
{
class Program
{
/*
* Sample program to configure and display all channels on all devices by polling the device interface for data
*
*/
static void Main(string[] args)
{
try
{
Console.WriteLine("Creating interface and searching for devices...");
using (MMDeviceInterface deviceInterface = new MMDeviceInterface()) //Create the device interface instance
{
Console.WriteLine(string.Format("Found {0} devices", deviceInterface.DeviceInstances.Count()));
Console.WriteLine("Setting devices to open");
deviceInterface.SetAllOpen(true); //Open all found devices
deviceInterface.ResetAllToFactoryDefaults(false); //Set all devices to default configuration settings (do not save to flash)
deviceInterface.SetAllActive(false); //Set all existing channels to inactive
deviceInterface.SetAllShuntCal(false); //Disable shunt calibration on all devices
foreach (DeviceInstance device in deviceInterface.DeviceInstances)
{
Get stuck!! device.PoissonsRatio = 0.30; //Poissons ratio is set at the device instance
}
Console.WriteLine("Configuring and balancing (zeroing) channels...");
foreach (DeviceChannel channel in deviceInterface.Channels)
{
channel.Active = true; //Set the channel to active
channel.BridgeType = BridgeType.UndefinedHalfQuarter; //Set the bridge type
channel.EngUnits = "ue"; //Set engineering units to micro-strain
channel.GaugeFactor = 2.0; //Gage factor to 2.0
channel.BalanceMode = BalanceMode.Auto; //Set the balance mode to auto
channel.BalanceValue = channel.ADReading; //set the balance value to the current A/D reading
}
//Poll loop to read and display all available data until a any key is pressed
while (!Console.KeyAvailable)
{
foreach (double dataValue in deviceInterface.AllCurrentData)
{
Console.Write(string.Format("{0} ", dataValue));
}
Console.WriteLine();
Thread.Sleep(500);
}
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Exception: {0}", ex.Message));
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}

Respuesta aceptada

GS76
GS76 el 19 de En. de 2020
Editada: GS76 el 19 de En. de 2020
Hi all,
I received external assistance from https://www.freelancer.com/u/Intel1994 for this problem.
The support team at Vishay Micromeasurements assisted me with sample C# code, which formed the basis for this development.
I have continued developing the code and I have published on Matlab File Exchange if it can be of benefit to other users.

Más respuestas (0)

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by