[英]how to reference entry point in an external dll (C# / unity 3D)
I am using Unity 3D for an application I need to use Serial Port but in Unity, there's a missing implementation of event DataReceived
and others linked functions. 我正在为需要使用串行端口的应用程序使用Unity 3D,但是在Unity中,缺少事件
DataReceived
和其他链接函数的实现。 Therefore I think the solution is to make my own DLL that can manage Serial Port data and call it from unity as an external DLL. 因此,我认为解决方案是使自己的DLL可以管理串行端口数据,并作为一个外部DLL统一调用它。
I wrote the code below. 我写了下面的代码。 the code in my class library project (just a serial port froze opening for the test)
我的类库项目中的代码(只是为测试冻结了一个串行端口)
Code: 码:
using System;
using System.IO.Ports;
namespace serialPortManager2
{
public class laserManager
{
private SerialPort laserComPort;
public bool open()
{
bool laserSerialPortDetected = false;
// ouverture du port série pour pilotage du laser
foreach (string portName in SerialPort.GetPortNames())
{
if (portName == "COM4") laserSerialPortDetected = true;
}
if (laserSerialPortDetected)
{
laserComPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
laserComPort.Open();
if (laserComPort.IsOpen)
{
// timeout de lecture d'une mesure laser
laserComPort.ReadTimeout = 5000;
return true;
}
else return false;
}
else return false;
}
}
}
Code to reference DLL in Unity: 在Unity中引用DLL的代码:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public static class SPNativePlugIn {
// The name of the external library containing the native functions
private const string LIBRARY_NAME = "serialPortManager2";
[DllImport(LIBRARY_NAME)] public static extern bool open();
}
My problem is that I get this error: EntryPointNotFoundException: open
我的问题是出现此错误:
EntryPointNotFoundException: open
I guess I have to integrate the laserManager
class somewhere but I do not know the syntax, I tried quite a few things but I can not find it. 我想我必须在某个地方集成
laserManager
类,但是我不知道语法,我尝试了很多事情,但找不到。
Create a folder named "Plugins" in the "Assets" Folder then put your .dll file in the "Plugins" folder and import it in your script in this way using dllFileName;
在“ Assets”文件夹中创建一个名为“ Plugins”的文件夹,然后将您的.dll文件放入“ Plugins”文件夹中,并
using dllFileName;
以此方式将其导入脚本中using dllFileName;
This works for every .dll not include in the unity default library 适用于未包含在统一默认库中的每个.dll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.