This site requires JavaScript, please enable it in your browser!
Greenfoot back
Yogibaer
Yogibaer wrote ...

2013/11/4

Using dll libraries to control hardware

Yogibaer Yogibaer

2013/11/4

#
hello to all, on Greenfoot.org i saw two informations: Docu how to use native libraries and Sense Board Demo. I want to control a similar multi-I/O-board called K8055D from Veleman, Belgium The difference: the board comes with a dll-file to control it via USB but without BYTE-Information I started to follow the advices to use dll´s. Attached I show the situation of work, but you see: There are compiler comments, but I don´t know how to avoid them. Asking for help Yogibaer
Start of PanelWorld

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Controlboard for a multi-I/O-Interface-Board, similar to SenseBoard
 * @author Yogibaer
 */
public class PanelWorld extends World
 {
    static 
      {final NativeLoader loader = new NativeLoader();     
       loader.loadClass("KD8055");}  
 // alternative  loader.loadClass(„K8055D.dll“) gives no problems from the compiler
    
    private  KD8055   board;   
    
    public PanelWorld()
    {
       super(600, 400, 1);        
    }
    
    public void act()
    { test1();          
    }
        
    public void test1()
    { board.oeffnen();
      board.setzLampe1();
       Greenfoot.delay(10);
      board.setzLampe2();
      board.setzLampe3();
      board.schliessen();
    }
Start of KD8055
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * KD8055 is the bridge-class to the K8055D.dll.
 *  * @author Yogibaer  
 */

public class KD8055 
{
       
    public void act() 
    {
        // Add your action code here.
    }
    
    public void oeffnen()
     {K8055D.openDevice(0);}     or    {K8055D.dll.openDevice(0);)
     
    public void setzLampe1()
     {K8055D.SetDigitalChannel(1);}
    public void setzLampe2()
     {K8055D.SetDigitalChannel(2);}
    public void setzLampe3()
     {K8055D.SetDigitalChannel(3);}
  
compiler says: cannot find symbol – variable K8055D or package K8055D does not exist Following the advice of the documentation I „placed native binaries (.dll, .so and .jnilib) files in the root folder of the scenario“.
davmac davmac

2013/11/5

#
I think you misunderstand. A dll cannot implement a Java class, only methods, and to do so properly it must be JNI conformant. .You can't just call any arbitrary dll from Java code. You may be able to write your own JNI "bridge" library to interface between Java and a third-party dll. See the JNI documentation or the Wikipedia article.
mjrb4 mjrb4

2013/11/6

#
As davmac says, you'd need a JNI conformant wrapper to call this DLL (or any). Also bear in mind that when you succumb to JNI then you instantly forfeit Java's cross platform ability - so it won't magically work on non-windows systems in this case. That aside, in many cases (including this) you can usually find a JNI wrapper that someone else has written and published. As luck would have it, I've actually used this board in the past (built it from a kit a long time ago, before Arduino's became popular!) and used it with Java, so I can confirm it's definitely possible. I used this wrapper (http://k8055-java-wrap.sourceforge.net/) which worked well and did everything I needed it to, which admittedly wasn't much, but I certainly didn't encounter any serious bugs along the way.
You need to login to post a reply.