سؤال

I am trying to read serial using Java:

    byte[] text = new byte[5];
    for(int i = 0;i<5;i++){
        text[i] = (byte)in.read();
    }

For some reason it returns me some weird data. I have tried libraries like RXTX and COMM, but other issues comes then. Is there some way to read everything in raw Java way? Any code snippets would be helpful.

Thanks

هل كانت مفيدة؟

المحلول

The problem is that Byte is just too narrow for this data serial data(because it is signed), so I do loose most significant bit. Solution is to read everything to int.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top