Re: [xSocket-develop] nbc and reading incomming frames with bytes
Status: Inactive
Brought to you by:
grro
|
From: <jun...@wp...> - 2008-12-02 10:07:54
|
Hi Gregor,<br>
<br>
I get strange output. <br>
<br>
If I expect F0 C1 01 01 01 81 00 I get 1007d 1007d 81 81 81 1007d 0 <br>
If I expect F0 C1 01 01 01 81 01 I get 1007d 1007d 81 81 81 1007d 81<br>
<br>
Do You know maybe what could be a reason ? It is correct that there is
7 bytes and the last one changes but where does those funny values came
from? I tried readStringByLength(available) and I get same wrong
output. Maybe function stringToHex doesn't work properly? Is it
possible to get Hex values from ByteBuffer[] directly?
DataConverter.toHexString(data) won't work.<br>
<br>
I wrote<br>
<br>
if (available > 0) {<br>
ByteBuffer[] data = nbc.readByteBufferByLength(available);<br>
String s = DataConverter.toString(data);<br>
System.out.println(stringToHex(s));<br>
return true;<br>
<br>
//and I use this function to convert to Hex<br>
<br>
public static String stringToHex(String base)<br>
{<br>
StringBuffer buffer = new StringBuffer();<br>
int intValue;<br>
for(int x = 0; x < base.length(); x++)<br>
{<br>
int cursor = 0;<br>
intValue = base.charAt(x);<br>
String binaryChar = new String(Integer.toBinaryString(base.charAt(x)));<br>
for(int i = 0; i < binaryChar.length(); i++)<br>
{<br>
if(binaryChar.charAt(i) == '1')<br>
{<br>
cursor += 1;<br>
}<br>
}<br>
if((cursor % 2) > 0)<br>
{<br>
intValue += 128;<br>
}<br>
buffer.append(Integer.toHexString(intValue) + " ");<br>
}<br>
return buffer.toString();<br>
}<br>
<br>
<br>
<br><br /><br /><br />----------------------------------------------------<br />Czujesz związek z Kopernikiem?! :)<br />Sprawdź swoje korzenie na bliscy.pl<br />Zbuduj drzewo swojej rodziny: <br /><A HREF="http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/bliscy.html&sid=565" TARGET="_blank">http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/bliscy.html&sid=565</A>
|