K8061 DLL not compatible with .net Microsoft Charts

Hi all,
i’ve developed an application with K8061 in C#. It seems that DLL is not compatible with Microsoft Charts components.
Just for a test i’ve reduced application to a simple call to OpenDevice and an Emply Charts.
As soon as OpenDevice is called application quit with this error:
The program ‘[3292] Thermostate.vshost.exe: Managed’ has exited with code -1073741819 (0xc0000005).

Obviously as soon as one component (board initialization or Chart) is removed application runs fine.
Any suggestion?

This is k8061.cs lib:
[i]using System;
using System.Runtime.InteropServices;
namespace Thermostate
{
///


/// Summary description for k8061.
///

public class k8061
{
/*
Result
Longint: If succeeded the return value will be the card address read from the K8061 hardware. The
card address is value between 0 and 7 which corresponds to the jumper (A1, A2, A3) setting on the
K8061 card. Use this value in the next function calls to access this card.
If more K8061 cards are connected to the PC, repeat this function call until all the cards are opened.
Return value -1 indicates that all K8061 cards are opened.
Return value -2 indicates that no card was found.
/
[DllImport(“k8061.dll”)]
public static extern int OpenDevice();
/

Description
Unloads the communication routines for K8061 cards and unloads the driver needed to communicate
via the USB port. This is the last action of the application program before termination.
*/
[DllImport(“k8061.dll”)]
public static extern void CloseDevices();

	[DllImport("k8061.dll")]
	public static extern int ReadAnalogChannel(int CardAddress, int Channell );
	[DllImport("k8061.dll")]
	public static extern void ReadAllAnalog(int CardAddress, ref int[] data);
	[DllImport("k8061.dll")]
	public static extern void OutputAnalogChannel (int CardAddress, int Channel, int Data);
	[DllImport("k8061.dll")]
	public static extern void OutputAllAnalog(int CardAddress, ref int[] data);
	[DllImport("k8061.dll")]
	public static extern void ClearAnalogChannel(int CardAddress,int Channel);
	[DllImport("k8061.dll")]
	public static extern void ClearAllAnalog(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern void SetAnalogChannel(int CardAddres, int Channel);
	[DllImport("k8061.dll")]
	public static extern void SetAllAnalog(int CardAddress);

	[DllImport("k8061.dll")]
	public static extern void OutputAllDigital(int CardAddress, int data);
	[DllImport("k8061.dll")]
	public static extern void ClearDigitalChannel(int CardAddress, int Channel); 
	[DllImport("k8061.dll")]
	public static extern void ClearAllDigital(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern void SetDigitalChannel(int CardAddress, int Channel);
	[DllImport("k8061.dll")]
	public static extern void SetAllDigital(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern bool ReadDigitalChannel(int CardAddress, int Channel);
	[DllImport("k8061.dll")]
	public static extern int ReadAllDigital(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern void OutputPWM(int CardAddress,int Data);
	[DllImport("k8061.dll")]
	public static extern bool PowerGood(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern bool Connected(int CardAddress);
	[DllImport("k8061.dll")]
	public static extern void ReadVersion(int CardAddress,ref int[] Buffer);

	
	private int _cardaddress;

	public bool _K8061_InitCard()
	{
		_cardaddress = OpenDevice();
		if (_cardaddress == -2)
		{
			return (false);
		} 
		else 
		{
			return (true);
		}
	}
 }

}[/i]

Application code:

public ThermoState()
{
InitializeComponent();
iface._K8061_InitCard();
}

Try putting the _K8061_InitCard() inside a button click event handler instead of that constructor, and see if it still crashes when you click the button. Maybe the initialization order of native/managed code is wrong somewhere.

Another suggestion was to rename your project to a name < 10 characters, but this seems like a long shot…

Moved from InitializeComponent and inserted on an onClick event worked fine.
Anyway on onLoad event on form does not work too.
Only way founded to have it working automatically is to put into a timing event, but it’s not so elegant.

Update:
Chart Component was put into a tab panel. As soon as i choose Charts tab (with card now opened) program fails.
I’ve moved card opening to a button and having three figures:

  • Opening tab charts without pressing card button (so InitCard is not called) work.
  • Opening tab charts after pressing card button (so InitCard is called) does not work.
  • Opening tab chart without pressing card button, then back to open situation, press card button, then again Charts tab, works.

Seems that initCard create a problem to Charts visualization routines, as soon as Charts is visualized before card initialization, initCard runs fine.

Last Update.
After some testing i finally saw that initCards had a serious impact on .net Charts.
Even if i can load a new chart with some trick it couldn’t be possible to write any kind of data.
As a test i added a button to retrieve data from a db and create a chart with them after an initCard call.
Result was an exception in winform module.
Having used charts components many times without any problem i can only argue that is initcard in k8061.dll that for some reason is not compatible (or at least create some problem) with microsoft .net charting component.