How to implement C# interface in Python

37 Views Asked by At

This is my implementation of this C# interface:

// Assembly location: D:\Others\PROJECTS\Strahlerdauretest\NewFirmware\FilamentEnduranceTest\dlls\Fischer.Devices.Dpp.Sdk.dll
using Filament.Standard.hightemperature;
using Filament.Standard.highvoltage;
using Fiona;
using System.Runtime.InteropServices;

#nullable disable
namespace Filament.Standard
{
  [Guid("ee59bf8b-06a4-4633-8ec6-06ad9fb1a4e2")]
  public interface IErrorCallback : IObject, IRefCountable
  {
    Status OnHvDeviation([In] HvDeviationData recordData);

    Status OnAnodeCurrentDeviation([In] DeviationTime[] recordData);

    Status OnHtDeviation([In] DeviationSeverity level);
  }
}

in Python as:

class DoErrorCallbacks(IErrorCallback):
    __namespace__ = "Filament.Standard"

    def OnHvDeviation(self, recordData):
        recordTime = recordData.timestamp
        print(f"Voltage drop begin {recordTime.day}.{recordTime.month}.{recordTime.year} {recordTime.hour}:{recordTime.minute}:{recordTime.second}.{recordTime.subseconds}")

        for seg in recordData.deviationSegments:
            if seg.category == recordData.deviationSegments.Invalid:
                break
            print(f"Category: {seg.category} Count: {seg.samplesInCategory}")

        return status.Ok

    def OnHtDeviation(self, level):
        if level == DeviationSeverity.Warning:
            print("\n-----------------------")
            print("Warning! Tube temperature reached high level.")
            print("-----------------------")
        elif level == DeviationSeverity.Critical:
            print("\n-----------------------")
            print("Error! Tube temperature reached critical level. -> Tube got disabled")
            print("-----------------------")
        return status.Ok

    def OnAnodeCurrentDeviation(self, recordData):
        recordBegin = recordData[0]
        recordEnd = recordData[1]

        print(f"\nOver current begin {recordBegin.day}.{recordBegin.month}.{recordBegin.year} {recordBegin.hour}:{recordBegin.minute}:{recordBegin.second}.{recordBegin.subseconds}")
        print(f"Over current end   {recordEnd.day}.{recordEnd.month}.{recordEnd.year} {recordEnd.hour}:{recordEnd.minute}:{recordEnd.second}.{recordEnd.subseconds}")

        return status.Ok

    def QueryInterface(self, id):
        return status.NotImplemented

I call the method:

error_callback  = DoErrorCallbacks()
self._ifilament_device.SetErrorCallback(error_callback)

and I get this error:

class DoErrorCallbacks(IErrorCallback):
TypeError: Die Methode "QueryInterface" im Typ "Filament.Standard.DoErrorCallbacks" der Assembly "Python.Runtime.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" hat keine Implementierung.

For reference:

// Assembly location: D:\Others\PROJECTS\Strahlerdauretest\NewFirmware\FilamentEnduranceTest\dlls\FiONA.dll
using System;
using System.Runtime.InteropServices;

#nullable disable
namespace Fiona
{
  [Guid("53f23da3-51f2-4804-a315-30150216905a")]
  public interface IObject : IRefCountable
  {
    Status QueryInterface(Guid interfaceId, out object o);
  }
}
// Assembly location: D:\Others\PROJECTS\Strahlerdauretest\NewFirmware\FilamentEnduranceTest\dlls\FiONA.dll
#nullable disable
namespace Fiona
{
  public interface IRefCountable
  {
    long AddRef();

    long Release();
  }
}
0

There are 0 best solutions below