Hi,
I am an automation engineer and I would like to build some troubleshooting scenarios in unity for my coworkers. I came accross a DLL Com object (on windows) Interop.S7PROSIMLib which lets you call methods and read/write in C# to the PLCSim which is great because Siemens PLC Step7 is great to write automation programs. I tested with Visual Studio and it works great.
And this is the code that calls those methods, the reference to the DLL is within the solution explorer in visual studio and thus no need to use using.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public S7PROSIMLib.S7ProSim PLCSimConn = new S7PROSIMLib.S7ProSim();
public Form1()
{
InitializeComponent();
}
private void button_Connect_Click(object sender, EventArgs e)
{
PLCSimConn.Connect();
label_CPUState.Text = PLCSimConn.GetState();
label_ScanMode.Text = PLCSimConn.GetScanMode().ToString();
}
}
}
And in a c sharp script in unity I have this:
using UnityEngine;
using System.Collections;
using S7PROSIMLib;
public class NewBehaviourScript : MonoBehaviour {
private S7PROSIMLib.S7ProSimClass ps;
// Use this for initialization
void Start () {
ps = new S7PROSIMLib.S7ProSimClass();
ps.Connect();
}
}
I cannot remember how did the DLL became Interop the original name is S7PROSIMLib, I imagine after I dragged and dropped to the assets/plugins folder. After that it was referenced in visual studio as interop.XXX and I was no longer getting the console error in unity of missing reference or using XXX in script.
I got excited when no more console errors where showing. I ran, and then I received a COMException which I have no clue where to fix or even where to begin. This is the error I get in unity something to do with Marshal.
COMException
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (Int32 errorCode) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:1031)
System.__ComObject.Initialize (System.Type t) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/__ComObject.cs:103)
(wrapper remoting-invoke-with-check) System.__ComObject:Initialize (System.Type)
Mono.Interop.ComInteropProxy.CreateProxy (System.Type t) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs:108)
System.Runtime.Remoting.RemotingServices.CreateClientProxyForComInterop (System.Type type) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs:588)
System.Runtime.Remoting.Activation.ActivationServices.CreateProxyForType (System.Type type) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Remoting.Activation/ActivationServices.cs:234)
NewBehaviourScript.Start () (at Assets/Scripts/NewBehaviourScript.cs:11)
Can anyone that has experience with this error give me some pointers. Maybe this is not doable. And this is a link to the API for S7ProSim Documentation
Side note: I went through dozens of posts, and links online for using DLL but most of the links are user created DLL’s.
Thanks for your help.