
From digging around it seems that I might have in fact got a broken set of
David, maybe my code got chopped then because this is the start of my
program:
module Main where
import Data.ByteString.Char8 as BS hiding (putStrLn) ***HERE IT IS***
import Data.String.Conversions as SC
import Data.Word (Word16)
import Data.Vector as V (filterM, null, (!)) --as V hiding ((++))
import System.USB
import System.Environment
where the "BS" (pardon the pun) is quite plainly defined. And changing it
as suggested only yields this:
usb1.hs:61:18:
Not in scope: `B.replicate'
Perhaps you meant `BS.replicate' (imported from Data.ByteString.Char8)
So I don't think that's the solution.
libraries. I found this:
http://stackoverflow.com/questions/12576817/couldnt-match-expected-type-with...
and
when I actually listed the bytestring packages as suggested I get this
(terrible!) output:
WARNING: there are broken packages. Run 'ghc-pkg check' for more
details.
/var/lib/ghc/package.conf.d
bytestring-0.9.2.1
/home/sean/.ghc/i386-linux-7.4.2/package.conf.d
bytestring-0.10.0.1
and doing the suggested "ghc-pkg check" made me reach for the toilet
rolls....
WARNING: there are broken packages. Run 'ghc-pkg check' for more details.
/var/lib/ghc/package.conf.d
bytestring-0.9.2.1
/home/sean/.ghc/i386-linux-7.4.2/package.conf.d
bytestring-0.10.0.1
sean@sean-Dimension-4700 ~/Documents/haskell/usb $ ghc-pkg check
There are problems in package snap-core-0.9.3.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package tls-extra-0.6.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package crypto-numbers-0.1.3:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-io-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-algorithms-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package vty-4.7.0.20:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package pango-0.12.2:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
There are problems in package webkit-0.12.3:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
There are problems in package gtk-0.12.3:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
snap-core-0.9.3.1
tls-extra-0.6.1
crypto-numbers-0.1.3
repa-io-3.2.2.201204.1
repa-algorithms-3.2.2.201204.1
repa-3.2.2.201204.1
vty-4.7.0.20
pango-0.12.2
webkit-0.12.3
gtk-0.12.3
hakyll-4.1.4.0
snap-server-0.9.3.1
http-conduit-1.8.7.1
tls-1.1.2
crypto-pubkey-0.1.2
gloss-raster-1.7.7.201204.1
yi-0.6.6.0
hbro-0.9.0.0
hbro-contrib-0.9.0.0
ltk-0.12.0.0
So... I think that my real problem is that I have a badly broken package
setup. I am going to remove both bytestring packages as well as all those
broken things (I don't need them anyway( and reinstall and see what
happens. I hope it just goes away.... I really want to be USB programming
not fixing up my installation.. nothing like computers to make life awkward.
Thanks.
Sean.
On 27 February 2013 19:21, David McBride
You have this line in your code, but that doesn't correlate to the imports you listed.
BS.replicate 64 '\0'
import qualified Data.ByteString as B ( ByteString, packCStringLen, drop, length ) import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim' ) import qualified Data.ByteString.Unsafe as BU ( unsafeUseAsCStringLen )
So you must have imported Data.ByteString.Lazy as BS somewhere. Change that to B.replicate and it will probably work.
On Wed, Feb 27, 2013 at 11:41 AM, emacstheviking
wrote: Karol, Alexander,
Thanks for your feedback... I am still a little confused as I shall explain... first of all let's look at the prototype for 'writeInterrupt',
writeInterrupt :: DeviceHandle -> EndpointAddress -> WriteAction
To me, that reads a "takes a device handle and an endpoint address and returns a WriteAction", and to quote the WriteAction help text verbatim so there is no confusion:
type WriteAction = ByteString -> Timeout -> IO (Size, Status)Source
Handy type synonym for write transfers.
"A WriteAction is a function which takes a ByteString to write and a Timeout. The function returns an IO action which, when exectued(sic), returns the number of bytes that were actually written paired with a Status flag which indicates whether the transfer Completed or TimedOut."
Now let's move to my original code and the 'right' code...
action <- writeInterrupt handle endPoint let action = writeInterrupt handle endPoint
If I understand things correctly up to this point, my mistake was being too eager in using "<-", 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 "let" which captures the WriteAction that is returned which can be executed with the payload and the timeout on the next line:
(size, status) <- action payload 1000
On this line, the use of "<-" 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.
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 "string-conversions" (convertString) package but decided to battle it out instead...
First the new code as edited in response to Karol:
testBoard :: Device -> DeviceHandle -> IO () testBoard dev handle = do
putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\"" -- write 0x00 0x00 0x00 0x00, get back same...we need to pad the -- packet out to 64 bytes for a full-speed device... should probably -- get this (64) from the device configuration / description record -- for maximum portability!
let payload = BS.replicate 64 '\0'
let endPoint = EndpointAddress 0 Out let action = writeInterrupt handle endPoint (size, status) <- action payload 1000 return ()
And the new error:
usb1.hs:64:28: Couldn't match expected type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString' with actual type `ByteString' In the first argument of `action', namely `payload' In a stmt of a 'do' block: (size, status) <- action payload 1000
In the expression: do { putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\""; let payload = BS.replicate 64 '\NUL'; let endPoint = EndpointAddress 0 Out; let action = writeInterrupt handle endPoint; .... }
Where and why does it think that "Data.ByteString.Internal.ByteString" is the type of the first parameter to "action" which is quite clearly stated as being "ByteString" ??? I know that "String", 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't I understand why the type checker picked up "internal" somewhere along the way?
In the source code for WriteAction we have this:
type WriteAction = B.ByteString → Timeout → IO (Size, Status)
and at the top of the that source file:
-- from bytestring: import qualified Data.ByteString as B ( ByteString, packCStringLen, drop, length ) import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim' ) import qualified Data.ByteString.Unsafe as BU ( unsafeUseAsCStringLen )
So why is it trying to be "internal"! I have tried not to be lazy, I have read everything and looked everywhere before posting again. If it had said:
type WriteAction = BI.ByteString → Timeout → IO (Size, Status)
I would have understood but it doesn't does it ?! Can somebody explain for me so I can just get on and write my killer USB application please! LOL
:) Thanks, Sean.
On 27 February 2013 12:07, Karol Samborski
wrote: Hi Sean,
I think that your function for testing board should look like this:
testBoard :: Device -> DeviceHandle -> IO () testBoard dev handle = do putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\"\n" -- write 0x00 0x00 0x00 0x00, get back same... let payload = pack "\x00\x00\x00\x00" let endPoint = EndpointAddress 0 Out let action = writeInterrupt handle endPoint (size, status) <- action payload 1000 return ()
You need to use let because writeInterrupt returns (Timeout -> ByteString -> IO (Size, Bool)) instead of IO (Timeout -> ByteString -> IO (Size, Bool))
Karol
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners