Are there any functions available in K8062.dll that I can use to detect if a K8062 is currently connected to a USB port? Is there are way to detect and distinguish multiple K8062’s connected?
[quote]Are there any functions available in K8062.dll that I can use to detect if a K8062 is currently connected to a USB port? [/quote]No - at the moment there is no feedback functions. It is possible to add such a function. I’ll inform when ready to download…
[quote]Is there are way to detect and distinguish multiple K8062’s connected?[/quote]There is no addressing possibility in the K8062 hardware. Only one unit per PC is possible.
Now the K8062d.dll and K8062e.exe are modified.
Function added:
bool Connected()
Here a link to download the files: box.net/shared/2l0b2tk8e1
The USB connection of the K8062 card is detected in the K8062e.exe program.
Calling the StartDevice() starts this program.
When running, you can check if the hardware is connected by calling the function Connected().
Here an example code how to use this function:
[code]#include
#include <windows.h>
#include
typedef void (__stdcall *PFNSTARTDEVICE)();
typedef void (__stdcall *PFNSETDATA)(DWORD dwChannel, DWORD dwData);
typedef void (__stdcall *PFNSETCHANNEL)(DWORD dwCount);
typedef void (__stdcall *PFNSTOPDEVICE)();
typedef bool (__stdcall *PFNCONNECTED)();
// Definitions:
PFNSTARTDEVICE StartDevice;
PFNSETDATA SetData;
PFNSETCHANNEL SetChannelCount;
PFNSTOPDEVICE StopDevice;
PFNCONNECTED Connected;
HINSTANCE m_hK8062dDLL;
int init();
using namespace std;
int main(int)
{
if (!init())
{
StartDevice();
if (Connected())
{
cout << “K8062 Connected - Press Enter to continue” << endl;
cin.get();
SetChannelCount(32);
SetData(2, 250);
cout << “Press Enter to “StopDevice” and “FreeLibrary”” << endl;
cin.get();
}
else
{
cout << “K8062 Not Connected” << endl;
cout << “Press Enter to “StopDevice” and “FreeLibrary”” << endl;
cin.get();
}
StopDevice();
FreeLibrary(m_hK8062dDLL);
}
return EXIT_SUCCESS;
}
int init()
{
// Loading DLL
m_hK8062dDLL = LoadLibrary(“k8062d.dll”);
if (m_hK8062dDLL != NULL)
{
// DLL function assignments
StartDevice = (PFNSTARTDEVICE)GetProcAddress(m_hK8062dDLL, “StartDevice”);
SetData = (PFNSETDATA)GetProcAddress(m_hK8062dDLL, “SetData”);
SetChannelCount = (PFNSETCHANNEL)GetProcAddress(m_hK8062dDLL, “SetChannelCount”);
StopDevice = (PFNSTOPDEVICE)GetProcAddress(m_hK8062dDLL, “StopDevice”);
Connected = (PFNCONNECTED)GetProcAddress(m_hK8062dDLL, “Connected”);
return 0;
}
return -1; // Error to load DLL
}[/code]
I’m developing a application for the K8062 in C#/.NET. With the sdk supplied dll it all works fine. But the connected function in this topic would really be nice in my application. The problem is that when I replace the K8062D.dll and K8062e.exe I get a ArithmeticException. Anyone has any idea why? And other people have this new version of the dll/exe working?
Please paste your C# code here.
[code]using System.Runtime.InteropServices;
namespace WakeUpLight
{
class CDMX
{
[DllImport(“K8062D.dll”)]
public static extern void StartDevice();
[DllImport("K8062D.dll")]
public static extern void StopDevice();
[DllImport("K8062D.dll")]
public static extern void SetData(int channel, int data);
[DllImport("K8062D.dll")]
public static extern void SetChannelCount(int count);
}
}
[/code]
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
CDMX.StartDevice();
CDMX.SetChannelCount(8);
CDMX.SetData(3, 100);
CDMX.SetData(4, 100);
CDMX.SetData(5, 100);
CDMX.SetData(6, 100);
CDMX.SetData(7, 100);
}
~Window1()
{
CDMX.StopDevice();
}
}
I don’t think it’s in my C# code. The code works with the original dll.
I made a test with the new K8062e.exe and k8062d.dll put to the \bin\Debug folder of the project.
Works also if the files are put to the System32 folder (in 32 bit environment).
This is the code:
[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 System.Runtime.InteropServices;
namespace K8062Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class CDMX
{
[DllImport("K8062D.dll")]
public static extern void StartDevice();
[DllImport("K8062D.dll")]
public static extern void StopDevice();
[DllImport("K8062D.dll")]
public static extern void SetData(int channel, int data);
[DllImport("K8062D.dll")]
public static extern void SetChannelCount(int count);
[DllImport("K8062D.dll")]
public static extern bool Connected();
}
private void button1_Click(object sender, EventArgs e)
{
CDMX.StartDevice();
CDMX.SetChannelCount(8);
CDMX.SetData(3, 100);
CDMX.SetData(4, 100);
CDMX.SetData(5, 100);
CDMX.SetData(6, 100);
CDMX.SetData(7, 100);
}
private void button2_Click(object sender, EventArgs e)
{
CDMX.StopDevice();
}
private void button3_Click(object sender, EventArgs e)
{
if (CDMX.Connected())
label1.Text = "Yes";
else
label1.Text = "No";
}
}
}[/code]
Thanks for the response. I will create a new project and use your code and check if it works.
Btw, What happens if you have a k8062d.dll in both the \bin\Debug folder and in your System32 folder? Does he take the on in \bin\Debug or the one in System32?
Seems to search first in the \bin\Debug folder and then in System32 folder.
When I create a new application and I use your code it all seems to work. So, thanks for the response.
OK. But still strange why you got the “ArithmeticException” error message with the new DLL but not with the old one…
When I compaired the working and the not working application I found out that my application was made with WPF and your application was created with Windows Forms. Don’t know why that is a problemen.
As a test I created a WPF application.
This is not similar as yours.
This seems to work too:
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
namespace WpfApplication1
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
class CDMX
{
[DllImport(“K8062D.dll”)]
public static extern void StartDevice();
[DllImport("K8062D.dll")]
public static extern void StopDevice();
[DllImport("K8062D.dll")]
public static extern void SetData(int channel, int data);
[DllImport("K8062D.dll")]
public static extern void SetChannelCount(int count);
[DllImport("K8062D.dll")]
public static extern bool Connected();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
CDMX.StartDevice();
CDMX.SetChannelCount(8);
CDMX.SetData(3, 100);
CDMX.SetData(4, 100);
CDMX.SetData(5, 100);
CDMX.SetData(6, 100);
CDMX.SetData(7, 100);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
CDMX.StopDevice();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
if (CDMX.Connected())
label1.Content = "Yes";
else
label1.Content = "No";
}
}
}[/code]
You are right. That code works. So it’s not wpf that’s the problem here.
I made some changes to your code and I reproduced the exception. The only thing I changed is that I call some of the dmx functions directly from the constructor.
Can you try this code?
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DmxTestApplication2
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
CDMX.StartDevice();
if (CDMX.Connected())
label1.Content = "Yes";
else
label1.Content = "No";
CDMX.StopDevice();
}
class CDMX
{
[DllImport("K8062D.dll")]
public static extern void StartDevice();
[DllImport("K8062D.dll")]
public static extern void StopDevice();
[DllImport("K8062D.dll")]
public static extern void SetData(int channel, int data);
[DllImport("K8062D.dll")]
public static extern void SetChannelCount(int count);
[DllImport("K8062D.dll")]
public static extern bool Connected();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
CDMX.StartDevice();
CDMX.SetChannelCount(8);
CDMX.SetData(3, 100);
CDMX.SetData(4, 100);
CDMX.SetData(5, 100);
CDMX.SetData(6, 100);
CDMX.SetData(7, 100);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
CDMX.StopDevice();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
if (CDMX.Connected())
label1.Content = "Yes";
else
label1.Content = "No";
}
}
}
[/code]
By doing this I got similar “ArithmeticException” error message as you are getting.
This is strange problem.
The difference between the working DLL and the non-working DLL is that the non-working one was compiled with an older Delphi version.
Now the problem is fixed by recompiling the DLL with the newer Delphi version.
Here is a link to download the updated DLL: box.net/shared/2l0b2tk8e1
Thank you for your comment!
Nice work.
I’m going to test the new dll when I get home from work. Will post my findings of course.
As far as I can see now, the dll works without problems. No more ArithmeticException.
Thanks a lot for the support!
Great, that there is an update.
…but why it isn’t included on official product page?