How to use python callback function to get return string values from a C# Dll method

36 Views Asked by At

Below is the working C# code, here 'RegistrationCallbackFunction' method is called with 2 arguments

  1. LFSDLL.LFSInterface.LFS_CB_DLT_LOG_VIEW // To enable Log view
  2. DltLogViewCB // Callback function to read back 2 string variables key & data

C# code:

private void buttonDltLogOn_Click(object sender, EventArgs e)
{
    trace($"Callback Set - dlt log view");
    LFSDLL.LFSInterface.RegistrationCallbackFunction(LFSDLL.LFSInterface.LFS_CB_DLT_LOG_VIEW, DltLogViewCB);
    bool result = LFSDLL.LFSInterface.SendCommand(LFSDLL.LFSInterface.LFS_CMD_DLT_LOG_VIEW_ON);
    trace($"Send Result = {result}");
}
        
public async void DltLogViewCB(string key, string data)
{
    trace($"Callback Result = {key} : {data}");
}

Python code:

import clr 
from types import *
from System import Action
clr.AddReference(r"LFSInterface")    # LFSInterface is the Dll
from LFSDLL import LFSInterface
LFSota = LFSInterface()
LFSota.SendCommand(LFSota.LFS_CMD_APP_START)   # Working fine from Py
LFSota.SendCommand(LFSota.LFS_CMD_DLT_LOG_VIEW_ON)  #Working from Py

LFSota.RegistrationCallbackFunction(LFSota.LFS_CB_DLT_LOG_VIEW, DltLogViewCB ) # Error statement

I am trying to use a C# Dll in my Python code. I referred working C# code sample to create python script

Problem

Not sure how to use a callback function in python similar to C# to get back the key&data string values from the DLL

LFSota.RegistrationCallbackFunction(LFSota.LFS_CB_DLT_LOG_VIEW,(DltLogViewCB) )

TypeError: No method matches given arguments for LFSInterface.RegistrationCallbackFunction: (<class 'str'>, <class 'function'>)

Thank you

0

There are 0 best solutions below