K8061 Java jni Problem

Hi,

I tried a programm with the board K8055 and get no problems. I used a sample prog from the book MSR with Java and USB.
Now i want to try the prog on K8061 but i get a problem with the DLL. I get this errorlog.

[quote]#

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0036ec89, pid=5136, tid=8180

JRE version: 7.0_07-b10

Java VM: Java HotSpot™ Client VM (23.3-b01 mixed mode, sharing windows-x86 )

Problematic frame:

C [K8061.dll+0x3ec89] ReadVersion+0x95

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

If you would like to submit a bug report, please visit:

bugreport.sun.com/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

--------------- T H R E A D ---------------

Current thread (0x0027a800): JavaThread “main” [_thread_in_native, id=8180, stack(0x002e0000,0x00330000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x006a0870

Registers:
EAX=0x00000000, EBX=0x344cc6b0, ECX=0x00000000, EDX=0x00000002
ESP=0x0032fabc, EBP=0x0032fac8, ESI=0x00330000, EDI=0x00000003
EIP=0x0036ec89, EFLAGS=0x00010246

Top of Stack: (sp=0x0032fabc)
0x0032fabc: 0027a800 344cc6b0 0036eb2f 0032fae8
0x0032facc: 6eb416a8 00330000 0036eb0c 344cc6b0
0x0032fadc: 0032fb20 025aa607 0036eb0c 0032fb20
0x0032faec: 025aa707 0027a928 0032fb30 0027b114
0x0032fafc: 0027b11c 0032fb00 344cc6b0 0032fb30
0x0032fb0c: 344ccc68 00000000 344cc6b0 00000000
0x0032fb1c: 0032fb30 0032fb54 025a32c7 00000000
0x0032fb2c: 025a8989 244f0300 0032fb34 344cb89f

Instructions: (pc=0x0036ec89)
0x0036ec69: f0 b9 40 00 00 00 b8 c0 08 37 00 c6 00 00 40 49
0x0036ec79: 75 f9 33 c0 a3 8c 09 37 00 33 c0 a3 84 09 37 00
0x0036ec89: 80 be 70 08 37 00 00 0f 84 9f 00 00 00 6a 00 68
0x0036ec99: 88 09 37 00 52 68 80 08 37 00 6a 01 8b 04 b5 64

Register to memory mapping:

EAX=0x00000000 is an unknown value
EBX=0x344cc6b0 is an oop
{method}

  • klass: {other class}
    ECX=0x00000000 is an unknown value
    EDX=0x00000002 is an unknown value
    ESP=0x0032fabc is pointing into the stack for thread: 0x0027a800
    EBP=0x0032fac8 is pointing into the stack for thread: 0x0027a800
    ESI=0x00330000 is pointing into the stack for thread: 0x0027a800
    EDI=0x00000003 is an unknown value

Stack: [0x002e0000,0x00330000], sp=0x0032fabc, free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [K8061.dll+0x3ec89] ReadVersion+0x95
C [JK8055.dll+0x16a8] Java_JK8055_SetAllDigital+0x2f
j JK8055.SetAllDigital()V+0
j test.main([Ljava/lang/String;)V+15
v ~StubRoutines::call_stub
V [jvm.dll+0x12a39a]
V [jvm.dll+0x1d962e]
V [jvm.dll+0x12a41d]
V [jvm.dll+0xaee94]
V [jvm.dll+0xb9217]
C [javaw.exe+0x1fea]
C [javaw.exe+0xa0eb]
C [javaw.exe+0xa175]
C [kernel32.dll+0x133aa] BaseThreadInitThunk+0x12
C [ntdll.dll+0x39ef2] RtlInitializeExceptionChain+0x63
C [ntdll.dll+0x39ec5] RtlInitializeExceptionChain+0x36

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j JK8055.SetAllDigital()V+0
j test.main([Ljava/lang/String;)V+15
v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x0104e800 JavaThread “Service Thread” daemon [_thread_blocked, id=7788, stack(0x04bf0000,0x04c40000)]
0x0104c800 JavaThread “C1 CompilerThread0” daemon [_thread_blocked, id=8504, stack(0x04ae0000,0x04b30000)]
0x0104b400 JavaThread “Attach Listener” daemon [_thread_blocked, id=8576, stack(0x04930000,0x04980000)]
0x01048400 JavaThread “Signal Dispatcher” daemon [_thread_blocked, id=8200, stack(0x049e0000,0x04a30000)]
0x01036400 JavaThread “Finalizer” daemon [_thread_blocked, id=8176, stack(0x04660000,0x046b0000)]
0x01031800 JavaThread “Reference Handler” daemon [_thread_blocked, id=5612, stack(0x04820000,0x04870000)]
=>0x0027a800 JavaThread “main” [_thread_in_native, id=8180, stack(0x002e0000,0x00330000)]

Other Threads:
0x01030400 VMThread [stack: 0x045d0000,0x04620000] [id=4616]
0x01050800 WatcherThread [stack: 0x048e0000,0x04930000] [id=7700]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
def new generation total 4928K, used 281K [0x244b0000, 0x24a00000, 0x29a00000)
eden space 4416K, 6% used [0x244b0000, 0x244f6558, 0x24900000)
from space 512K, 0% used [0x24900000, 0x24900000, 0x24980000)
to space 512K, 0% used [0x24980000, 0x24980000, 0x24a00000)
tenured generation total 10944K, used 0K [0x29a00000, 0x2a4b0000, 0x344b0000)
the space 10944K, 0% used [0x29a00000, 0x29a00000, 0x29a00200, 0x2a4b0000)
compacting perm gen total 12288K, used 115K [0x344b0000, 0x350b0000, 0x384b0000)
the space 12288K, 0% used [0x344b0000, 0x344ccfb0, 0x344cd000, 0x350b0000)
ro space 10240K, 42% used [0x384b0000, 0x388ef150, 0x388ef200, 0x38eb0000)
rw space 12288K, 54% used [0x38eb0000, 0x3952fad8, 0x3952fc00, 0x39ab0000)

Card table byte_map: [0x01080000,0x01130000] byte_map_base: 0x00f5da80

Polling page: 0x000c0000

Code Cache [0x025a0000, 0x02638000, 0x045a0000)
total_blobs=134 nmethods=6 adapters=64 free_code_cache=32185Kb largest_free_block=32958208

Compilation events (10 events):
Event: 0.044 Thread 0x0104c800 2 java.lang.String::charAt (29 bytes)
Event: 0.044 Thread 0x0104c800 nmethod 2 0x02630288 code [0x02630390, 0x026304bc]
Event: 0.048 Thread 0x0104c800 3 java.lang.String::indexOf (70 bytes)
Event: 0.048 Thread 0x0104c800 nmethod 3 0x02630608 code [0x02630720, 0x0263085c]
Event: 0.048 Thread 0x0104c800 4 java.lang.String::indexOf (166 bytes)
Event: 0.049 Thread 0x0104c800 nmethod 4 0x02630988 code [0x02630aa0, 0x02630cd0]
Event: 0.050 Thread 0x0104c800 5 java.io.Win32FileSystem::normalize (143 bytes)
Event: 0.050 Thread 0x0104c800 nmethod 5 0x02630fc8 code [0x02631110, 0x026313ac]
Event: 0.050 Thread 0x0104c800 6 java.lang.Object:: (1 bytes)
Event: 0.051 Thread 0x0104c800 nmethod 6 0x02631708 code [0x02631800, 0x02631890]

GC Heap History (0 events):
No events

Deoptimization events (0 events):
No events

Internal exceptions (3 events):
Event: 0.019 Thread 0x0027a800 Threw 0x244b11d8 at C:\jdk7u1_32P\jdk7u7\hotspot\src\share\vm\prims\jni.cpp:3994
Event: 0.045 Thread 0x0027a800 Threw 0x244e9e88 at C:\jdk7u1_32P\jdk7u7\hotspot\src\share\vm\prims\jvm.cpp:1166
Event: 0.048 Thread 0x0027a800 Threw 0x244ed350 at C:\jdk7u1_32P\jdk7u7\hotspot\src\share\vm\prims\jvm.cpp:1166

Events (10 events):
Event: 0.046 loading class 0x0104f7f8
Event: 0.046 loading class 0x0104f7f8 done
Event: 0.046 loading class 0x39bad170
Event: 0.046 loading class 0x39ae3788
Event: 0.046 loading class 0x39ae3788 done
Event: 0.046 loading class 0x39bad170 done
Event: 0.048 loading class 0x01058f20
Event: 0.048 loading class 0x01058f20 done
Event: 0.049 loading class 0x39abaa28
Event: 0.049 loading class 0x39abaa28 done

Dynamic libraries:
0x01170000 - 0x0119f000 C:\Program Files (x86)\Java\jre7\bin\javaw.exe
0x778d0000 - 0x77a50000 C:\Windows\SysWOW64\ntdll.dll
0x75710000 - 0x75820000 C:\Windows\syswow64\kernel32.dll
0x75eb0000 - 0x75ef7000 C:\Windows\syswow64\KERNELBASE.dll
0x75940000 - 0x759e0000 C:\Windows\syswow64\ADVAPI32.dll
0x76f60000 - 0x7700c000 C:\Windows\syswow64\msvcrt.dll
0x756f0000 - 0x75709000 C:\Windows\SysWOW64\sechost.dll
0x751f0000 - 0x752e0000 C:\Windows\syswow64\RPCRT4.dll
0x74fb0000 - 0x75010000 C:\Windows\syswow64\SspiCli.dll
0x74fa0000 - 0x74fac000 C:\Windows\syswow64\CRYPTBASE.dll
0x75c80000 - 0x75d80000 C:\Windows\syswow64\USER32.dll
0x76de0000 - 0x76e70000 C:\Windows\syswow64\GDI32.dll
0x75640000 - 0x7564a000 C:\Windows\syswow64\LPK.dll
0x75d80000 - 0x75e1d000 C:\Windows\syswow64\USP10.dll
0x740d0000 - 0x7426e000 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\COMCTL32.dll
0x75f00000 - 0x75f57000 C:\Windows\syswow64\SHLWAPI.dll
0x76e70000 - 0x76ed0000 C:\Windows\system32\IMM32.DLL
0x75570000 - 0x7563c000 C:\Windows\syswow64\MSCTF.dll
0x74d60000 - 0x74d96000 C:\Windows\SysWOW64\nvinit.dll
0x74560000 - 0x7461e000 C:\Program Files (x86)\Java\jre7\bin\msvcr100.dll
0x64cd0000 - 0x6501c000 C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll
0x74b90000 - 0x74b97000 C:\Windows\system32\WSOCK32.dll
0x75530000 - 0x75565000 C:\Windows\syswow64\WS2_32.dll
0x756e0000 - 0x756e6000 C:\Windows\syswow64\NSI.dll
0x74400000 - 0x74432000 C:\Windows\system32\WINMM.dll
0x751e0000 - 0x751e5000 C:\Windows\syswow64\PSAPI.DLL
0x746c0000 - 0x746cc000 C:\Program Files (x86)\Java\jre7\bin\verify.dll
0x74630000 - 0x74650000 C:\Program Files (x86)\Java\jre7\bin\java.dll
0x74540000 - 0x74553000 C:\Program Files (x86)\Java\jre7\bin\zip.dll
0x6eb40000 - 0x6eb48000 C:\Users\Pete\Desktop\test\JK8055.dll
0x00330000 - 0x0037d000 C:\Windows\system32\K8061.dll
0x75650000 - 0x756df000 C:\Windows\syswow64\oleaut32.dll
0x76c30000 - 0x76d8c000 C:\Windows\syswow64\ole32.dll
0x75040000 - 0x751dd000 C:\Windows\syswow64\setupapi.dll
0x76ed0000 - 0x76ef7000 C:\Windows\syswow64\CFGMGR32.dll
0x76dc0000 - 0x76dd2000 C:\Windows\syswow64\DEVOBJ.dll
0x74530000 - 0x74537000 C:\Windows\system32\WINUSB.DLL
0x76d90000 - 0x76dbd000 C:\Windows\syswow64\WINTRUST.dll
0x75820000 - 0x7593e000 C:\Windows\syswow64\CRYPT32.dll
0x75b50000 - 0x75b5c000 C:\Windows\syswow64\MSASN1.dll
0x74a90000 - 0x74b7b000 C:\Windows\system32\dbghelp.dll

VM Arguments:
jvm_args: -Dfile.encoding=Cp1252
java_command: test
Launcher Type: SUN_STANDARD

Environment Variables:
PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\EgisTec MyWinLocker\x64;C:\Program Files (x86)\EgisTec MyWinLocker
USERNAME=Pete
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows 7 , 64 bit Build 7601 Service Pack 1

CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, ht, tsc, tscinvbit

Memory: 4k page, physical 4042608k(1632932k free), swap 8083364k(4744392k free)

vm_info: Java HotSpot™ Client VM (23.3-b01) for windows-x86 JRE (1.7.0_07-b10), built on Aug 28 2012 19:49:22 by “java_re” with unknown MS VC++:1600

time: Mon Nov 12 20:41:16 2012
elapsed time: 0 seconds

[/quote]

some ideas?

it seems to be a problem with the method ReadVersion in the K0861.DLL
but in the K8055.DLL there is no ReadVersion method
Please help, i tried to google that problem but get no solution.

Yes, the function [color=#0000FF]ReadVersion[/color] in the K8061 DLL is different compared to the function [color=#0000FF]Version[/color] of the K8055 and K8055N DLLs.

K8061 DLL:

ReadVersion
Syntax
PROCEDURE ReadVersion(CardAddress: Longint; Buffer: Pointer);
Parameters
CardAddress: The address of previously opened card.
Buffer: Pointer to an array of long integers where the software (firmware) version info data will be
read. The size of the buffer should be minimum 50 long integers (200 bytes).

K8055 and K8055N DLL:

Version
Syntax
int Version();
Result
int: A 32 bit integer where the DLL version (4 digits) is represented. Each byte is one digit.

Ok… but where is now the problem? How can i fix it?

What does the JNI wrapper for calling ReadVersion() look like?

I dont have the funktion ReadVersion in the wrapper, because i dont need that.
Or do i need all available functions in the wrapper?

[quote]Stack: [0x002e0000,0x00330000], sp=0x0032fabc, free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [K8061.dll+0x3ec89] ReadVersion+0x95
C [JK8055.dll+0x16a8] Java_JK8055_SetAllDigital+0x2f
j JK8055.SetAllDigital()V+0
j test.main([Ljava/lang/String;)V+15[/quote]

Looking at this part of the stack trace, test.main() calls JK8055.SetAllDigital(), which calls the C function Java_JK8055_SetAllDigital() in JK8055.dll which then calls ReadVersion() in K8061.dll.

Do you have the source code of JK8055.dll? If so, does the function Java_JK8055_SetAllDigital() in there call ReadVersion() and what exactly is it passing as Buffer argument?

Ok i’m not at home now. I’ll post the code later. Thanks

Not that I used JNI ever, I’m just an experienced C programmer who regularly uses gdb.

However, the combination of JK8055.dll calling K8061.dll strikes me as odd. Shouldn’t the JNI glue code for calling K8061.dll be in something like JK8061.dll instead?

I am also not a prof in jni i just followed the steps in the book. The JK8055.DLL is a self made dll that calls the K8061.DLL

The question then is, does it “always” call the K8061.dll, or does it eventually sometimes call functions of the same name in other dlls?

There are several libraries from Velleman that all export functions like OpenDevice(), SetAllDigital() and so on. They eventually do something different. The K8055 version for example is based on HID communication while the K8061 version uses the Microchip mpusbapi.dll instead.

From the source code I could quickly find online, it doesn’t seem like ReadVersion() is called internally inside the K8061.dll. But what I looked at may either not be the latest version of the code, or this whole error could be the result of a corrupted call stack.

Yes it call only the K8061.dll

In the error log there are some dynamic libraries but i cant find the mpusbapi.dll ?!?

viewtopic.php?t=853

At least that old version of the dll uses it. That it doesn’t appear in the call stack at the moment of the crash doesn’t mean that it isn’t referenced.

The original K8061.DLL is using functions in the mpusbapi.dll.

Now here is a new driver and new DLL for the K8061:
box.com/s/nfybaxspvy9689fujbgq
This new K8061.DLL is no longer using the mpusbapi.dll.

Instructions how to install the new driver and to test the DLL:

  1. In the Device Manager uninstall the K8061 driver v.1.0.0.6 (dated 19/12/2007).
  2. Unplug and plug the K8061 card.
  3. Extract the downloaded ZIP package.
  4. Install the new driver from folder K8061Driver_v1.0.0.2 (dated 24/08/2009).
  5. In Device Manager make sure the driver v.1.0.0.2 is installed
  6. Go to folder K8061Demo and run the K8061_Demo.exe

[quote=“VEL255”]The original K8061.DLL is using functions in the mpusbapi.dll.

Now here is a new driver and new DLL for the K8061:
box.com/s/nfybaxspvy9689fujbgq
This new K8061.DLL is no longer using the mpusbapi.dll.[/quote]
Can’t find the source code for that.

Does that version somehow internally invoke ReadVersion() and can that call cause the crash due to some missing initialization?

As a side note, these requests and the usefulness of availability of the driver/library source code are fairly frequent. And you routinely upload such to some download site (not firmware, but drivers and libraries). Wouldn’t it make sense to put all the drivers/libraries and their corresponding source code onto a web/ftp server so users can find them on their own?

Regards,
Jan

ok… here i am again.

here’s the source code of JK8055.dll

[code]#include <jni.h>
#include “JK8055.h”
#include <stdio.h>
#include <windows.h>

typedef long (*OpenDevice)(long);
typedef void (*CloseDevice)();
typedef void (*SetAllDigital)();
typedef void (*ClearAllDigital)();
typedef long (*ReadAnalogChannel)(long);
typedef void (*OutputAnalogChannel)(long,long);
typedef void (*OutputAllAnalog)(long, long);
typedef void (*ClearAnalogChannel)(long);
typedef void (*ClearAllAnalog)();
typedef void (*SetAnalogChannel)(long);
typedef void (*SetAllAnalog)();
typedef void (*WriteAllDigital)(long);
typedef void (*ClearDigitalChannel)(long);
typedef void (*SetDigitalChannel)(long);
typedef long (*ReadDigitalChannel)(long);
typedef long (*ReadAllDigital)();
typedef long (*ReadCounter)(long);
typedef void (*ResetCounter)(long);
typedef void (*SetCounterDebounceTime)(long,long);
typedef long (*SearchDevices)();
typedef long (*SetCurrentDevice)(long);

HINSTANCE hinstLib;
int dllGeladen = 0;

JNIEXPORT jlong JNICALL Java_JK8055_open (JNIEnv * env, jobject o)
{
//printf("%d" , card );
hinstLib = LoadLibrary(“K8061.dll”);
if (hinstLib)
{
dllGeladen = 1;
return 1;
}
else
{
printf (“DLL nicht geladen”);
return -1;
}
}

JNIEXPORT jlong JNICALL Java_JK8055_OpenDevice (JNIEnv * env, jobject o, jlong card)
{
//printf("%d" , card );
OpenDevice function;
if (dllGeladen !=1)
{
hinstLib = LoadLibrary(“K8061.dll”);
dllGeladen = 1;
}

if (hinstLib)
{
//printf(“DLL geladen”);
dllGeladen = 1;
function = (OpenDevice) GetProcAddress(hinstLib, “OpenDevice”);
//if (function)
//printf (“Funktion geladen”);
long result = (*function) ((long)card);
//printf( “OpenDevice\n” );
return result;
}
else
{
printf (“DLL nicht geladen”);
return -1;
}

}
JNIEXPORT void JNICALL Java_JK8055_CloseDevice (JNIEnv *env, jobject o)
{
CloseDevice function;
if (dllGeladen == 1)
{
function = (CloseDevice) GetProcAddress(hinstLib, “CloseDevice”);
(*function) ();
BOOL fFreeResult = FreeLibrary(hinstLib);
//printf( “CloseDevice\n” );
dllGeladen = 0;
}
else
{
printf (“dll nicht geladen”);
}
return;
}

/*

  • Class: JK8055
  • Method: ReadAnalogChannel
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadAnalogChannel (JNIEnv *env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    ReadAnalogChannel function;
    function = (ReadAnalogChannel) GetProcAddress(hinstLib, “ReadAnalogChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    long result = (*function) ((long)channel);
    //BOOL fFreeResult = FreeLibrary(hinstLib);
    //printf( “ReadAnalogChannel\n” );
    return result;
    }
    else
    {
    printf (“dll nicht geladen”);
    return -1;
    }
    }

/*

  • Class: JK8055
  • Method: OutputAnalogChannel
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_OutputAnalogChannel (JNIEnv *env, jobject o , jlong channel, jlong data)
    {
    if (dllGeladen == 1)
    {
    OutputAnalogChannel function;
    function = (OutputAnalogChannel) GetProcAddress(hinstLib, “OutputAnalogChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) ((long)channel, (long) data);
    //printf( “OutputAnalogChannel\n” );
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: OutputAllAnalog
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_OutputAllAnalog (JNIEnv * env, jobject o, jlong data1, jlong data2)
    {
    if (dllGeladen == 1)
    {
    OutputAllAnalog function;
    function = (OutputAllAnalog) GetProcAddress(hinstLib, “OutputAllAnalog”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) ((long)data1, (long) data2);
    //BOOL fFreeResult = FreeLibrary(hinstLib);
    //printf( “OutputAllAnalog\n” );
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: ClearAnalogChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAnalogChannel (JNIEnv *env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    ClearAnalogChannel function;
    function = (ClearAnalogChannel) GetProcAddress(hinstLib, “ClearAnalogChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) ((long)channel);
    //printf (“ClearAnalogChannel”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: ClearAllAnalog
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAllAnalog (JNIEnv *env, jobject o)
    {
    if (dllGeladen == 1)
    {
    ClearAllAnalog function;
    function = (ClearAllAnalog) GetProcAddress(hinstLib, “ClearAllAnalog”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) ();
    //printf (“ClearAllAnalog”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: SetAnalogChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAnalogChannel (JNIEnv * env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    SetAnalogChannel function;
    function = (SetAnalogChannel) GetProcAddress(hinstLib, “SetAnalogChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) (channel);
    //printf (“SetAnalogChannel”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: SetAllAnalog
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAllAnalog (JNIEnv *env, jobject o)
    {
    if (dllGeladen == 1)
    {
    SetAllAnalog function;
    function = (SetAllAnalog) GetProcAddress(hinstLib, “SetAllAnalog”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) ();
    //printf (“SetAllAnalog”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: WriteAllDigital
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_WriteAllDigital (JNIEnv *env, jobject o, jlong data)
    {
    if (dllGeladen == 1)
    {
    WriteAllDigital function;
    function = (WriteAllDigital) GetProcAddress(hinstLib, “WriteAllDigital”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) (data);
    //printf (“WriteAllDigital”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: ClearDigitalChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearDigitalChannel (JNIEnv * env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    ClearDigitalChannel function;
    function = (ClearDigitalChannel) GetProcAddress(hinstLib, “ClearDigitalChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) (channel);
    //printf (“ClearDigitalChannel”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: ClearAllDigital
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAllDigital (JNIEnv *env, jobject o)
    {
    if (dllGeladen == 1)
    {
    OpenDevice function0;
    ClearAllDigital function;
    function = (ClearAllDigital) GetProcAddress(hinstLib, “ClearAllDigital”);
    function0 = (OpenDevice) GetProcAddress(hinstLib, “OpenDevice”);
    (*function0)(0);
    (*function) ();
    //BOOL fFreeResult = FreeLibrary(hinstLib);
    //printf( “ClearAllDigital\n” );
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: SetDigitalChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetDigitalChannel (JNIEnv *env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    SetDigitalChannel function;
    function = (SetDigitalChannel) GetProcAddress(hinstLib, “SetDigitalChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    (*function) (channel);
    //printf (“SetDigitalChannel”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }

return;
}

/*

  • Class: JK8055
  • Method: SetAllDigital
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAllDigital (JNIEnv *env, jobject o)
    {
    if (dllGeladen == 1)
    {
    SetAllDigital function;
    function = (SetAllDigital) GetProcAddress(hinstLib, “SetAllDigital”);
    (*function) ();
    //printf( “SetAllDigital\n” );
    }
    else
    {
    printf (“dll nicht geladen”);
    }
    return;
    }

/*

  • Class: JK8055
  • Method: ReadDigitalChannel
  • Signature: (J)Z
    */
    JNIEXPORT jboolean JNICALL Java_JK8055_ReadDigitalChannel (JNIEnv *env, jobject o, jlong channel)
    {
    if (dllGeladen == 1)
    {
    ReadDigitalChannel function;
    function = (ReadDigitalChannel) GetProcAddress(hinstLib, “ReadDigitalChannel”);
    //if (function)
    //printf (“Funktion geladen”);
    int result = (*function) (channel);
    //printf (“ReadDigitalChannel”);
    return result;
    }
    else
    {
    printf (“dll nicht geladen”);
    return -1;
    }
    }

/*

  • Class: JK8055
  • Method: ReadAllDigital
  • Signature: ()J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadAllDigital (JNIEnv *env, jobject o)
    {
    if (dllGeladen = 1)
    {
    ReadAllDigital function;
    function = (ReadAllDigital) GetProcAddress(hinstLib, “ReadAllDigital”);
    //if (function)
    //printf (“Funktion geladen”);
    long result = (*function) ();
    //printf (“ReadAllDigital”);
    return result;
    }
    else
    {
    printf (“dll nicht geladen”);
    return -1;
    }
    }

/*

  • Class: JK8055
  • Method: ReadCounter
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadCounter (JNIEnv *env, jobject o, jlong counter)
    {
    if (dllGeladen == 1)
    {
    ReadCounter function;
    function = (ReadCounter) GetProcAddress(hinstLib, “ReadCounter”);
    //if (function)
    //printf (“Funktion geladen”);
    long result = (function) (counter);
    //printf (“ReadCounter”);
    return result;
    }
    else
    {
    printf (“dll nicht geladen”);
    return -1;
    }
    }
    /
  • Class: JK8055
  • Method: ResetCounter
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ResetCounter (JNIEnv *env, jobject o, jlong counter)
    {
    if (dllGeladen == 1)
    {
    ResetCounter function;
    function = (ResetCounter) GetProcAddress(hinstLib, “ResetCounter”);
    if (function)
    printf (“Funktion geladen”);
    (*function) (counter);
    printf (“ResetCounter”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }

return;
}

/*

  • Class: JK8055
  • Method: SetCounterDebounceTime
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetCounterDebounceTime (JNIEnv *env, jobject o, jlong counter, jlong time)
    {
    if (dllGeladen == 1)
    {
    SetCounterDebounceTime function;
    function = (SetCounterDebounceTime) GetProcAddress(hinstLib, “SetCounterDebounceTime”);
    if (function)
    printf (“Funktion geladen”);
    (*function) (counter,time);
    printf (“SetCounterDebounceTime”);
    }
    else
    {
    printf (“dll nicht geladen”);
    }

return;
}

JNIEXPORT jlong JNICALL Java_JK8055_SearchDevices (JNIEnv *env, jobject o)
{
if (dllGeladen ==1)
{
SearchDevices function;
function = (SearchDevices) GetProcAddress(hinstLib,“SearchDevices”);
if (function)
{
long wert = (*function)();
return wert;
}
else
{
return -1;
}
}
else
{
printf (“dll nicht geladen”);
return -1;
}
}

JNIEXPORT jlong JNICALL Java_JK8055_SetCurrentDevice (JNIEnv * env, jobject o, jlong device)
{
if (dllGeladen ==1)
{
SetCurrentDevice function;
function = (SetCurrentDevice) GetProcAddress(hinstLib,“SetCurrentDevice”);
if (function)
{
long wert = (*function)(device);
return wert;
}
else
{
return -1;
}
}
else
{
printf (“dll nicht geladen”);
return -1;
}
return 0;
}
[/code]

and the code of the header:

[code]/* DO NOT EDIT THIS FILE - it is machine generated /
#include <jni.h>
/
Header for class JK8055 */

#ifndef _Included_JK8055
#define _Included_JK8055
#ifdef __cplusplus
extern “C” {
#endif
/*

  • Class: JK8055
  • Method: open
  • Signature: ()J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_open
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: OpenDevice
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_OpenDevice
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: CloseDevice
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_CloseDevice
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: ReadAnalogChannel
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadAnalogChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: OutputAnalogChannel
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_OutputAnalogChannel
    (JNIEnv *, jobject, jlong, jlong);

/*

  • Class: JK8055
  • Method: OutputAllAnalog
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_OutputAllAnalog
    (JNIEnv *, jobject, jlong, jlong);

/*

  • Class: JK8055
  • Method: ClearAnalogChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAnalogChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: ClearAllAnalog
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAllAnalog
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: SetAnalogChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAnalogChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: SetAllAnalog
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAllAnalog
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: WriteAllDigital
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_WriteAllDigital
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: ClearDigitalChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearDigitalChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: ClearAllDigital
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_ClearAllDigital
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: SetDigitalChannel
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetDigitalChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: SetAllDigital
  • Signature: ()V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetAllDigital
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: ReadDigitalChannel
  • Signature: (J)Z
    */
    JNIEXPORT jboolean JNICALL Java_JK8055_ReadDigitalChannel
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: ReadAllDigital
  • Signature: ()J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadAllDigital
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: ReadCounter
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_ReadCounter
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: ResetCounter
  • Signature: (J)V
    */
    JNIEXPORT void JNICALL Java_JK8055_ResetCounter
    (JNIEnv *, jobject, jlong);

/*

  • Class: JK8055
  • Method: SetCounterDebounceTime
  • Signature: (JJ)V
    */
    JNIEXPORT void JNICALL Java_JK8055_SetCounterDebounceTime
    (JNIEnv *, jobject, jlong, jlong);

/*

  • Class: JK8055
  • Method: SearchDevices
  • Signature: ()J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_SearchDevices
    (JNIEnv *, jobject);

/*

  • Class: JK8055
  • Method: SetCurrentDevice
  • Signature: (J)J
    */
    JNIEXPORT jlong JNICALL Java_JK8055_SetCurrentDevice
    (JNIEnv *, jobject, jlong);

#ifdef __cplusplus
}
#endif
#endif
[/code]

and the java wrapper class:

[code]public class JK8055
{
static {
System.loadLibrary(“JK8055”);
}
public native long open();
public native long OpenDevice(long CardAddress);
public native void CloseDevice();
public native long ReadAnalogChannel(long Channel);
public native void OutputAnalogChannel(long Channel, long Data);
public native void OutputAllAnalog(long Data1, long Data2);
public native void ClearAnalogChannel(long Channel);
public native void ClearAllAnalog();
public native void SetAnalogChannel(long Channel);
public native void SetAllAnalog();
public native void WriteAllDigital(long Data);
public native void ClearDigitalChannel(long Channel);
public native void ClearAllDigital();
public native void SetDigitalChannel(long Channel);
public native void SetAllDigital();
public native boolean ReadDigitalChannel(long Channel);
public native long ReadAllDigital();
public native long ReadCounter(long CounterNr);
public native void ResetCounter(long CounterNr);
public native void SetCounterDebounceTime(long CounterNr, long DebounceTime);
public native long SearchDevices ();
public native long SetCurrentDevice (long device);

}[/code]

and i tested it with the new dll and driver without success :frowning:

Now the source is included to the package.
This DLL is just a test version to try to solve possible problems.
It is not yet ready for “official” release - but can be released on the Velleman web site in the future.
It seems there is no help using this DLL version in this case though.

Just curious: Is the “long” data type 64-bits in Java ?
docs.oracle.com/javase/1.5.0/doc … types.html

The K8055 and K8061 DLLs need 32-bit integers as parameters.

It seems at least in the case of ReadVersion(), the K8061.dll is using a pointer to a result buffer as a function argument. The caller is responsible to allocate a result buffer of at least 200 bytes (to hold 50 long values). I suspect that the caller is passing either a NULL pointer (BTW the DLL doesn’t check for that), an insufficiently sized buffer, a misaligned pointer or a pointer into the text segment (read only to a process) and that causes the exception.

It is still unclear to me where the apparent call to ReadVersion() is coming from. Neither the new DLL version nor the JNI glue code are calling it anywhere. It could still be a corrupted call stack resulting from something else, but in my experience they look a lot more ugly and cryptic than this.

[quote=“VEL255”]Just curious: Is the “long” data type 64-bits in Java ?
docs.oracle.com/javase/1.5.0/doc … types.html

The K8055 and K8061 DLLs need 32-bit integers as parameters.[/quote]

dont know… but i get the same crash with 32bit winxp.

by the way: i downloaded the new dll at the velleman website

velleman.eu/downloads/files/ … r_v4_0.zip