Trying to use dmxusb.dll

Post Reply
PierreF
Posts: 2
Joined: Tue Aug 21, 2018 7:18 am
Real Name: Pierre F

Hello,
I am working on a project to command dmx light via a software i am working on. I am on windows 64 and using an Open DMX. At first i tried to use the C# example on the Enttec website.
https://www.enttec.com/fr/products/prot ... n-dmx-usb/
But i had a lot of troubel, and couldn't make the light work properly, ie wrong color, delay. I have tried on windows 64 and 32 bits.
I have found QLC+, and it work flawlessly, and in looking in the source files to see how you control the light, i noticed that the program create and use dmxusb.dll.
I have tried to use it via a c# program, but i can't manage to use it, and it crash.
At first, i tried to execute a simple program to call the fonction dmxusb.init(), but I got an error System.DllNotFoundException, linked to the lack of some of the dependency of dmxusb.dll like some Qt dll.
Then i tried to execute my program from the installed qlc+ 4.11.2, and also got the same error, but QLC+ run just fine.
Finally I have tried to launch it from the installed qlc+ 5, using the qml config and the code available in the 4.11.2 source code. This time the error was SystemBadImageFormatException, which come either from a difference beetwen the software and the dll called, if they don't run on 32 or 64 bits, or from the .NET version. This happened even if i compile my program in 32 or 64 bits and I compiled both program on the same computer so the .NET version should be the same.
I was wondering if i need to do something special when linking to the dll or when using it.
I am programming on windows 64, using visual studio 2017, and in C#. I have already made some code in c# that use a c++ dll, so i know it's possible.
I know it is not directly linked to the development of QLC+, but I am stuck on trying to control the DMX lights, and if anyone could help me, I would be really grateful. If you need more informations, you just have to ask.
Thanks.

Pierre F.
janosvitok
Posts: 1326
Joined: Mon Apr 13, 2015 7:05 am
Location: Bratislava, Slovakia
Real Name: Jano Svitok
Contact:

Hi,

check the sources of DmxUsb plugin here: https://github.com/mcallegari/qlcplus/t ... dmxusb/src
You'll see that in windows it uses FTD2XX library from http://www.ftdichip.com/Drivers/D2XX.htm (the same place Enttec download page links to).

In that driver.zip you'll find ftd2xx.h, ftd2xx.lib and ftd2xx.dll (or similar names). That you should call from your c# code. The plugin is just QT/QLC+ wrapper around this dll.

https://github.com/mcallegari/qlcplus/b ... erface.cpp contains QLC+ interface to FTD2XX.
Check also the rest of the files in the directory. You don't need them all, start with enttec dmx usb open and its dependencies (parent classes, etc.)

Note that writing to serial port happens in a separate thread.


Jano
PierreF
Posts: 2
Joined: Tue Aug 21, 2018 7:18 am
Real Name: Pierre F

janosvitok wrote: Tue Aug 21, 2018 10:14 am In that driver.zip you'll find ftd2xx.h, ftd2xx.lib and ftd2xx.dll (or similar names). That you should call from your c# code. The plugin is just QT/QLC+ wrapper around this dll.
I have already tried to control the light directly throught ftd2xx.dll by using the c# exemple project. The program had different behavior depending on the computer running it, with no apparent link with the OS version, windows 7 or 10.
Either the light would have a 1 message delay, or the wrong light channel would be set apparantly at random.

That why I tried to use dmxusb.dll. I can control my lights using QLC+, so my plan was to use this dll already build and configure rather than try to make my own by removing the unnecesary protocols.
I couldn't find a difference in the configuration and use of the FTD2xx functions beetwen QLC+ and the c# example, so i don't really know what i am doing wrong with the FTD2xx functions. Especially when it is already made.
janosvitok wrote: Tue Aug 21, 2018 10:14 am Note that writing to serial port happens in a separate thread.
If i am using an Open DMX, can't I use run(), in enttecdmxusbopen.cpp?

Thanks

Pierre F.
janosvitok
Posts: 1326
Joined: Mon Apr 13, 2015 7:05 am
Location: Bratislava, Slovakia
Real Name: Jano Svitok
Contact:

Pierre,

you can't directly use the run() from enttecdmxusbopen.cpp, for several reasons:
- it needs QT, so you would need to initialize the whole QT ecosystem
- it probably is not exported from dll, so you need to compile your own version
- and surely many others

Enttec page provides you with c# library, and c# example. I quickly looked at both.
It seems that the example contains slightly modified version of the library (OpenDMX class).
Check both and find differences.

While I'm not a C# programmer (I program in C++, Java and Ruby), from the quick look
I can see some problematic places. Those are meant as skeleton/easy introduction,
but for production work the code has to be improved.

The base is that you should have a thread that will periodically output the DMX data.
The library has this, but the example does not (see writeData() with or without while).
You need to make sure the body of the loop runs every 1/44 of second no matter what happens.
QLC+ uses combination of sleep() and active loop (loop while time elapsed < desired time, with empty body).

I don't see any locking for buffer[], which may or may not be a problem.

So, go through the example and library code, find the problem and improve on it/make your own.
I think that's the easiest way to go.

If you can't find the problem in two pages of C# source code, then I wish you good luck with
debugging C++ binary code...

If you get stuck, you may post your code somewhere, and maybe I'll have quick look, but I don't promise anything.


Alternatively, if you can find a program that will convert artnet to opendmx, you can write your program to output
artnet (https://art-net.org.uk/) which is quite simple network protocol over UDP.


Jano
Post Reply