gpib.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ;;
  2. ;; gpib.scm - guile binding for LinuxGpib
  3. ;;
  4. ;; Copyright (C) 2003 Stefan Jahn <stefan@lkcc.org>
  5. ;;
  6. ;; LinuxGpib is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2 of the License, or
  9. ;; (at your option) any later version.
  10. ;;
  11. ;; LinuxGpib is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;;
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with LinuxGpib; if not, write to the Free Software
  18. ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. ;;
  20. (define (println . args) (for-each display args) (newline))
  21. (define gpib:handle '())
  22. (define (gpib:init)
  23. (catch 'misc-error
  24. (lambda ()
  25. (if (not (feature? 'gpib))
  26. (begin
  27. (set! gpib:handle (dynamic-link "libgpib-guile.so"))
  28. (dynamic-call "gpib_init" gpib:handle))))
  29. (lambda args #f)))
  30. (define (gpib:halt)
  31. (if (dynamic-object? gpib:handle)
  32. (begin (dynamic-unlink gpib:handle)
  33. (set! gpib:handle '()))))
  34. (define (gpib:open index pad sad timeout eoi eos)
  35. (ibdev index pad sad timeout eoi eos))
  36. (define (gpib:command fd list)
  37. (let* ((clist '()))
  38. (for-each (lambda (c)
  39. (set! clist (cons (integer->char c) clist)))
  40. list)
  41. (ibcmd fd (list->string (reverse clist)))))
  42. (define (gpib:write fd string)
  43. (ibwrt fd string))
  44. (define (gpib:read fd bytes)
  45. (ibrd fd bytes))
  46. (define (gpib:find name)
  47. (ibfind name))
  48. (define (gpib:remote-enable fd enable)
  49. (ibsre fd enable))
  50. (define (gpib:interface-clear fd)
  51. (ibsic fd))
  52. (define (gpib:device-clear fd)
  53. (ibclr fd))
  54. (define (gpib:reset fd)
  55. (ibonl fd 1))
  56. (define (gpib:close fd)
  57. (ibonl fd 0))
  58. (define (gpib:wait fd status)
  59. (ibwait fd status))
  60. (define (gpib:serial-poll fd)
  61. (ibrsp fd))
  62. (define (gpib:trigger fd)
  63. (ibtrg fd))
  64. (define (gpib:request-service fd service)
  65. (ibrsv fd service))
  66. (define (gpib:error-code)
  67. (iberr))
  68. (define (gpib:counter)
  69. (ibcnt))
  70. (define (gpib:error)
  71. (let* ((error (iberr)))
  72. (cond
  73. ((equal? error EDVR) "<OS Error>")
  74. ((equal? error ECIC) "<Not CIC>")
  75. ((equal? error ENOL) "<No Listener>")
  76. ((equal? error EADR) "<Adress Error>")
  77. ((equal? error ECIC) "<Invalid Argument>")
  78. ((equal? error ESAC) "<No Sys Ctrlr>")
  79. ((equal? error EABO) "<Operation Aborted>")
  80. ((equal? error ENEB) "<No Gpib Board>")
  81. ((equal? error EOIP) "<Async I/O in prg>")
  82. ((equal? error ECAP) "<No Capability>")
  83. ((equal? error EFSO) "<File sys. error>")
  84. ((equal? error EBUS) "<Command error>")
  85. ((equal? error ESTB) "<Status byte lost>")
  86. ((equal? error ESRQ) "<SRQ stuck on>")
  87. ((equal? error ETAB) "<Device Table Overflow>"))))
  88. (export
  89. ;; public Gpib procedures
  90. gpib:init
  91. gpib:halt
  92. gpib:open
  93. gpib:command
  94. gpib:write
  95. gpib:read
  96. gpib:find
  97. gpib:remote-enable
  98. gpib:interface-clear
  99. gpib:device-clear
  100. gpib:close
  101. gpib:reset
  102. gpib:wait
  103. gpib:serial-poll
  104. gpib:trigger
  105. gpib:request-service
  106. gpib:error-code
  107. gpib:counter
  108. gpib:error
  109. ;; status byte
  110. DCAS DTAS LACS TACS ATN CIC REM LOK CMPL EVENT SPOLL RQS SRQI END TIMO ERR
  111. ;; public Gpib commands
  112. GTL SDC PPC GET TCT LLO DCL PPU SPE SPD UNL UNT PPD
  113. ;; timeout constants
  114. TNONE T10us T30us T100us T300us T1ms T3ms T10ms T30ms T100ms T300ms T1s
  115. T3s T10s T30s T100s T300s T1000s
  116. ;; end-of-string constants
  117. REOS XEOS BIN
  118. )