<div dir="ltr"><div style>HURRAH! I have finally got it to compile...</div><div style><br></div><div style>I manually deleted the broken packages (I play too much anyway so a tidy up was in order) and it still failed with:</div>

<div style><br></div><font face="courier new, monospace">[1 of 1] Compiling Main             ( usb1.hs, usb1.o )<br><br>usb1.hs:64:28:<br>    Couldn&#39;t match expected type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString&#39;<br>

                with actual type `ByteString&#39;<br>    In the first argument of `action&#39;, namely `payload&#39;<br>    In a stmt of a &#39;do&#39; block: (size, status) &lt;- action payload 1000<br>    In the expression:<br>

      do { putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;&quot;;<br>           let payload = BS.replicate 64 &#39;\NUL&#39;;<br>           let endPoint = EndpointAddress 0 Out;<br>           let action = writeInterrupt handle endPoint;<br>

           .... }</font><div style>And I suddenly remembered that despite the clean up I still had two bytestring packages:</div><div style><br></div><font face="courier new, monospace">sean@sean-Dimension-4700 ~/Documents/haskell/usb $ ghc-pkg list bytestring<br>

/var/lib/ghc/package.conf.d<br>   bytestring-0.9.2.1<br>/home/sean/.ghc/i386-linux-7.4.2/package.conf.d<br>   bytestring-0.10.0.2</font><div><br></div><div style>So, on the basis that the system is always right and I am always wrong I removed the local one in my home folder:</div>

<div><br></div><font face="courier new, monospace">sean@sean-Dimension-4700 ~/Documents/haskell/usb $ ghc-pkg unregister bytestring-0.10.0.2</font><div><font face="courier new, monospace"><br></font><div style>and then tried again:</div>

<div style><br></div><font face="courier new, monospace">sean@sean-Dimension-4700 ~/Documents/haskell/usb $ ghc --make usb1.hs<br>Linking usb1 ...<br><br>sean@sean-Dimension-4700 ~/Documents/haskell/usb $ sudo ./usb1<br>
Inspecting device: &quot;Bus 005 Device 002&quot;<br>
libusbx: error [submit_bulk_transfer] submiturb failed error -1 errno=2<br>usb1: IOException &quot;&quot;</font><div><b><br></b></div><div style>For me that <b>is</b> *success*, it fails because since I wrote it I read the USB docs again and I have to &quot;claim&quot; the device before I can talk to the endpoint but at least I am now focused on my goal of USB interaction with the Hexwax chip again.</div>

<div style><br></div><div style>A big thanks to everybody, this list is once again proving to be awesome, another happy user walks away :)</div><div style><br></div><div style>Thanks everybody, especially Karol, Alexander and David.</div>

<div style><br></div><div style>Sean Charles.</div><div style><br></div><div><i>PS: Yes, I am using a a Dell from 2004 because as much as I&#39;d love to but a shiny new iMac I cant bring myself to part with my trusty friend. Hell, I even wrote my own computer language system with it and it&#39;s &quot;good enough&quot;. Shameless plug (<a href="http://feltweb.info">http://feltweb.info</a>, site written in FELT!)  Still under-way, doing &quot;Java&quot; with it of late, not finished yet because USB and hardware is more fun right now!<br>

</i></div><div><br></div><div><br></div><div style><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 27 February 2013 19:21, David McBride <span dir="ltr">&lt;<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You have this line in your code, but that doesn&#39;t correlate to the imports you listed.<br><br>BS.replicate 64 &#39;\0&#39;<br>

<br>    import qualified Data.ByteString          as B  ( ByteString, packCStringLen, drop, length )<br>
    import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim&#39; )<br>    import qualified Data.ByteString.Unsafe   as BU ( unsafeUseAsCStringLen )<br><br>So you must have imported Data.ByteString.Lazy as BS somewhere.  Change that to B.replicate and it will probably work.<br>


<br><br><div class="gmail_quote">On Wed, Feb 27, 2013 at 11:41 AM, emacstheviking <span dir="ltr">&lt;<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr"><div><div><div><div><div>Karol, Alexander,<br><br></div>Thanks for your feedback... I am still a little confused as I shall explain... first of all let&#39;s look at the prototype for &#39;writeInterrupt&#39;,<div>


<br>

<br>    writeInterrupt :: DeviceHandle -&gt; EndpointAddress -&gt; WriteAction<br><br></div></div>To me, that reads a &quot;takes a device handle and an endpoint address and returns a WriteAction&quot;, and to quote the WriteAction help text verbatim so there is no confusion:<br>




<br>    type WriteAction = ByteString -&gt; Timeout -&gt; IO (Size, Status)Source<br><br>    Handy type synonym for write transfers.<br><br>        &quot;A WriteAction is a function which takes a ByteString to write and a Timeout.<br>




         The function returns an IO action which, when exectued(sic), returns the number<br>         of bytes that were actually written paired with a Status flag which indicates whether<br>         the transfer Completed or TimedOut.&quot;<br>




