K8062 32bit and 64bit dll

Currently I’m writing a presentation program that will support DMX output. For example to create amblight from the playing video.
I’m supporting a serveral dmx interface, and would like to support the Velleman DMX kit as well. The program is written in C#, and currently support all CPU types 32bits as well 64 bits.
To continue the support of running in 64bit mode, all DLL’s must also run in 64 bit mode.
Is there or will be there a 64bit dll of the ‘K8062D.dll’ dll that I can imported into my project? I’ve al ready looked into the DLL source that you supplied, but I’m not able to build a DLL from that source. (Which compiler is used to build the dll?) Also I’ve found a V3 in the forums, but not on the product page, which version is recommend to used?

I’m sorry, the 64bit version of the K8062D.DLL is not available.
The K8062e.exe is using third party 32bit timer unit FASTTime32.dll.

If you anyhow like to try to use the software, I recommend to use the version 3.
Here you can download it with Delphi source code and a demo:
app.box.com/s/uyb5p4zyxdo1q4mlegiy

Thanks for the reply.

I’ve found the DLL source of the ‘version 2’ on the product page, and found that the DLL only don’t do much. It only pass the data through a virtual memory mapping to K8062D.exe, which will use the FASTTime32.dll. The DLL starts a new process (the K8062D.exe file) which is 32 bit, but it is a different process. Is this correct?

If so, and you would like, I can write a managed DLL of the ‘K8062D.dll’, that will support 32 bit and 64 bit. It start the process (K8062, as 32 bit process), and will communicate trough the virtual memory mapping. Because the processes are separated the management version can run in 64bit mode.

The only thing: I can’t test if this is going to work, because I haven’t the kit at home. And to buy the kit only to support your device is a quite bit expensive. Is it possible that we make some arrangement that I provide you the .Net version of the K8062D.dll (with all the source code to compile) which running in 32bit and 64 bit mode. And you provide me with this kit, so I’m able to test and debug the dll.

Now the 64-bit DLL for the K8062 is ready.
Thank you for all the info and the effort.
You are right - there is no need to have the K8062e.exe and FASTTime32.dll as 64-bit.
Only the simple K8062D.dll has to be 64-bit to be used with 64-bit applications.
Now this is done.
Here you can download the 64-bit version of the K8062D.dll with source code:
app.box.com/s/mpallm7fqlray9yleoq1
There in the package are also two 64-bit demo software using this new 64-bit DLL - they are also with source code.

Thanks :slight_smile:

Yester day I have created a managed version, but don’t know if this is working. Can you try this for me. The benefits for my to use the managed version above the native is that I don’t need to deliver 2dll and check for 64 / 32 bit running.

The program is simple, it open the device, set the channel count to 24, and changes the value of the first 3 channels.
The program can by downloaded from: gerritenmarian.nl/www/Velleman.Dmx.zip

Also some questions:

  • How can I check if the device is connected? What is the address of the memory file where this value is setted by the .exe file? (v2 hasn’t this property)
  • The address of the first channel is 44 ( (channel + 10) * 4 ), is this corrent?

Thanks in advance

The c# code for now:


using System;
using System.Diagnostics;
using System.IO.MemoryMappedFiles;

namespace Velleman.Dmx
{
    public class Controller : IDisposable
    {

        #region Constants

        const string VIRTUALFILENAME = "ShareK8062Data";
        const int DATASIZE = 2500;
        const int CHANNEL_OFFSET = 10;

        #endregion

        #region Fields

        readonly MemoryMappedFile memoryMappedFile;
        readonly MemoryMappedViewAccessor accessor;
        Process process;

        #endregion

        #region Properties

        public bool IsConnected
        {
            get
            {
                return GetShareData(0) == 123;
            }
        }

        #endregion

        #region Constructor and Dispose
 
        public Controller()
        {
            memoryMappedFile = MemoryMappedFile.CreateOrOpen(VIRTUALFILENAME, DATASIZE, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, null, System.IO.HandleInheritability.Inheritable);
            accessor = memoryMappedFile.CreateViewAccessor(0, DATASIZE);
        }

        public void Dispose()
        {
            accessor.Dispose();
            memoryMappedFile.Dispose();

            // If process is still alive, kill it
            if (process != null && !process.HasExited)
                process.Kill();
        }

        #endregion

