rodel-talampas / java-simple-serial-connector

Automatically exported from code.google.com/p/java-simple-serial-connector
0 stars 0 forks source link

No reading from port #59

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

import jssc.SerialPort;
import jssc.SerialPortException;
import java.lang.NullPointerException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import jssc.SerialPortEvent;
public class Main
{
    static byte[] buffer;
    static String str;
    static SerialPortEvent event;

    public static void main(String[] args) throws IOException, UnsupportedEncodingException
    {
SerialPort serialPort = new SerialPort("/dev/ttyUSB0");
        try {
            serialPort.openPort();//Open serial port
            serialPort.setParams(115200, 8, 1, 0);//Set params.
            serialPort.writeBytes("AT+CMGR=1\r\n".getBytes());//Write data to port
str =  serialPort.readString();
 System.out.println("old = " + str);

serialPort.closePort();
}

Почему не вычитывается строка сообщения?
Как можно вычитывать без явного указания 
размера вычитки? Ведь сообщения разные 
могут приходить.

What is the expected output? What do you see instead?
answer is NULL.

Ответ - null;
В порт приходит (смотрю снифером) :
AT+CMGR=1

+CMGR: "REC READ","+79154041718",,"14/02/12,14:16:50+16"
Add1analog;return1message;

OK

если использовать 

str =  serialPort.readString(105);
System.out.println("105b = " + str);, то ответ 

105b = AT+CMGR=1

+CMGR: "REC READ","+79154041718",,"14/02/12,14:16:50+16"
Add1analog;return1message;

OK

What version of the product are you using? On what operating system?
2.8.0

Please provide any additional information below.

Original issue reported on code.google.com by kit...@gmail.com on 13 Feb 2014 at 9:08