I need to show a live data on text field in C#.basically whenever a value changes, below c++ function under LTscriptenginedll.dll
ConnectLiveData(void* pCallBack, const char** pszTagNames, const int** pnTagAddress,
bool bdiscconectConnection, bool bPyRequest)
gives new value . I need to create a C# function which will call and takes value from this C++ function everytime value changes in function.I tried but so for I am still struggling.
Below is my code.
public unsafe float StartLiveInfo(string tagNameFromRequest)
{
string tagName = tagNameFromRequest;//"Motor_1.OutPut.VI";
byte[] tagNameByte = Encoding.ASCII.GetBytes(tagName);
IntPtr tagNamePtr = Marshal.UnsafeAddrOfPinnedArrayElement(tagNameByte, 0);
IntPtr[] tagNameIntPtr = new IntPtr[2];
tagNameIntPtr[0] = tagNamePtr;
tagNameIntPtr[1] = IntPtr.Zero;
int tagValueTemp = 0;
int*[] tagValuePtr = new int*[2];
tagValuePtr[0] = &tagValueTemp;
tagValuePtr[1] = null;
float test;
fixed (int** tagValue1 = tagValuePtr)
{
fixed (IntPtr* tagName1 = tagNameIntPtr)
{
try
{
myCallBackPtr obj = new myCallBackPtr(CallMethod);
int finalTagValue = ConnectLiveData(obj, tagName1, tagValue1,false,true);
test = Convert.ToSingle(*tagValue1[0]);
return test;
}
catch (Exception ex)
{
return 0;
}
}
}
}
This is how I have called dll function and using delegate.
public delegate void myCallBackPtr();
[DllImport("LTscriptenginedll.dll")]
public static extern unsafe int ConnectLiveData(myCallBackPtr ps,IntPtr* test, int** temp,bool bdiscconectConnection, bool bPyRequest);
Here is callMethod
public static void CallMethod()
{
Console.WriteLine("callbackcalled");
}
I am calling this StartLiveInfo function from main.aspx on buttonclick event and showing return value in text field.
below it the code:
protected void Button1_Click(object sender, EventArgs e)
{
float retValue = oraDal.StartLiveInfo("M1.Speed");
TextBox1.Text = Convert.ToString(retValue);
}