        public void StartDevice()
        {
            SetShareData(1, 222);
            process = Process.Start("K8062e.exe");
        }

        public void StopDevice()
        {
            SetShareData(0, 333);
        }

        public void SetChannel(short channel, byte value)
        {
            if (channel <= 0 || channel > 512)
                throw new ArgumentOutOfRangeException("Parameter 'channel' must be greather then 0 and less then or equal to 512");
            SetShareData(channel + CHANNEL_OFFSET, (int)value);
        }

        public void SetChannelCount(short channels)
        {
            if (channels <= 0 || channels > 512)
                throw new ArgumentOutOfRangeException("Parameter 'channels' must be greather then 0 and less then or equal to 512");
            SetShareData(2, (int)channels);
        }

        #region Private methods to read and write the data

        byte[] ReadAllData()
        {
            byte[] buffer = new byte[DATASIZE];
            for (int i = 0; i < buffer.Length; i++)
                buffer[i] = accessor.ReadByte(i);
            return buffer;
        }

        void SetShareData(int address, int data)
        {
            address *= sizeof(int);
            accessor.Write(address, data);
        }

        int GetShareData(int address)
        {
            address *= sizeof(int);
            return accessor.ReadInt32(address);
        }

        #endregion

    }
}

Your code Velleman.Dmx.exe seems to work fine!

[quote]- How can I check if the device is connected? What is the address of the memory file where this value is setted by the .exe file? (v2 hasn’t this property)[/quote] It seems to be 600*4 in bytes:function Connected: Boolean; stdcall; begin if GetShareData(600)=198 then result:=true else result:=false; end;

[quote]- The address of the first channel is 44 ( (channel + 10) * 4 ), is this corrent?[/quote]Yes, in bytes it is 44:[code]PROCEDURE SetData(Channel: Longint ; Data: Longint); stdcall;
begin
if channel>0 then SetShareData(Channel+10,Data);
end;

PROCEDURE SetAllData(DataArray: Pointer); stdcall;
var p:^longint;
i:integer;
begin
p:=DataArray;
for i:=11 to 521 do
begin
SetShareData(i,p^);
inc§;
end;
end;[/code]
Here a snippet of the 64-bit DLL source code:[code]procedure StartDevice; stdcall;
var h:integer;
begin
SetShareData(1,222);
h := WinExec(‘K8062E.exe’, SW_RESTORE);
// If the function succeeds, the return value is greater than 31
end;

procedure StopDevice; stdcall;
begin
SetShareData(0,333);
end;

function Connected: Boolean; stdcall;
begin
if GetShareData(600)=198 then
result:=true else result:=false;
end;

PROCEDURE SetChannelCount(Count: Longint); stdcall;
begin
if Count>0 then SetShareData(2,Count);
end;

PROCEDURE SetData(Channel: Longint ; Data: Longint); stdcall;
begin
if channel>0 then SetShareData(Channel+10,Data);
end;

PROCEDURE SetAllData(DataArray: Pointer); stdcall;
var p:^longint;
i:integer;
begin
p:=DataArray;
for i:=11 to 521 do
begin
SetShareData(i,p^);
inc§;
end;
end;

procedure SetShareData (address,data: Longint);
var p:^longint;
begin
p:= MapViewOfFile (hMapFile, File_Map_Write, 0, 0, DataSize);
// p:=ShareData;
inc(p,address);
p^:=data;
end;

function GetShareData (Address:Longint): Longint; stdcall;
var p:^longint;
begin
p:= MapViewOfFile (hMapFile, File_Map_Write, 0, 0, DataSize);
// p:=ShareData;
inc(p,Address);
Result:=p^;
end;[/code]

Thanks, I’ve put it all together in a library. Download link for the source and dll: gerritenmarian.nl/www/Velleman.K8062D.zip.

I can’t host this file for ever, so if possible, can you download this file, and make a more ‘stable’ download link? So more people can use this library.
Or add it to the product page. Fill free to use it!

Thank you very much!
I’ll test your code and provide the second download link.

I quickly noticed the DLL is not standard Windows DLL but .NET framework assembly - right?
So this DLL can be used only with Microsoft Visual Studio projects…

I made a simple C# project and got the DLL ‘linked’ to it as a reference and got it working too.

