<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Moving long integers over Serial</title>
		<link>http://forums.leaflabs.com/topic.php?id=940</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:09:48 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=940" rel="self" type="application/rss+xml" />

		<item>
			<title>dreamcat4 on "Moving long integers over Serial"</title>
			<link>http://forums.leaflabs.com/topic.php?id=940#post-5811</link>
			<pubDate>Sat, 30 Jul 2011 11:51:12 +0000</pubDate>
			<dc:creator>dreamcat4</dc:creator>
			<guid isPermaLink="false">5811@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi there. A while ago I updated and re-released the Arduino CmdMessenger library. It provides a simple framework for sending structured binary data over the Serial link. Its possible to write a callback function which decodes some aribrary series of bytes into one or more integer data / mixed data. The data payload should be encoded into base64 to avoid potential collisions with the control characters (eg the command-termination character, and field separator are ASCII, and so each occupy one 255 byte value, plus newline \r and linefeed \n). Full instructions at the README file on its github page. Note: nobody has tested it yet on a Maple, corrections welcome.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>x893 on "Moving long integers over Serial"</title>
			<link>http://forums.leaflabs.com/topic.php?id=940#post-5802</link>
			<pubDate>Fri, 29 Jul 2011 18:00:32 +0000</pubDate>
			<dc:creator>x893</dc:creator>
			<guid isPermaLink="false">5802@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You know many new if see .disas file
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "Moving long integers over Serial"</title>
			<link>http://forums.leaflabs.com/topic.php?id=940#post-5801</link>
			<pubDate>Fri, 29 Jul 2011 16:28:44 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">5801@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You can easily create a #define macro that'll do this for you:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;#define makeLong(msb, byte2, byte3, lsb) ((msb &#38;lt;&#38;lt; 24) &#124; (byte2 &#38;lt;&#38;lt; 16) &#124; (byte3 &#38;lt;&#38;lt; 8) &#124; (lsb))&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;A more robust - yet slower version:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;#define makeLong(msb, byte2, byte3, lsb) (((msb &#38;amp; 0xff) &#38;lt;&#38;lt; 24) &#124; ((byte2 &#38;amp; 0xff) &#38;lt;&#38;lt; 16) &#124; ((byte3 &#38;amp; 0xff) &#38;lt;&#38;lt; 8) &#124; (lsb &#38;amp; 0xff))&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;For example, if you're sending the value &#60;code&#62;0x11223344&#60;/code&#62; MSB first over serial, you'll receive them as:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;uint8 byte1 = 0x11; // value first serial read
uint8 byte2 = 0x22; // value from second serial read
uint8 byte3 = 0x33; // etc.
uint8 byte4 = 0x44;

uint32 my_long = makeLong(byte1, byte2, byte3, byte4);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;If you're expecting 4 bytes to arrive, you can do something similar to this pseudo-code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;uint32 my_long = read first byte;
while(I&#38;#39;m still waiting for 3 more bytes)
{
    value = read next byte from serial
    my_long = (my_long &#38;lt;&#38;lt; 8) &#124; value
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;After you get your 4 bytes, you're done =]. This is also more scalable in the event you ever need to go to 64-bit numbers, or down to 16-bit numbers.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>JoshSanders on "Moving long integers over Serial"</title>
			<link>http://forums.leaflabs.com/topic.php?id=940#post-5800</link>
			<pubDate>Fri, 29 Jul 2011 16:05:28 +0000</pubDate>
			<dc:creator>JoshSanders</dc:creator>
			<guid isPermaLink="false">5800@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi guys!&#60;/p&#62;
&#60;p&#62;On my computer, I have some 32-bit integers I want to send to a Maple.&#60;br /&#62;
SerialUSB.read() reads one byte at a time into a local variable.&#60;br /&#62;
Is there a function something like Arduino's word(high_byte, low_byte) for reconstructing a long from four sequentially read bytes on the Maple end? Or is there a better / more elegant way to go about this? If not, I'll need to write my own function... something like&#60;/p&#62;
&#60;p&#62;long NewLongInt = makeLongInt(HighestByte, HighByte, LowByte, LowestByte)&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Josh
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
