K8062 dll in C#

Hi

I am currently trying use the dll provided for the K8062 in C# however i am getting no output signal from the program.

I have tested the box and it is fully functional with the tester C++ program and it is therfore definatly not a hardware fault.

I have tried adding the dll to the system32 folder as suggested in another thread with no effect (it can see the dll and i do not get any error messages when the program runs).

Computer is running vista

CODE:-
Declaration of dll

[code]public class DMXDLL
{
[DllImport(“K8062D.dll”)]
public extern static int StartDevice();

    [DllImport("K8062D.dll")]
    public extern static void SetData(int Channel, int Data);

    [DllImport("K8062D.dll")]
    public extern static void StopDevice();

    [DllImport("K8062D.dll")]
    public extern static void SetChannelCount(int Count);
}[/code]

Start Device

private void Form1_Load(object sender, EventArgs e) { int deviceNo = DMXDLL.StartDevice(); }

And on click of a button

DMXDLL.SetChannelCount(8);
DMXDLL.SetData(3, 245);

Can anyone see anything blindingly obvious i have missed?

Thank you for your time in advance.

I think your code is OK.
You have to put the K8062e.exe to the same folder where the K8062D.DLL is.

Hi thanks for the prompt responce i have since fixed the problem.

turns out the lamp was responding however because i was not calling the stopdevice function on exiting it was jamming the device open preventing it from working.

I can post an example if anyone else would find it usefull

Once again thanks for the help, very much appriciated :slight_smile:

Also the FASTTime32.dll must be in the same folder together with the k8062d.dll and k8062e.exe.
If everything works OK it is there…
BTW: The function StartDevice() doesn’t return anything.

public extern static void StartDevice(); 

Seems to work also with ‘int’ anyhow…

Hi,
I’m experiencing problems in using this K8062 dll in a C# program.
I have successfully imported the dll, and compiled the project. I don’t get any errors while executing the program. When calling StartDevice() i get the red leds blinking, and when calling CloseDevice() it stops…But when calling SetData(1,200) i don’t get the light on…
I have these files in my working library: K80623.exe, K8062D.dll, FASTTime32.dll.
When using the DMX Demo the controller works perfect (using the same address).
I would appreciate any useful help!
Thanks,
Aviad.
This is my code:

        [DllImport("K8062D.dll")]
        public extern static void StartDevice();
        [DllImport("K8062D.dll")]
        public extern static void SetData(long Channel, long Data);
       [DllImport("K8062D.dll")]
        public static extern void StopDevice();
       [DllImport("K8062D.dll")]
        public extern static void SetChannelCount(long Count);

        static void Main(string[] args)
        {

          // StopDevice();
           StartDevice();
           
           SetChannelCount(8);
           SetData(1, 200);
           StopDevice(); 
        }

Mind your basic data types (long is not identical to int)

msdn.microsoft.com/en-us/library … 90%29.aspx

byte/sbyte = 1 byte = 8 bits
short/ushort = 2 bytes = 16 bits
int/uint = 4 bytes = 32 bits
long/ulong = 8 bytes = 64 bits

The DLL uses 32-bit integers.

So not only will your program not work, your program will probably crash randomly after a while because the stack gets corrupted.

It works now.
I thought it should be long because the functions are declared like this in the header file:
FUNCTION __stdcall StartDevice();
FUNCTION __stdcall SetData(long Channel, long Data);
FUNCTION __stdcall SetChannelCount(long Count);
FUNCTION __stdcall StopDevice();

How could i know that it should be int and not as declared in the header?

Anyway, thanks for the the help!
Aviad

Indeed, there is big confusion between the “long” and “int” or “integer”.
Here are the function declarations for Visual Basic 6

Private Declare Sub StartDevice Lib "k8062d.dll" () Private Declare Sub SetData Lib "k8062d.dll" (ByVal Channel As Long, ByVal Data As Long) Private Declare Sub SetChannelCount Lib "k8062d.dll" (ByVal Count As Long) Private Declare Sub StopDevice Lib "k8062d.dll" ()
Here are the function declarations for Visual Basic 2008:

Private Declare Sub StartDevice Lib "k8062d.dll" () Private Declare Sub SetData Lib "k8062d.dll" (ByVal Channel As Integer, ByVal Data As Integer) Private Declare Sub SetChannelCount Lib "k8062d.dll" (ByVal Count As Integer) Private Declare Sub StopDevice Lib "k8062d.dll" ()
Here are the function declarations for the Borland C++Builder:

FUNCTION __stdcall StartDevice(); FUNCTION __stdcall SetData(long Channel, long Data); FUNCTION __stdcall SetChannelCount(long Count); FUNCTION __stdcall StopDevice();
This is quite confusing indeed…

True, if you’re not told what basic data type is expected (WORD, DWORD, …) it takes a bit of research to find out. The golden rule is that most dll’s use 32-bit integers as parameters. So to be sure check the data types for the programming language that you are using and select one that is 32-bits wide.

In C/C++ int and long are identical (both 32-bit integers)
In C# int is smaller than long (32-bit, 64-bit)
In Visual Basic 6.0 an Integer is 16-bit, and Long is 32-bit
In Visual Basic .NET an Integer is 32-bit and a Long is 64-bit

The difference between Visual Basic 6 and Visual Basic .NET stems from history. Visual Basic 6.0 was devised in the age when 16-bit was still common (VB6 is quite old). Nowadays the situation is the same for 32-bit/64-bit.