Hello Pierre,
I understand your Example. I can run it if I change it to Scilab sci=new Scilab(false) without graphics. How do I use the thread class Idle and the ScilabManager Class with the Example to make it run ?

Like that ?
...
public class Main {
    static boolean bgraph;
    public static void main(String[] args){
*Idle newThread= new Idle(???);
    Idle.run();
*    ...further with your Example

Moreover my compiler dosen't know types /classes in Idle and Scilab Manager. Which imports/librarys do I need ?

Thank You So Much,
Daniel

Am 15.02.2017 um 11:21 schrieb Perrichon:

Hello Daniel,

Here is a basic program I’ve realized under netbeans 7.01

It works with scilab x64 windows 7 or 10, scilab 5.5.2 ; not with 6.0.0 b2

Also here are the libraries to incilude in your java project (eclipse if i well understood) :

org.scilab.modules.jvm.jar

org.scilab.modules.javasci.jar

org.scilab.modules.core.jar

org.scilab.modules.types.jar

JDK1.8

It works with jdk1.8.0_40

//----------------------------------------------------------------------------------------------------------------------------------------------------

// Java program and main program

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package testscilabv2;

import org.scilab.modules.javasci.Scilab;

import org.scilab.modules.types.ScilabType;

import org.scilab.modules.types.ScilabDouble;

/**

*

* @author pierre

*/

public class TestScilabV2 {

    static boolean bgraph;

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

        try {

Scilab sci = new Scilab(true);

if (sci.open()) {

       /* Send a Scilab instruction */

sci.exec("foo = [ 2, 4, 6; 4, 0, 10; 6, 10, 12 ];");

/* Retrieve the variable foo */

ScilabType foo = sci.get("foo");

/* Display the variable */

          System.out.println("Representation of  : " + foo);

/* Get the data and retrieve the 2,2 value */

double[][] aReal = ((ScilabDouble)foo).getRealPart();

System.out.println("foo[1,1] = " + aReal[1][1]);

/* Change the value of 2,2 */

aReal[1][1] = Math.PI;

/* Create a new variable */

ScilabDouble bar = new ScilabDouble(aReal);

/* Send it to Scilab */

sci.put("bar", bar);

/* Display it through Scilab */

sci.exec("disp(bar)");

sci.exec("about();");

sci.exec("plot3d();");

System.out.println("\nFermer le grahique pour terminer le programme de test...");

do {

// Boucle tant que le graphique n'a pas été refermé

//-------------------------------------------------

bgraph=sci.isGraphicOpened();

       sci.exec("aPPeScilabJavasciv2=1;");

}while (bgraph);

sci.close();

System.out.println("...Fin du programme de test");

} else {

System.out.println("Could not start Scilab ");

}

/* Can be improved by other exceptions: AlreadyRunningException,

* InitializationException, UndefinedVariableException,

* UnknownTypeException, etc

*/

} catch (org.scilab.modules.javasci.JavasciException e) {

System.err.println("An exception occurred: " + e.getLocalizedMessage());

}

    }

}

*De :*Daniel Neutzler [mailto:daniel.neutz...@haw-hamburg.de]
*Envoyé :* lundi 13 février 2017 13:07
*À :* Perrichon <perrichon.pie...@wanadoo.fr>; 'Users mailing list for Scilab' <users@lists.scilab.org>
*Objet :* Re: [Scilab-users] Question about javasci V2

Hello Pierre,
thank you for your answer. It is nice to hear that my Problem is probably a Bug. I'm not sure how to use your example. Which Libs do I need for it or may you have a simple example to use it?
I'm sorry, my Java knowlegde is restricted (Beginner).

Thank You for your Help,
Daniel Neutzler

Am 04.02.2017 um 19:29 schrieb Perrichon:

    Hello Daniel

    I’ve already met your problem one year ago, and for me it is
    really a bug.

    I work with scilab x64 5.5.2, netbeans 7.01, on W7 or W10 platform.

    I’ve sovled it in my application, so I’m just able to propose
    parts of code.

    I’ve delay the 2 instructions *Scilab sci = new Scilab(true)* and
    if (sci.open()) {, by creating a ScilabManager class, … and a
    thread class named  Idle

    Part of ScilabManager  (also note the  public static void
    OpenScilab())

    public class ScilabManager {

        public static Scilab sci;       //Driver Scilab

    public static boolean bScilabOpen;

    public static boolean InitScilab;

    public  static Fifo FifoScilab;

    private static TListeFifo SciJob;

    static ScilabError TErrorScilab;

    public static File ScilabFile;

    private static int dim = 500;

    public static String [] Script;

    private static int iScript;

        public static Configuration AppConfiguration;

        public static Log LogScilab;

        public static int NumGraph=0;

    ScilabManager() {

    try {

    sci = new Scilab(true);

    InitScilab=true;

           } catch (JavasciException.InitializationException ex) {

    Logger.getLogger(ScilabManager.class.getName()).log(Level.SEVERE,
    null, ex);

    }

        }

        @SuppressWarnings("CallToThreadDumpStack")

    public static void OpenScilab() {

            try {

                bScilabOpen=sci.open();

            } catch (JavasciException ex) {

    ex.printStackTrace();

    }

            if (bScilabOpen) System.out.println("\nScilab est ouvert\n");

    else System.out.println("\nErreur ouverture Scilab\n");

            ScilabError.ClearScilabError();

            try {

    // Initialisation et chargements des fonctions Scilab

    //---------------------------------------------------

    AppConfiguration = new Configuration();

    } catch (FileNotFoundException ex) {

          Logger.getLogger(ScilabManager.class.getName()).log(Level.SEVERE,
    null, ex);

    } catch (IOException ex) {

    Logger.getLogger(ScilabManager.class.getName()).log(Level.SEVERE,
    null, ex);

    } catch (JavasciException ex) {

       Logger.getLogger(ScilabManager.class.getName()).log(Level.SEVERE,
    null, ex);

    }

            try {

    // Initialisation du fichier de log out (Traces commandes Scilab)

    //--------------------------------------------------------------

    LogScilab = new Log();

    OptsimView.SetLogFile();

    } catch (FileNotFoundException ex) {

    ex.printStackTrace();

    } catch (IOException ex) {

    ex.printStackTrace();

    }

            Script = new String[dim];

    Now note part of Idle task :

    public class Idle extends Thread  {

        protected volatile boolean IdleRunning = true;

    public static boolean bCloseIdle=false;

        private static int Count=1;

    private static int setGraphe=0;

      private static JTextField TF=null;

    private static Timer bTimer;

    private static JLabel AnimationLabel;

    private static Icon idleicone;

    private int ThreadNumber;

    Idle (JTextField TFi, Timer busyIconTimer,

    JLabel statusAnimationLabel, Icon icone) {

    TF=TFi;

    bTimer=busyIconTimer;

    AnimationLabel=statusAnimationLabel;

    idleicone=icone;

    this.ThreadNumber=Count++;

    }

    @Override

    public synchronized void run() {

        boolean bTest;

        if (ScilabManager.InitScilab) {

                ScilabManager.OpenScilab();

    }

        ScilabManager.sci.exec("aPPeScilabJavasciv2=1;");

        while (IdleRunning) { …etc

    So instructions *Scilab sci = new Scilab(true)* and if (sci.open
    are delayed.

    This is the only solution I’ve found. After that Scilab well run
    with Java netbeans and javasci2.

    Also well note that my program doesn’t work with Scilab 6.0.0 b2
    at compile time and see :

    http://bugzilla.scilab.org/show_bug.cgi?id=14626

    Hope it helps you

    Sincerely

    Pierre

    *De :*users [mailto:users-boun...@lists.scilab.org] *De la part
    de* Daniel Neutzler
    *Envoyé :* mardi 31 janvier 2017 13:15
    *À :* users@lists.scilab.org <mailto:users@lists.scilab.org>
    *Objet :* [Scilab-users] Question about javasci V2

    Hi, I am using Scilab 5.5.2 and trying to open a Scilab script from
    Java. Therfore I followed the documentation: Compute and run with
    javasci v2.

    I use Eclipse to compile and run. It works, but I want now to open
    it in "advanced mode"  to get grahpics
    (*Scilab sci = new Scilab(true);*). If i do it, I get a compile
    Error. What's wrong ?
    Code and Error Plot out see below.

    Thank You for your Help,
    Daniel Neutzler

    ####Error####
    java.lang.ExceptionInInitializerError
        at
    org.scilab.modules.commons.xml.XConfiguration.<clinit>(Unknown Source)
        at org.scilab.modules.core.Scilab.<clinit>(Unknown Source)
        at
    org.scilab.modules.javasci.Call_ScilabJNI.Call_ScilabOpen(Native
    Method)
        at
    org.scilab.modules.javasci.Call_Scilab.Call_ScilabOpen(Unknown Source)
        at org.scilab.modules.javasci.Scilab.open(Unknown Source)
        at StartUp.main.main(main.java:17)
    Caused by: java.lang.NullPointerException
        at java.io.File.<init>(Unknown Source)
        at org.scilab.modules.commons.ScilabConstants.<clinit>(Unknown
    Source)
        ... 6 more
    Exception in thread "main"

    #### JAVA Code####

    package StartUp;
    *import org.scilab.modules.javasci.Scilab;
    import org.scilab.modules.types.ScilabType;*
    import java.io.File;
    import java.io.FileNotFoundException;

    public class main {

        public static void main(String[] args) throws
    FileNotFoundException{
            System.out.println("Starte Programm
    Pin-Positionsanalyse-Tool V1.0...");

            try {
    *Scilab sci = new Scilab(true); // Starts in advanced mode *
                if (sci.open()) {
                sci.execException(new
    File("C:/Users/Daniel/Desktop/test.sce"));
                sci.close();
                 } else {
                     System.out.println("Could not start Scilab ");
                 }
        /* Can be improved by other exceptions: AlreadyRunningException,
        * InitializationException, UndefinedVariableException,
        * UnknownTypeException, etc
        */
             } catch (org.scilab.modules.javasci.JavasciException e) {
                 System.err.println("An exception occurred: " +
    e.getLocalizedMessage());
             }
        }
    }


_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to