<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="http://forum.robosavvy.com/feed.php?f=5&amp;t=2264" />

<title>RoboSavvy Forum</title>
<subtitle>Robosavvy Forum: The largest online community of Humanoid Robot Builders</subtitle>
<link href="http://forum.robosavvy.com/index.php" />
<updated>2008-02-20T19:28:26+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=5&amp;t=2264</id>
<entry>
<author><name><![CDATA[JavaRN]]></name></author>
<updated>2008-02-20T19:28:26+01:00</updated>
<published>2008-02-20T19:28:26+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=2264&amp;p=14277#p14277</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=2264&amp;p=14277#p14277"/>
<title type="html"><![CDATA[Zig-bee a note to Java Programmers]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=2264&amp;p=14277#p14277"><![CDATA[
I've just finished my first communication program through Zig-bee with the CM-5.  I would like to mention a few important points for those of you who will eventually use Java to communicate with CM-5 using zig-bee.<br /><br />Java's byte type is an 8-bit signed two's complement number so if you need to send a packet using an array of bytes you have to follow the same format using &quot;different numbers&quot;, so if you are going to send the number 10 to the CM-5 use the array:<br /><br />{-1, 85, 10, -11, 0, -1}<br /><br />note that while writing your Java program you cannot use the hexadecimal 0xFF in the array since it will be treated as an integer and you'll get a compile time error, that's why you need to use -1.  So as a general rule you can follow the following method for sending a packet using the byte type in Java:<br /><br />1. Start with -1 and 85 which are the header.<br />2. Get the LSB to send. say 64, that would be the third number<br />3. Add one to it and make it negative (-65) that would be the fourth number.<br />4. Do the same with the MSB, if you don't have anything to send then add 0 and -1.  So sending the number 64 to the CM-5 through zig-bee would involve the following array:<br /><br />{-1, 85, 64, -65, 0, -1}<br /><br /><br />Of course this method works with positive numbers up to 127.  If you have bigger positive numbers then you have to modify steps 2, 3, and 4 above<br /><br />So if you want to send 200 for LSB, you have to:<br />1. Subtract 200 (or the number you have) from 256 and add negative to it.  In this case you will end up with -56.<br />2. the fourth number would be a positive number which is one less than the previous number, so in this case it would be 55.<br />3.  Apply the same principle to the MSB.<br /><br />So if you want to send the number 200 in the LSB, you have to send:<br /><br />{-1, 85, -56, 55, 0, -1}<br /><br />Or else if you want to avoid all this math you can work with an array of int and then typecast each item to a byte.  However you might encounter some problems when receiving data especially data which is bigger than 127.<br /><br />Hope this helps Java Bioloid programmers out there.<br /><br /><br />Note: I got the Zig-bee packet information from <a href="http://www.bipedrobots.co.uk/blindex.aspx?id=328" class="postlink">http://www.bipedrobots.co.uk/blindex.aspx?id=328</a><br /><br />Charles<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=546">JavaRN</a> — Wed Feb 20, 2008 7:28 pm</p><hr />
]]></content>
</entry>
</feed>