0

I have an incoming 11 bytes of data per send. It always begins with 0A 52 which identifies the device. The remaining is as so:

0A 52 08 01 01 01 00 C1 20 02 59 

52 Packettype    
08 subtype       
01 Sequence nbr  
01 01 ID            
00 C1 SenseT
20 SenseH
02 Status         
5  level  
9  PwrLvl

As there is no CR/LF what is the best way to read in the 11 bytes making sure it begins with 0A 52 and still being able to split the final byte into nibbles.

Thanks for your help.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
DevilCode
  • 1,054
  • 3
  • 35
  • 61
  • 1
    The SO question - [Reading Serial Port in Java](http://stackoverflow.com/questions/336714/reading-serial-port-in-java) is a good starting point, the example given can easily be modified to read 11 bytes instead of 8. – Perception Jan 30 '13 at 07:47
  • javax.comm has more or less been depreciated from my understanding. – DevilCode Jan 30 '13 at 08:06
  • Deprecated? I don't think so. You may need to use a third party implementation of the API though, depending on your platform. See [RXTX](http://rxtx.qbang.org/wiki/index.php/Main_Page). – Perception Jan 30 '13 at 09:02
  • Yes that's what i'm using rxtx from qbang.org. – DevilCode Jan 30 '13 at 10:19

1 Answers1

0

while ( ( len = this.in.read(buffer,0,1)) > -1 )

Setting the length of bytes to read to 1 will solve the problem. See: http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read(byte[], int, int)

This explains it better than I could.

Afshin Moazami
  • 2,092
  • 5
  • 33
  • 55
DevilCode
  • 1,054
  • 3
  • 35
  • 61