Giter Club home page Giter Club logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
jSSC tested on FTDI and Prolific chips, and works correctly on it.

I wrote an example with your method, and it works fine:

public class Main {

    private static SerialPort serialPort;

    public static void main(String[] args) {
        serialPort = new SerialPort("COM15");
        try {
            serialPort.openPort();
            serialPort.setParams(9600, 8, 1, 0);
            while(true){
                System.out.println(getByte());
            }
        }
        catch (SerialPortException ex) {
            ex.printStackTrace();
        }
    }

    protected static byte getByte() throws jssc.SerialPortException {
        while (serialPort.getInputBufferBytesCount() < 1) {
            try {
                Thread.sleep(1);
                if (Thread.currentThread().isInterrupted()) {
                    return 0;
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                return 0;
            }
        }
        return (byte)(serialPort.readBytes(1))[0];
    }
}

Method getByte() blocks while input buffer is empty.

If you have not solve the problem, please mail me.

Original comment by [email protected] on 7 Oct 2011 at 5:26

from java-simple-serial-connector.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
I think that perhaps I did not express my question as clearly as I should have 
done.

The method serialPort.readBytes(1); does not block when there are no new bytes.
Should it block?
If it should block then there is a defect.
If it should not block then I have misunderstood how it works.

In my application I need a method which does block until a new byte is 
received. 
The method I suggested above does work for me successfully and the jSSC library 
seems to be very reliable.
I would consider fine tuning the line 
Thread.sleep(1);
if the baud rate of the interface is very slow.

Original comment by [email protected] on 11 Oct 2011 at 7:40

from java-simple-serial-connector.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
The method readBytes(1) will blocks if your input buffer is empty. If you have 
any data in input buffer this method will return the one byte from it.

If you need to know that you have any data in input buffer try to use 
EventListener (last example on this page: 
http://code.google.com/p/java-simple-serial-connector/wiki/jSSC_examples)

Original comment by [email protected] on 12 Oct 2011 at 5:06

from java-simple-serial-connector.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024

Original comment by [email protected] on 23 Nov 2011 at 4:21

  • Changed state: Fixed

from java-simple-serial-connector.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
Muy bueno ese ultimo metodo me sirbio de mucho
saludos.

Original comment by [email protected] on 22 Oct 2014 at 12:14

from java-simple-serial-connector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.