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:
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
filepath=uigetdir('C:\','Open directory where *.dll is located');
MM_DotNet_DLL=NET.addAssembly([filepath '\MMDeviceControlLib.dll'])
import MMDeviceControlLib.*
import MMDeviceControlLib.MMDeviceInterface.*
New_Device_Interface=MMDeviceInterface
New_Device_Interface.SetAllOpen(true);
New_Device_Interface.ResetAllToFactoryDefaults(false);
New_Device_Interface.SetAllActive(false);
New_Device_Interface.SetAllShuntCal(false);
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();
}
}
}