Closed GoogleCodeExporter closed 9 years ago
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 scream3r.org@gmail.com
on 7 Oct 2011 at 5:26
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 arthur.m...@googlemail.com
on 11 Oct 2011 at 7:40
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 scream3r.org@gmail.com
on 12 Oct 2011 at 5:06
Original comment by scream3r.org@gmail.com
on 23 Nov 2011 at 4:21
Muy bueno ese ultimo metodo me sirbio de mucho
saludos.
Original comment by JhonMast...@gmail.com
on 22 Oct 2014 at 12:14
Original issue reported on code.google.com by
arthur.m...@googlemail.com
on 6 Oct 2011 at 8:11