I have a Java code that uses Java ME8 on the Raspberry P (RPI) board, code on the RPI device Communicates with using serial communication Data is changed in the context of the frames.
When getting the data from the device to the RPI, the getInputStream.read (byte [] byte) is hanged and the code is hanged. And I am unable to implement the timeout, for example while loop Say, if I rcecive nothing for more than 40 seconds, it should end.
My code is:
Private zero receive packets (long timeout) throws IOException {// timeOut = 120; Arrays.fill (awkByte, (byte) 0x00); Arrays.fill (rec, (byte) 0x00); Println ("Received"); I = 0; K = 0; // bases a byte array to get data // acabyte [0] = (byte) 0xFF; Int num = 0; Long X = 0; X = System.currentTimeMillis (); While (system.startTimeMillis () & lt; = (x + timeOut)) {Arrays.fill (awkByte, (byte) 0x00); Num = 0; System.out.println ("while" in); K = 0; Num = connection.getInputStream (). Read (awkByte); if (num & lt; = 0) {brake;} System.out.println (" Num: "+ num"; while (num> gt; 0) {rec [i] = awkByte [k]; i ++; k ++; num--;}} System.out.println ("Received:" ); (Int J = 0; J & LT; REC Long; J ++) {System.out.print (REC [J] + "T \");}}
FYI: I am not using any multithreading in my code.
And I'm getting a number of bytes and the loop is finished or read ().
ago Then read.
if (connection .getInputStream (.) Available ()> 0) {num = connection.getInputStream (.) Read (awkByte);} and {// do something Is?}
जावा कार्यक्रम छात्रों के लिए उदाहरण है
ReplyDeleteलेबल नमूना कोड का उपयोग करना