Here’s the code. I think not the best one as a programming example though… :)[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Velleman.K8062D;

namespace K8062Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    Controller myvel = new Velleman.K8062D.Controller();
  
    private void button1_Click(object sender, EventArgs e)
    {
        myvel.StartDevice();
        myvel.SetChannelCount(8);
    }


    private void button2_Click(object sender, EventArgs e)
    {
        myvel.StopDevice();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        if (myvel.IsConnected)
            label1.Text = "Yes";
        else
            label1.Text = "No";            
    }

    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        myvel.SetChannel(1, (byte)trackBar1.Value);
        label2.Text = trackBar1.Value.ToString();
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
         myvel.StopDevice();
    }
}

}[/code]

Yes, that is correct. I’m a .Net C# developer, so the written Velleman.K8062D.DLL is also a .Net DLL :). Because the ‘K8062e’ file works with MemoryMapping, a .Net dll was easy to write for it. As benefit the .Net DLL support Any CPU type, so it does not matter anymore if the program run as 64bit or as 32bit. And you don’t need an extra dll (or 2 with 64bit support).

I would rather say: ‘This DLL can be used only in a .Net runtime environment.’ Because the DLL supports also Mono Projects, there are also many bridges to use .Net in an Java environment (eample: php.net/manual/en/class.dotnet.php).

Note: I’ve a small issues in the dll source code with the method SetData. (Currently throws an exception when you use SetData)
This method will send the given buffer to their channels, but the current method will use 0 as channel address, and that is not possible. There are 2 fixes for it, but don’t know how the native DLL works. A byte array of 513 bytes and skipping the first (Solution A). Or a byte array of 512 bytes and add a number for the channel (Solution B).

Solution A

        public void SetData(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            if (data.Length > 513)
                throw new ArgumentOutOfRangeException("Can't send more data then 512 values");

            for (short i = 1; i < data.Length; i++)
                SetChannel(i, data[i]);
        }

Solution B

        public void SetData(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            if (data.Length > 512)
                throw new ArgumentOutOfRangeException("Can't send more data then 512 values");

            for (short i = 0; i < data.Length; i++)
                SetChannel(i + 1, data[i]);
        }

Thank you for the info.

About the SetData issue:
I tested your solution B. This works fine:[code] public void SetData(byte[] data)
{
if (data == null)
throw new ArgumentNullException(“data”);
if (data.Length > 512)
throw new ArgumentOutOfRangeException(“Can’t send more data then 512 values”);

        for (short i = 0; i < data.Length; i++)
            SetChannel(i+1, data[i]);
    }[/code]

Example usage in the application software: private void button4_Click(object sender, EventArgs e) { byte[] DataBuffer = new byte[512]; for (int i = 0; i < 100; i++) { DataBuffer[i] = 0x55; } myvel.SetData(DataBuffer); }

The beginning of the resulting DMX signal as an oscilloscope screenshot:

I have the same requirements as Gerrit, so I therefore tested the code he wrote.

However, it seems that you can only set the first 8 channels with his code. What am I missing?

I could really appreciate some help here.

Thanks,

Jim

Is there an exception when you set the 9th channel? Or is the code accepting the value, but there is no response (a lamp / dimmer) on that channel?

Have you some example code on calling the SetData method? (Like the example of VEL255).

Note: When you downloaded the version from the gerritenmarian host, the SetDate method must be replaced with Solution B in my latest post.

Hi
I have a question on this topic:
Because the DLL from Gerrit isnt available anymore, I use the dll that comes from velleman (found at app.box.com/s/uyb5p4zyxdo1q4mlegiy).

That works good, but the checking of the connection state doesnt work. I am a VB.net Developer and declare the Conneted state like this:

When I check the connection once (the Interface is connected via USB, but not yet with the software) , it returns the value FALSE which is correct and like I wanted and expected it. When I connect now the Interface , it returns the value TRUE, which is also okay. But when I now disconnect the interface via software (USB still connected) it returns also TRUE wich isnt what I want. I want to know if the software is conneted with the interface (StartDevice / StopDevice), and not if the interface is connected with the USB Port.
Is that possible?
And also: Is Gerrits DLL available somewhere?
I hope you can help me.

[quote]I want to know if the software is conneted with the interface (StartDevice / StopDevice), and not if the interface is connected with the USB Port.
Is that possible?[/quote]I’m sorry, this is not possible with the current software and DLL version.