<?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: SerialUSB.read() problem fixed</title>
		<link>http://forums.leaflabs.com/topic.php?id=894</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:09 +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=894" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-12073</link>
			<pubDate>Fri, 27 Jul 2012 16:44:51 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12073@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Strange. Do you get this error reliably?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rjacquier on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-12023</link>
			<pubDate>Thu, 26 Jul 2012 06:37:01 +0000</pubDate>
			<dc:creator>rjacquier</dc:creator>
			<guid isPermaLink="false">12023@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;This post is a little old, but I'm getting the same error as kanne.&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;Kane&#60;/strong&#62; was getting this error: &#34;error resetting after download: libusb0-dll:err [reset] could not reset device, win error: Das System kann die angegebene Datei nicht finden.&#34;&#60;/p&#62;
&#60;p&#62;except mine is in english: &#34;error resetting after download: libusb0-dll:err [reset] could not reset device, win error: The system cannot find the file specified.&#34;&#60;/p&#62;
&#60;p&#62;I'm getting the same with Window 7 64 bit too.&#60;/p&#62;
&#60;p&#62;What is causing this issue?&#60;br /&#62;
btw: I used the win 7 work-around for the driver signing issue. (&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=73#post-788&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=73#post-788&#60;/a&#62;)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5765</link>
			<pubDate>Wed, 27 Jul 2011 05:25:51 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5765@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;the success of the auto-reset on program seems to indicate that you had the USB pipe working ok. But to make sure, do you have the correct COM port selected in the tools-&#38;gt;serial port drop down?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kanne on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5660</link>
			<pubDate>Thu, 14 Jul 2011 15:15:28 +0000</pubDate>
			<dc:creator>kanne</dc:creator>
			<guid isPermaLink="false">5660@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I use Window 7 64 bit. I try this:&#60;/p&#62;
&#60;p&#62;// a more complicated but 100% functional echo server&#60;br /&#62;
#include &#34;usb.h&#34; // gives us access to libmaple usb functions&#60;/p&#62;
&#60;p&#62;void setup()&#60;br /&#62;
{&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop()&#60;br /&#62;
{&#60;br /&#62;
    int newbytes = SerialUSB.available();&#60;/p&#62;
&#60;p&#62;    if ( !newbytes )&#60;br /&#62;
        return;&#60;/p&#62;
&#60;p&#62;    char buf[65];&#60;/p&#62;
&#60;p&#62;    // newbytes will never be &#38;gt; 64&#60;br /&#62;
    usbReceiveBytes((uint8*)buf,newbytes);&#60;br /&#62;
    buf[newbytes] = 0; // set the last char to 0 to create a null terminated string&#60;br /&#62;
    SerialUSB.print(buf);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;After uploading:&#60;/p&#62;
&#60;p&#62;Going to build using 'armcompiler' (ARM)&#60;br /&#62;
	Compiling core...&#60;br /&#62;
	No libraries to compile.&#60;br /&#62;
	Compiling the sketch...&#60;br /&#62;
	Linking...&#60;br /&#62;
	Computing sketch size...&#60;/p&#62;
&#60;p&#62;C:\Users\kanne\AppData\Local\Temp\build8546768095020471328.tmp\sketch_jul14a.cpp.bin  :&#60;br /&#62;
section    size   addr&#60;br /&#62;
.data   12616      0&#60;br /&#62;
Total   12616&#60;/p&#62;
&#60;p&#62;Binary sketch size is reported above. Check it against a 108000 byte maximum.&#60;br /&#62;
Loading via dfu-util&#60;br /&#62;
Resetting to bootloader via DTR pulse&#60;br /&#62;
Searching for DFU device [1EAF:0003]...&#60;br /&#62;
Found it!&#60;/p&#62;
&#60;p&#62;Opening USB Device 0x1eaf:0x0003...&#60;br /&#62;
Found Runtime: [0x1eaf:0x0003] devnum=1, cfg=0, intf=0, alt=1, name=&#34;DFU Program FLASH 0x08005000&#34;&#60;br /&#62;
Setting Configuration 1...&#60;br /&#62;
Claiming USB DFU Interface...&#60;br /&#62;
Setting Alternate Setting ...&#60;br /&#62;
Determining device status: state = dfuIDLE, status = 0&#60;br /&#62;
dfuIDLE, continuing&#60;br /&#62;
Transfer Size = 0x0400&#60;br /&#62;
bytes_per_hash=252&#60;br /&#62;
Starting download: [##################################################] finished!&#60;br /&#62;
error resetting after download: libusb0-dll:err [reset] could not reset device, win error: Das System kann die angegebene Datei nicht finden.&#60;br /&#62;
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present&#60;/p&#62;
&#60;p&#62;Done!&#60;/p&#62;
&#60;p&#62;Resetting USB to switch back to runtime mode&#60;/p&#62;
&#60;p&#62;Then I opened a serial monitor with 9600 baud and entered s couple of line.&#60;br /&#62;
But no response from maple board.&#60;br /&#62;
I got the same result with 115200 baud.&#60;br /&#62;
The I disconnect the board and try again =&#38;gt; same result.&#60;/p&#62;
&#60;p&#62;Btw. on Linux the USB communication works fine.&#60;br /&#62;
For Windows I always use an FTDI to communicate over serial with the maple board.&#60;/p&#62;
&#60;p&#62;1) any idea whats wrong with USB on Windows 7 ?&#60;br /&#62;
2) is it possible to flash the board on Windows 7 without pressing the reset button ?&#60;br /&#62;
3) what does &#34;error resetting after download: libusb0-dll&#34; mean ? it always comes up after flashing.&#60;/p&#62;
&#60;p&#62;Thomas from CH
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5584</link>
			<pubDate>Thu, 07 Jul 2011 12:58:53 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5584@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ahh..yes
&#60;/p&#62;</description>
		</item>
		<item>
			<title>StephenFromNYC on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5580</link>
			<pubDate>Thu, 07 Jul 2011 12:05:19 +0000</pubDate>
			<dc:creator>StephenFromNYC</dc:creator>
			<guid isPermaLink="false">5580@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello-&#60;/p&#62;
&#60;p&#62;In the &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=894#post-5485&#34;&#62;above&#60;/a&#62; code (section &#34;1 Workaround&#34;) should the line read:&#60;/p&#62;
&#60;p&#62;usbReceiveBytes((uint8*)buf, newbytes);&#60;/p&#62;
&#60;p&#62;Thank you poslathian for the fixes!&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/profile.php?id=843&#34;&#62;Stephen from NYC&#60;/a&#62; (full disclosure: I am not a member of the LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5486</link>
			<pubDate>Fri, 01 Jul 2011 15:41:56 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5486@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;p.s. a little backstory here is that there USED to be a nice ring buffer on the serialusb buffer, but that had an odd bug that would lock it up on occasion and prevent new bytes from being received. We went through several iterations of it before just abandoning the ring buffer. The current version is dead simple - bytes come in from the usb port - and then all new bytes are refused until the current ones are read. Thus, it is most efficient to send and read 64 bytes at a time, which is the size of the hardware buffer for USB.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SerialUSB.read() problem fixed"</title>
			<link>http://forums.leaflabs.com/topic.php?id=894#post-5485</link>
			<pubDate>Fri, 01 Jul 2011 15:40:07 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5485@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You may have noticed a bug introduced in 0.0.9 whereby code like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;while(SerialUSB.available()) {
   SerialUSB.print(SerialUSB.read()); // should be an echo server
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;would sometimes give zany results. The problem has been solved. The problem was that consecutive calls to usbReadBytes (called by SerialUSB.read) just read the same bytes over and over again, and already-read bytes were not being dequeued.&#60;/p&#62;
&#60;p&#62; If you were having trouble with SerialUSB.read() you have three options:&#60;/p&#62;
&#60;p&#62;1) Workaround:&#60;br /&#62;
   instead of making consecutive calls to SerialUSB.read(), make a single call all the bytes in the buffer like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// a more complicated but 100% functional echo server
#include &#38;quot;usb.h&#38;quot; // gives us access to libmaple usb functions

char buf[65];
void loop() {
  int newbytes = 0;
   if (newbytes = SerialUSB.available()) { // newbytes will never be &#38;gt; 64
       usbReadBytes((uint8*)buf,newbytes);
       buf[newbytes] = 0; // set the last char to 0 to create a null terminated string
       SerialUSB.print(buf);
   }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;2) replace your usb.c file:&#60;br /&#62;
   in your maple-ide installation directory, locate:&#60;br /&#62;
     (maple-ide-x.x.x)/hardware/leaflabs/cores/maple/usb.c&#60;br /&#62;
   replace this file with this version:&#60;br /&#62;
    &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/usb/usb.c&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/libmaple/usb/usb.c&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;3) wait for the 0.0.12 or other future release of IDE, where the issue will be fixed. &#60;/p&#62;
&#60;p&#62;Happy Hacking!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
