the enttec seems to be a unmanaged .dll, this is something very different from a .NET managed dll…
you access a managed .dll with DllImport in a class. the class could be anywhere in your project. so just copy this code into your plugin (inside the namespace):
code(lang=csharp):
public class OpenDMX
{
public static byte[]() buffer = new byte[511](511);
public static uint handle;
public static bool done = false;
public static int bytesWritten = 0;
public static FT_STATUS status;
public const byte BITS_8 = 8;
public const byte STOP_BITS_2 = 2;
public const byte PARITY_NONE = 0;
public const UInt16 FLOW_NONE = 0;
public const byte PURGE_RX = 1;
public const byte PURGE_TX = 2;
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_Open(UInt32 uiPort, ref uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_Close(uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_Read(uint ftHandle, IntPtr lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesReturned);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_Write(uint ftHandle, IntPtr lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesWritten);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_SetDataCharacteristics(uint ftHandle, byte uWordLength, byte uStopBits, byte uParity);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_SetFlowControl(uint ftHandle, char usFlowControl, byte uXon, byte uXoff);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_GetModemStatus(uint ftHandle, ref UInt32 lpdwModemStatus);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_Purge(uint ftHandle, UInt32 dwMask);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_ClrRts(uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_SetBreakOn(uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_SetBreakOff(uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_GetStatus(uint ftHandle, ref UInt32 lpdwAmountInRxQueue, ref UInt32 lpdwAmountInTxQueue, ref UInt32 lpdwEventStatus);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_ResetDevice(uint ftHandle);
[DllImport("FTD2XX.dll")](DllImport("FTD2XX.dll"))
public static extern FT_STATUS FT_SetDivisor(uint ftHandle, char usDivisor);
public static void start()
{
handle = 0;
status = FT_Open(0, ref handle);
Thread thread = new Thread(new ThreadStart(writeData));
thread.Start();
setDmxValue(0, 0); //Set DMX Start Code
}
public static void setDmxValue(int channel, byte value)
{
if (buffer != null)
{
buffer[channel](channel) = value;
}
}
public static void writeData()
{
while (!done)
{
initOpenDMX();
FT_SetBreakOn(handle);
FT_SetBreakOff(handle);
bytesWritten = write(handle, buffer, buffer.Length);
Thread.Sleep(25);
}
}
public static int write(uint handle, byte[]() data, int length)
{
IntPtr ptr = Marshal.AllocHGlobal((int)length);
Marshal.Copy(data, 0, ptr, (int)length);
uint bytesWritten = 0;
status = FT_Write(handle, ptr, (uint)length, ref bytesWritten);
return (int)bytesWritten;
}
public static void initOpenDMX()
{
status = FT_ResetDevice(handle);
status = FT_SetDivisor(handle, (char)12); // set baud rate
status = FT_SetDataCharacteristics(handle, BITS_8, STOP_BITS_2, PARITY_NONE);
status = FT_SetFlowControl(handle, (char)FLOW_NONE, 0, 0);
status = FT_ClrRts(handle);
status = FT_Purge(handle, PURGE_TX);
status = FT_Purge(handle, PURGE_RX);
}
}
/// <summary>
/// Enumaration containing the varios return status for the DLL functions.
/// </summary>
public enum FT_STATUS
{
FT_OK = 0,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_OTHER_ERROR
};
then add the missing uses clause on top:
code(lang=csharp):
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
and yes, in order to find the dll, it must lie besides the calling .exe, which is vvvv.exe in your case. if that doesn’t work try the bin/managed folder…