We’re using the K8055 board to programatically pause a printer. Everything is working wonderfully (great product)! However, the one issue that I have is when I close my application (C# - Visual Studio 2008 Professional) while running inside of Visual Studio I get two error dialogs. The first one says:
The exception unknown software exception (0x0eedfade) occurred in the application at location 0x7c812a6b.
I click Okay on that and I get a second error dialog:
Runtime error 217 at 00009C34.
If I run my app outside of VS it runs fine with no exception. I’ve played around with the DLL imports to see if that made any difference and it does not. Although I could deploy the app since it runs fine outside of VS I’m concerned that I’m creating a resource leak. Here’s a class that I developed for the board:
Never mind…I answered my own question. I was using the K8055.dll when I should have been using the K8055_c.dll. Here’s the corrected class that now does not error when the application quits in VS:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Label_Applicator_Manager
{
public enum Address : int
{
Address0 = 0,
Address1 = 1,
Address2 = 2,
Address3 = 3
}
public enum Channel : int
{
Channel1 = 1,
Channel2 = 2,
Channel3 = 3,
Channel4 = 4,
Channel5 = 5
}
public enum Counter : int
{
Counter1 = 1,
Counter2 = 2
}
public class Velleman_K8055 : IDisposable
{
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall )]
public static extern unsafe int OpenDevice(int address);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void CloseDevice();
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void WriteAllDigital(int data);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void ClearDigitalChannel(int channel);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void ClearAllDigital();
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void SetDigitalChannel(int channel);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void SetallDigitial();
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe bool ReadDigitalChannel(int channel);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe int ReadAllDigital();
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void ResetCounter(int counter);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe int ReadCounter(int counter);
[System.Runtime.InteropServices.DllImport("K8055D_C", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe void SetCounterDebounceTime(int counter, int time);
private Address boardAddress;
private bool disposed = false;
public Velleman_K8055(Address _address)
{
boardAddress = _address;
int addr = (int)boardAddress;
// Attempt to open the board at the specified address
if (OpenDevice(addr) != (int)boardAddress)
{
throw new Exception("Could not open interface board at address " + boardAddress.ToString());
}
}
public void Close()
{
CloseDevice();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposed)
{
Close();
disposed = true;
}
}
public bool Read(Channel channel)
{
return ReadDigitalChannel((int)channel);
}
public void CounterReset(Counter counter)
{
ResetCounter((int)counter);
}
public int CounterRead(Counter counter)
{
return ReadCounter((int)counter);
}
public void SetCDT(Counter counter, int time)
{
SetCounterDebounceTime((int)counter, time);
}
}
}