Add sane-ref and sane-unref to make libsane usable reference counted instead
[cl-sane.git] / example / usage.lisp
blob814922f3009f2d9035abd391a1f1c3031b2a7c28
1 ;;;;;;;;;;;;
2 ;; This is a sort of elephants' graveyard of usage examples/snippets. Will be
3 ;; removed/replaced when the library is fully bound and I can write some proper
4 ;; documentation!
5 ;;;;;;;;;;;;;
7 (defpackage :sane-user
8 (:use :sane :cl :trivial-gray-streams :iterate))
10 (in-package :sane-user)
12 ;; With-init runs forms with the library initialised. It can bind a
13 ;; variable to the version - in this case, V.
14 (with-init v
15 (format t "~A~%" v)
16 42)
18 ;; devices lists the devices sane can find.
19 (with-init nil
20 (mapcar #'name (devices t)))
22 ;; List all the options of the device
23 (with-init nil
24 (with-device d "test:0"
25 (dump-option-list d)))
27 ;; Read from the device.
28 (with-init nil
29 (with-device d "test:0"
30 (setf (value (option "mode" d)) "Color")
31 (setf (value (option "test-picture" d)) "Color pattern")
33 (with-open-file (f "out.raw"
34 :direction :output
35 :element-type '(unsigned-byte 8)
36 :if-exists :supersede :if-does-not-exist :create)
37 (with-open-scanner-stream s d
38 (let (byte)
39 (iterate
40 (setf byte (stream-read-byte s))
41 (when (eq byte :eof) (terminate))
42 (write-byte byte f)))))))