<div><br><br></div><div>Now let&#39;s move to my original code and the &#39;right&#39; code...<br><br></div><div><div>    action &lt;- writeInterrupt handle endPoint<br></div></div><div><div>    let action = writeInterrupt handle endPoint<br>




<br></div></div><div><br>If I understand things correctly up to this point, my mistake was being too eager in using &quot;&lt;-&quot;, my mind at that point was obviously confusing the return value from WriteAction with the return type of writeInterrupt and I can see now that what I should have done was use &quot;let&quot; which captures the WriteAction that is returned which can be executed with the payload and the timeout on the next line:<br>




<br></div><div><div>    (size, status) &lt;- action payload 1000<br><br></div></div><div>On this line, the use of &quot;&lt;-&quot; is what is required in order to cause the promised IO action to  perform its duties and return me the tuple of data sent and status returned from the USB inner workings.<br>




<br></div><div>However, we now come to the new type checker error, and this one has me floored right now. Time and time again I find myself beating my head against a wall and tearing my hair out trying to understand the thousand-and-one variations on strings in Haskell! I even tried the &quot;string-conversions&quot; (convertString) package but decided to battle it out instead...<br>




<br></div><div>First the new code as edited in response to Karol:<div><br><br>    testBoard :: Device -&gt; DeviceHandle -&gt; IO ()<br></div>    testBoard dev handle = do<div><br>      putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;&quot;<br>


</div>

      -- write 0x00 0x00 0x00 0x00, get back same...we need to pad the                                      <br>      -- packet out to 64 bytes for a full-speed device... should probably                                  <br>




      -- get this (64) from the device configuration / description record                                   <br>      -- for maximum portability!                                                                           <br>




      let payload  = BS.replicate 64 &#39;\0&#39;<div><br>      let endPoint = EndpointAddress 0 Out<br></div><div>      let action   = writeInterrupt handle endPoint<br>      (size, status) &lt;- action payload 1000<br>


      return ()<br>

<br></div>And the new error:<br></div><br>usb1.hs:64:28:<br>    Couldn&#39;t match expected type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString&#39;<br>                with actual type `ByteString&#39;<br>    In the first argument of `action&#39;, namely `payload&#39;<br>




    In a stmt of a &#39;do&#39; block: (size, status) &lt;- action payload 1000<div><br>    In the expression:<br>      do { putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;&quot;;<br>
</div>           let payload = BS.replicate 64 &#39;\NUL&#39;;<br>

           let endPoint = EndpointAddress 0 Out;<br>           let action = writeInterrupt handle endPoint;<br>           .... }<br><br><br></div>Where and why does it think that &quot;Data.ByteString.Internal.ByteString&quot; is the type of the first parameter to &quot;action&quot; which is quite clearly stated as being &quot;ByteString&quot; ???<br>




</div>I know that &quot;String&quot;, the native type is 4-bytes and that ByteString (Strict) and ByteString (Lazy) are both 8-bit, which is great, and I understand that the strict version (at least to me) feels like the rightmatch to be using for data buffers for a USB transfer but why oh why oh why can&#39;t I understand why the type checker picked up &quot;internal&quot; somewhere along the way?<br>




<br></div>In the source code for WriteAction we have this:<br><br><div><div><div>    type WriteAction = B.ByteString → Timeout → IO (Size, Status)<br><br></div><div>and at the top of the that source file:<br><br>    -- from bytestring:<br>




    import qualified Data.ByteString          as B  ( ByteString, packCStringLen, drop, length )<br>    import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim&#39; )<br>    import qualified Data.ByteString.Unsafe   as BU ( unsafeUseAsCStringLen )<br>




<br><br></div><div>So why is it trying to be &quot;internal&quot;! I have tried not to be lazy, I have read everything and looked everywhere before posting again. If it had said:<br><br>    type WriteAction = BI.ByteString → Timeout → IO (Size, Status)<br>




<br>I would have understood but it doesn&#39;t does it ?!<br>Can somebody explain for me so I can just get on and write my killer USB application please! LOL<br><br>:)<br></div><div>Thanks,<br>Sean.<br><br></div><div><br>




</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div>On 27 February 2013 12:07, Karol Samborski <span dir="ltr">&lt;<a href="mailto:edv.karol@gmail.com" target="_blank">edv.karol@gmail.com</a>&gt;</span> wrote:<br>




</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi Sean,<br>
<br>
I think that your function for testing board should look like this:<br>
<br>
testBoard :: Device -&gt; DeviceHandle -&gt; IO ()<br>
testBoard dev handle = do<br>
  putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;\n&quot;<br>
  -- write 0x00 0x00 0x00 0x00, get back same...<br></div><div>
  let payload  = pack &quot;\x00\x00\x00\x00&quot;<br>
  let endPoint = EndpointAddress 0 Out<br></div><div>
  let action = writeInterrupt handle endPoint<br>
  (size, status) &lt;- action payload 1000<br>
  return ()<br>
<br>
You need to use let because writeInterrupt returns (Timeout -&gt;<br>
ByteString -&gt; IO (Size, Bool)) instead of IO (Timeout -&gt; ByteString -&gt;<br>
IO (Size, Bool))<br>
<br>
Karol<br>
<br></div><div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>