kramann.info
© Guido Kramann

Login: Passwort:










Informatik3
1 Vom_struct_zur_Klasse
..1.1 Vom_struct_zur_Klasse
..1.2 struct_Programm
..1.3 Klassen_Programm
..1.4 Offene_Fragen
..1.5 Historie
..1.6 Objektabstraktion
..1.7 OO_Kundenverwaltung
..1.8 Objektfaehigkeiten
..1.9 Formatierung
..1.10 Motivation
..1.11 Uebung1
..1.12 Uebung2
2 UML
..2.1 Volumenberechnung
..2.2 UML_Klassendiagramm
..2.3 Konstruktor
..2.4 Statische_Variable
3 Strings
..3.1 Klassenbibliotheken
..3.2 stringUML
..3.3 Uebung3
4 Initialisierungen
4 bluej
5 Zeiger_und_Arrays
..5.1 Zeiger
..5.2 Zeiger_und_Funktion
..5.3 Uebung4
6 Vererbung
..6.1 MesswerteUML
..6.2 MesswerteProgramm
..6.3 VererbungsProgramm
..6.4 Vector
..6.5 Uebung
7 Modifikatoren
..7.1 public_Vererbung
..7.2 protected_Vererbung
8 Listen_und_Templates
..8.1 Containertypen
....8.1.1 ListeUML
....8.1.2 ListeProgramm
..8.2 Templates
....8.2.1 Listentemplate
....8.2.2 STLvectorTemplate
..8.3 Uebung5
..8.4 Uebung6
..8.5 Uebung7
9 Java
..9.1 Uebung
..9.2 GettingStarted
..9.3 Animation
..9.4 Hybrid
..9.5 Threads
10 Delegation
11 LayoutProjekt
12 Fenster
13 Uebung
14 Zwischenprojekt
..14.1 Befehle
..14.2 Planung
..14.3 JNI
..14.4 JNIumsetzen
..14.5 Anwendungsklasse
..14.6 GUI01
..14.7 GUI02
15 Rasterlayout
..15.1 Bilder_Packages
..15.2 interfaces
..15.3 ArrayList
..15.4 clone
..15.5 Uebung
16 Nuetzliches
..16.1 Threads
..16.2 Animation
..16.3 RungeKutta
..16.4 Loesungsansatz
..16.5 Internetprogrammierung
....16.5.1 Codegenerierung
....16.5.2 PHP_Programmierung
....16.5.3 PHP_OOP
....16.5.4 Java
17 Algorithmen
..17.1 RungeKutta
..17.2 Loesungsansatz
..17.3 Evoopt
..17.4 Uebung12
..17.5 Uebung8_2014
..17.6 Ausdruecke
18 Uebung10
19 UML_ALT
..19.1 Flaechenberechnung
..19.2 UML_Flaechenberechnung
..19.3 Implementierung
..19.4 ListeUML
..19.5 ListenImplementierung
..19.6 Anwendung
kramann.info
© Guido Kramann

Login: Passwort:




JNI - Java Native Interface

(EN google-translate)

(PL google-translate)

An einem konkreten Beispiel wird gezeigt, wie der Weg aussieht von einem C-Programm, das Konsolenbefehle ausführt zu einem Java-Programm, das eine Native-Funktion aufruft.

avrdude -c ponyser -p m32 -P /dev/ttyS0 -v

Code 0-1: Konsolenbefehl.

Der Konsolenbefehl liefert beispielsweise folgende Ausgabe, wenn ein Mikrocontroller richtig verbunden ist:

avrdude: Version 5.5, compiled on Jan 14 2009 at 06:21:50
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/ttyS0
         Using Programmer      : ponyser
         AVR Part              : ATMEGA32
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PA0
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

         Programmer Type : SERBB
         Description     : design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502
avrdude: safemode: lfuse reads as FD
avrdude: safemode: hfuse reads as D9

avrdude: safemode: lfuse reads as FD
avrdude: safemode: hfuse reads as D9
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Code 0-2: Konsolenausgabe zu obigem Befehl.

Durch folgende Ergänzung ist es möglich die Ausgabe auf dem Standardkanal in die Datei out.txt umzuleiten und die Ausgabe auf dem Fehlerkanal in die Datei err.txt. Diese Technik nennt man "pipen". Als absoluter Pfad wird /mnt-system gewählt:

avrdude -c ponyser -p m32 -P /dev/ttyS0 -v > /mnt-system/out.txt 2> /mnt-system/err.txt

Code 0-3: Konsolenbefehl mit Umleitung der Ausgaben in die Dateien out.txt und err.txt:

Wenn ein Mikrocontroller richtig angeschlossen ist, findet sich in den Dateien z.B. folgendes:

avrdude: safemode: lfuse reads as FD
avrdude: safemode: hfuse reads as D9
avrdude: safemode: lfuse reads as FD
avrdude: safemode: hfuse reads as D9

Code 0-4: out.txt bei korrekt verbundenem Mikrocontroller.

avrdude: Version 5.5, compiled on Jan 14 2009 at 06:21:50
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/ttyS0
         Using Programmer      : ponyser
         AVR Part              : ATMEGA32
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PA0
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

         Programmer Type : SERBB
         Description     : design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Code 0-5: err.txt bei korrekt verbundenem Mikrocontroller.

Wird die Versorgungsspannung des Mikrocontrollers unterbrochen, oder das Programmiergerät entfernt, liefert der gleiche Aufruf folgendes:



Code 0-6: out.txt bei NICHT korrekt verbundenem Mikrocontroller. (Datei ist leer.)

avrdude: Version 5.5, compiled on Jan 14 2009 at 06:21:50
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/ttyS0
         Using Programmer      : ponyser
         AVR Part              : ATMEGA32
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PA0
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

         Programmer Type : SERBB
         Description     : design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Code 0-7: err.txt bei NICHT korrekt verbundenem Mikrocontroller.

Um also festzustellen, ob der Mikrocontroller korrekt verbunden ist, kann einfach überprüft werden, ob out.txt leer ist. Das folgende C-Programm nutzt genau dies, um eine Aussage zu treffen, ob der Mikrocontroller angeschlossen ist:

#include <stdlib.h>
#include <stdio.h>

int main()
{
    FILE* f;
    int i=0;
    int c;
    char *puffer;
    int anz;

    const char* befehl = "avrdude -c ponyser -p m32 -P /dev/ttyS0 -v > /mnt-system/out.txt 2> /mnt-system/err.txt";

    //Eventuell zuvor vorhandene Dateien out.txt und err.txt löschen:
    system("rm -f /mnt-system/out.txt");
    system("rm -f /mnt-system/err.txt");    

    //Befehl aufrufen:
    system(befehl);

    //Zählen, wieviele Zeichen in out.txt vorhanden sind:
    f = fopen("/mnt-system/out.txt","r");
    c = fgetc(f);
    anz=0;    
    while(c>=0)
    {
        //puffer[anz]=c;
        c = fgetc(f);
        anz++;
    }
    fclose(f);    

    printf("Die Datei out.txt enthaelt %i Zeichen.\n",anz);

    system(befehl);
}

Code 0-8: avrangeschlossen.c - Einfaches C-Programm, um zu prüfen, ob ein Mikrocontroller korrekt angeschlossen ist.