WonderWare ArchestrA Script Function Library

xzy1023

Member
Join Date
Apr 2013
Location
Toronto
Posts
7
I am trying to use lots same scripts in the ArchestrA IDE, so I decide to develop Custom Script Functions in Visual Studio for AppServer. I know the IDE is able to import the "dll" library fill. But I have no clue where to start.

Let me start with simple AddFunction() on .Net 4.5 Framework in Visual Studio using C# code.
Here is the code:

namespace Demo
{
public class DemoClass
{
public int GetAdd(int a, int b)
{
return a + b;
}
}
}

After I import the dll to IDE, I am able to see the function in the Function Browser. But when I am trying to use it in the script, it shows the "Unknow Method" fault. Anyone have thoughts about that?

Snipaste_2018-02-17_19-38-34.png Snipaste_2018-02-17_19-37-37.png Snipaste_2018-02-17_19-48-40.jpg
 
Last edited:
Still not working.
When I use the system function the intellisense pop up, but not the MyFunction().
When I move the mouse to the fuction, system indicate the Unknown Method.

Snipaste_2018-02-17_20-48-32.png snipaste_20180217_204950.png
 
Hmm, I did this a couple of years ago but would have to hunt it down.
It might be that you have to declare a variable as your class, then run the function (getAdd..?)
That is the way a lot of dotNet functions work in SP
 
No worries, glad I could be of help & you got it working.!!
Something to be aware of is updating our functions, I can’t quite recall but did have some issues I think..
 
I'm also wanting add a custom dll to System Platform. I started another thread before finding this one.

Mine is a little more complicated as I'm trying to add the Windows.From into the dll.

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WinFormsLibrary1
{
public class ResizableForm
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();

public Form GetCurrentWindow()
{
IntPtr activeWindowHandle = GetForegroundWindow();
Form f = Control.FromHandle(activeWindowHandle) as Form;
return f;
}
}
}


If I follow what is in this thread as a test using Visual Studio 2019 and the Class Library (.Net Framework) - C# template, I get a dll and can import it into System Platform, as posted above I can then find the function in the Function Browser but nothing happens in runtime when the script is run and I get this error in the SMC log:
Script execution exception.Message: Non-static method requires a target..
System.Reflection.TargetException: Non-static method requires a target.

I also had to change the System Platform script a little as it seems the DLL code listed in the OP uses GetAdd for the function name but the last pic uses just "Add".

dim cls as demo.DemoClass;
Me.intTest = cls.GetAdd(2,3);
 
Last edited:
I got the example in the first post to work but only after making the class and int static in Visual Stuido.

Like "static public class DemoClass" and "static public int GetAdd(int a, int b)"

But the DIM in the System Platform script no longer works.

So this works: Me.intTest = demo.DemoClass.GetAdd( 2, 3 );

But this has an error saying cls has no GetAdd function.

dim cls as demo.DemoClass;
Me.intTest = cls.GetAdd(2,3);

So is there a way to get System Platform to work with the original script or did they make some new requirement that code in the DLLs must be static? Would not think so but what am I doing wrong?
 
Last edited:
Ok, if I remove the static settings and put it back the System Platform script will work if I add this object = new line, "cls = new ClassLibraryDemo.DemoClass();"

dim cls as demo.DemoClass;
cls = new ClassLibraryDemo.DemoClass()
Me.intTest = cls.GetAdd(2,3);

I'm not sure what has changed or how the OP got it working without it.

Unfortunately, the resize code that I need still has the Non-static error and it already has the object equals new line.

Dim myLib As WinFormsLibrary1.ResizableForm;
Dim myGfc As System.Windows.Forms.Form;

myLib = new WinFormsLibrary1.ResizableForm();
myGfc = myLib.GetCurrentWindow();

myGfc.Width = 10;
myGfc.Height = 10;
 
Last edited:

Similar Topics

Hey I was needing help with some alarm scripting in Woderware System Platform. What would be the best way to write a script to auto acknowledge...
Replies
2
Views
2,487
Hi, I am trying to use Script function Library. I used Visual Studio to write the C# dll i will import in Archestra. So I import my dll...
Replies
1
Views
2,561
Anyone have any new stories with a .net script? I'm trying to grasp my capabilities as far as what I can call out from the windows system. Am I...
Replies
1
Views
1,266
Hi ! im having some trouble with the following code.. ------------------------------------------------------------------------ dim sr as...
Replies
3
Views
2,890
Hello guys I need a help from you all to complete my assignment I have more than 1000 tags in my project Now I have to make cause and effect chart...
Replies
0
Views
3,476
Back
Top Bottom