packages feed

bindings-K8055 0.1.1 → 0.1.2

raw patch · 11 files changed

+106/−51 lines, 11 filesbinary-added

Files

Bindings/K8055.hs view
@@ -24,25 +24,25 @@ import Bindings.K8055.Counters  --- | Depends on jumpers SK5, SK6 -data CardAddress +-- | Depends on jumpers SK5, SK6+data CardAddress   = Card1  -- ^ SK5:ON  SK6:ON   | Card2  -- ^ SK5:OFF SK6:ON   | Card3  -- ^ SK5:ON  SK6:OFF   | Card4  -- ^ SK5:OFF SK6:OFF-    + addressId :: Num a => CardAddress -> a-addressId address = +addressId address =   case address of     Card1 -> 0     Card2 -> 1     Card3 -> 2     Card4 -> 3 -    + foreign import stdcall unsafe "Version"   c_Version :: IO CInt-               + getVersion :: IO Int getVersion = do   vers <- c_Version@@ -54,9 +54,9 @@  foreign import stdcall unsafe "CloseDevice"   c_CloseDevice :: IO ()-                   + -- | Device is opened, action is performed and device is closed-withDevice :: CardAddress -> IO a -> IO a +withDevice :: CardAddress -> IO a -> IO a withDevice address action = do   ret <- c_OpenDevice (addressId address)   when (ret /= 0) (error "open device failed")
Bindings/K8055/AnalogIn.hs view
@@ -1,6 +1,6 @@ module Bindings.K8055.AnalogIn (   AnalogInput(..),-  readAnalogChannel, +  readAnalogChannel,   readAllAnalog   ) where @@ -13,14 +13,14 @@ data AnalogInput   = AnalogIn1   | AnalogIn2-    + analogInputId :: Num a => AnalogInput -> a analogInputId input =   case input of     AnalogIn1 -> 1     AnalogIn2 -> 2-   -    ++ foreign import stdcall unsafe "ReadAnalogChannel"   c_ReadAnalogChannel :: CInt -> IO CInt @@ -29,15 +29,15 @@ readAnalogChannel channel = do   res <- c_ReadAnalogChannel (analogInputId channel)   return $ fromIntegral res-   + foreign import stdcall unsafe "ReadAllAnalog"   c_ReadAllAnalog :: Ptr CInt -> Ptr CInt -> IO ()  -- | Reads the status of both analogue input-channels readAllAnalog :: IO (Word8, Word8) readAllAnalog = do-  alloca $ \ a1 -> +  alloca $ \ a1 ->     alloca $ \ a2 -> do       c_ReadAllAnalog a1 a2       a1' <- peek a1
Bindings/K8055/AnalogOut.hs view
@@ -14,9 +14,9 @@ data AnalogOutput   = AnalogOut1   | AnalogOut2-    + analogOutputId :: Num a => AnalogOutput -> a-analogOutputId output =                                       +analogOutputId output =   case output of     AnalogOut1 -> 0     AnalogOut2 -> 1@@ -32,7 +32,7 @@  foreign import stdcall unsafe "OutputAllAnalog"   c_OutputAllAnalog :: CInt -> CInt -> IO ()-                       + -- | Sets both analogue output channels according to the data outputAllAnalog :: Word8 -> Word8 -> IO () outputAllAnalog val1 val2 = do@@ -50,13 +50,13 @@  foreign import stdcall unsafe "ClearAllAnalog"   c_ClearAllAnalog :: IO ()-                   + -- | Sets all analogue output channels to minimum clearAllAnalog :: IO () clearAllAnalog = c_ClearAllAnalog  -foreign import stdcall unsafe "SetAnalogChannel"      +foreign import stdcall unsafe "SetAnalogChannel"   c_SetAnalogChannel :: CInt -> IO ()  -- | Sets the analogue output channel to maximum@@ -67,7 +67,7 @@  foreign import stdcall unsafe "SetAllAnalog"   c_SetAllAnalog :: IO ()-                    + -- | Sets all analogue output channels to maximum setAllAnalog :: IO () setAllAnalog = c_SetAllAnalog
Bindings/K8055/Counters.hs view
@@ -11,7 +11,7 @@ data Counter   = Counter1   | Counter2-    + counterId :: Num a => Counter -> a counterId cnt =   case cnt of@@ -29,8 +29,8 @@   foreign import stdcall unsafe "ReadCounter"-  c_ReadCounter :: CInt -> IO CInt        -                   +  c_ReadCounter :: CInt -> IO CInt+ -- | Reads the content of the pulse counte rnumber 1 or counter number 2 readCounter :: Counter -> IO Int readCounter cnt = do@@ -42,7 +42,7 @@   c_SetCounterDebounceTime :: CInt -> CInt -> IO ()  -- | Sets the debounce time to the pulse counter-setCounterDebounceTime :: Counter    +setCounterDebounceTime :: Counter                           -> Int    -- ^ 0 - 5000                           -> IO () setCounterDebounceTime cnt debounce =
Bindings/K8055/DigitalIn.hs view
@@ -1,4 +1,4 @@-module Bindings.K8055.DigitalIn (  +module Bindings.K8055.DigitalIn (   DigitalInput(..),   readDigitalChannel,   readAllDigital@@ -16,7 +16,7 @@   | DigitalIn6   | DigitalIn7   | DigitalIn8-    + digitalInputId :: Num a => DigitalInput -> a digitalInputId input =   case input of
Bindings/K8055/DigitalOut.hs view
@@ -64,7 +64,7 @@  -- | Sets the output channel setDigitalChannel :: DigitalOutput -> IO ()-setDigitalChannel dig = +setDigitalChannel dig =   c_SetDigitalChannel (digitalOutputId dig)  
K8055D.def view
@@ -1,24 +1,25 @@ LIBRARY K8055D EXPORTS-    Version-    OpenDevice-    CloseDevice-    ReadAnalogChannel-    SetAllAnalog-    ClearAllAnalog-    SetAllDigital-    ClearAllDigital-    ClearDigitalChannel-    SetDigitalChannel-    ReadDigitalChannel-    ReadAllDigital-    OutputAnalogChannel-    ClearAnalogChannel-    SetAnalogChannel-    WriteAllDigital-    OutputAllAnalog-    ReadCounter-    ResetCounter+    Version@0+    OpenDevice@4+    CloseDevice@0+    ReadAnalogChannel@4+    SetAllAnalog@0+    ClearAllAnalog@0+    SetAllDigital@0+    ClearAllDigital@0+    ClearDigitalChannel@4+    SetDigitalChannel@4+    ReadDigitalChannel@4+    ReadAllDigital@0+    OutputAnalogChannel@8+    ClearAnalogChannel@4+    SetAnalogChannel@4+    WriteAllDigital@4+    OutputAllAnalog@8+    ReadCounter@4+    ResetCounter@4     SetCurrentDevice     SearchDevices-    ReadAllAnalog+    ReadAllAnalog@8+    SetCounterDebounceTime@8
+ K8055D.dll.a view

binary file changed (absent → 18418 bytes)

+ README.markdown view
@@ -0,0 +1,54 @@+Description+-----------+This library allows you to control the Velleman K8055, a usb experiment interface board.++The board has:++ * 5 digital inputs+ * 2 analog inputs+ * 8 digital outputs+ * 2 analog outputs++How is works+------------+Velleman provides a `K8055D.dll`, so this is a **Windows-only solution**, to interact with the board.+A FFI interface has been written to interact with the dll functions.+For this I had to create a definition file `K8055D.def` and run `dlltool -k -d K8055D.def -l K8055D.dll.a`.++Some Background+---------------+My first attempt at interfacing this board was using `bindings-libusb`. After getting is to work+on Linux I was unable to compile it on Windows. Because my solution should work on Windows+I chose to interface the existing dll.++I haven't given up on the my first solution, it's still the cleanest way to go, having no+K8055 specific, native library dependencies and being platform-independent.++Install+-------+As mentioned earlier, we need the `K8055D.dll`. This can be obtained by downloading the official+[Velleman K8055 SDK]. Extract it and put the dll, `DLL_v4.0.0.0/K8055D.dll`, somewhere in PATH,+e.g. `C:\Windows\System32`.++Then all you need to do is install the cabal package:++    cabal install Bindings-K8055++Example+-------+Press a button, digital in, an run the following code:++    import Bindings.K8055++    main :: IO ()+    main =+      withDevice Card1 (readAllDigital >>= print)++Or using ghci:++    > import Bindings.K8055+    > withDevice Card1 (readAllDigital >>= print)+    0+++[Velleman K8055 SDK]: http://www.velleman.eu/downloads/files/downloads/k8055_sdk_version4.zip
bindings-K8055.cabal view
@@ -1,5 +1,5 @@ Name:                bindings-K8055-Version:             0.1.1+Version:             0.1.2 Synopsis:            Bindings to Velleman K8055 dll description:         Bindings to Velleman K8055 dll for interfacing USB I/O board. License:             BSD3@@ -11,7 +11,7 @@ Category:            FFI Build-type:          Simple Cabal-version:       >=1.2-extra-source-files:  K8055D.def libK8055D.a+data-files:          README.markdown K8055D.def K8055D.dll.a  Library   Exposed-modules:@@ -21,8 +21,8 @@     Bindings.K8055.DigitalOut,     Bindings.K8055.DigitalIn,     Bindings.K8055.Counters-  -  Build-depends: ++  Build-depends:     base >= 3 && < 5    extra-libraries: K8055D
− libK8055D.a

binary file changed (7150 → absent bytes)