Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
F

Francesco Fraccaroli

@Francesco Fraccaroli
About
Posts
4
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Java GUI programming
    F Francesco Fraccaroli

    Dear Richard, Thanks for your reply, I'll study about the two patterns you suggested me. For public variables, I show my problem: I want to write data on RS232 port, wait a reply, read data arrived and elaborate them. I create a SerialPort object using RxTx libraries and I setted a Listener to it. In my main class, a method write the data on the serial port and then wait on a Condition variable. The listener have to notify to the waiting method the arrival of the data. The two methods are on completely different classes, so I thought to make the condition variable global. Unfortunately, at now the program doesn't work. What shall be the right way to do solve kind of problem? Francesco

    Java question java sysadmin help

  • Java GUI programming
    F Francesco Fraccaroli

    Hi programmers, I'm working on a Java project that has a graphical interface and do some other stuffs, as serial/network communication, calculations, etc. In your experience, what is the right way to start? Start from the GUI and then program all the functions, or create all the backgrounds method and classes and then program the GUI? Another issue: you normally prefer to make some variables public or to pass them all as parameters? I'm a bit confused, expecially for Listeners. Thanks, Francesco

    Java question java sysadmin help

  • [SOLVED] SerialPort and Thread: can't read from the input stream.
    F Francesco Fraccaroli

    Dear Richard, thanks for the reply. I made the thread runnable by "implements Runnable" on the "Lettore" class definition, now it works. Thank you very much! The final code is this:

    public class Lettore implements Runnable {

    SerialPort port;
    
    public Lettore(SerialPort port) throws IOException {
        this.port = port;
    }
    
    @Override
    public void run() {
        byte\[\] buffer = new byte\[1024\];
        int len = -1;
            try {
            while (true) {
                //read, write on terminal, echo.
                len = port.getInputStream().read(buffer);
                System.out.print(new String(buffer, 0, len));
                if (len != 0) {
                    port.getOutputStream().write(buffer, 0, len);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    }

    Java help question

  • [SOLVED] SerialPort and Thread: can't read from the input stream.
    F Francesco Fraccaroli

    Hi colleague developers, I've got a problem in communicating with serial port. In my applcation I have to receive some data from the serial port and to manage them for some operation. For now I'm just trying to write out the data received. I've create a test class with main() that manage the connection (open the port, set the parameters) and starts a thread. The thread is started in this manner:

        try {
            (new Thread(new Lettore(port), "Lettore")).start();
        } catch (Exception e) {
            System.err.println("Errore " + e);
        }
    

    where the "port"parameter is the SerialPort object. The "Lettore" class contains the follow:

    SerialPort port;
    
    public Lettore(SerialPort port) throws IOException {
        this.port = port;
    }
    
    @Override
    public void run() {
        byte\[\] buffer = new byte\[1024\];
        int len = -1;
            try {
            while (true) {
                //read, write on terminal, echo.
                len = port.getInputStream().read(buffer);
                System.out.print(new String(buffer, 0, len));
                if (len != 0) {
                    port.getOutputStream().write(buffer, 0, len);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    }

    In this case, the code in the thread seems to be never executed: no characters are show on the terminal and on the other station of the communication. On the other hand, if I write the same code of the run() function in the main, it works fine. Someone has ever got this problem? Can anyone help me?

    Java help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups