pax_global_header00006660000000000000000000000064150704621550014517gustar00rootroot0000000000000052 comment=cb385c4dbed36d7a68b60832e106e9ce1f1390de .gitignore000066400000000000000000000032611507046215500130550ustar00rootroot00000000000000# # gitignore for linux-gpib-git/linux-gpib-user # # autotools and stuff aclocal.m4 autom4te.cache/ compile config.guess config.h config.h.in config.log config.status config.sub configure depcomp Makefile.in doc/doc_html/ doc/gpib_version.txt doc/linux-gpib.pdf examples/findlisteners examples/ibterm examples/ibtest examples/master_read_to_file examples/master_write_from_file examples/slave_read_to_file examples/slave_write_from_file include/gpib/gpib_version.h install-sh language/perl/LinuxGpib.bs language/perl/LinuxGpib.c language/perl/MYMETA.json language/perl/MYMETA.yml language/perl/Makefile.PL language/perl/Makefile.old language/perl/blib/ language/perl/pm_to_blib language/php/gpib_php.la language/python/build/ language/python/dist/ language/python/gpib.egg-info/ language/tcl/libgpib_tcl.la lib/TAGS lib/gpib_config/gpib_config lib/ibConfLex.c lib/ibConfLex.h lib/ibConfYacc.c lib/ibConfYacc.h lib/ibVers.h lib/libgpib.la lib/libgpib.pc libtool ltmain.sh m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 missing stamp-h1 test/libgpib_test usb/agilent_82357a/99-agilent_82357a.rules usb/gpib_udev_fxloader usb/lpvo_usb_gpib/99-lpvo_usb_gpib.rules usb/ni_usb_gpib/99-ni_usb_gpib.rules #tcl .xsetup #guile language/guile/libgpib-guile.la Makefile doc/Makefile doc/intEntities.dtf doc/man/ drivers/Makefile examples/Makefile include/Makefile include/gpib/Makefile language/Makefile language/guile/Makefile language/perl/Makefile language/php/Makefile language/php/TESTS/Makefile language/python/Makefile language/tcl/Makefile lib/Makefile lib/gpib_config/Makefile test/Makefile usb/Makefile usb/agilent_82357a/Makefile usb/lpvo_usb_gpib/Makefile usb/ni_usb_gpib/Makefile AUTHORS000066400000000000000000000021651507046215500121370ustar00rootroot00000000000000This is an incomplete list of people who have contributed code and/or documentation to the linux-gpib package, in alphabetical order. If you aren't listed here but should be, please tell Frank. John Ackermann Michel Billaud Stephan Boettcher John Bradshaw Marcello Carla' Albert Comerma Keith Dart Brian Donavan Gudjon I. Gudjonsson Frank Mori Hess Bernhard Heibler Steve Holland Stefan Jahn Robert Jordens Michael Katzmann Kentaro Kitagawa Christopher Lang Dan Lenski Thomas Nisius David Penkler Marco Prevedelli Michael Ritzert Claus Schroeter Uwe Strempel Werner Stille Bryan Thomas COPYING000066400000000000000000000432541507046215500121260ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. INSTALL000066400000000000000000000225251507046215500121220ustar00rootroot00000000000000 Installing Linux-GPIB user space -------------------------------------------------------------------------- A) First steps: -------------------------------------------------------------------------- o) Unpacking the Software: "linux-gpib-user-x.x.x" contains the userspace components of Linux-GPIB (the C library, etc.). For a functioning system you will also need the driver components contained in "linux-gpib-kernel-x.x.x" or the GPIB drivers in the kernel sources from linux kernel version 6.13 onwards. "linux-gpib-kernel-x.x.x" contains the code for gpib modules which are loaded into Linux kernel. This install file describes the installation of "linux-gpib-user-x.x.x". Unpack the archives with the 'tar' program, for example 'tar -xzf linux-gpib-user-x.x.x.tar.gz' B) Installing Linux-GPIB user space -------------------------------------------------------------------------- o) cd to your linux-gpib-user-x.x.x directory and run the './configure' script. Typically it would be run as: ./configure --sysconfdir=/etc Run './configure --help' for a list of additional options. If the configure script does not exist (you are using a git clone), it can be generated by running the './bootstrap' script. You will need automake, autoconf, etc. to generate the configure script. Type 'make'. Now the package will be compiled. Type 'make install' (as root). This will install the library, header files, etc. Make sure the directory you installed the shared library to is listed in your /etc/ld.so.conf file, so that ld can find libgpib.so. If the directory is not listed, add it and then run 'ldconfig'. With the default setup, to give a user access to the computer's gpib boards you will have to add them to the group 'gpib'. If this group does not already exist on your computer you may add it by running the command 'groupadd gpib' as root. You can then use the 'usermod' tool or edit /etc/groups to change the groups the user account belongs to. Or, you could change the permissions on the device files /dev/gpib[0-15] to something you like better. If you are using udev, you can set the permissions on the gpib device files with a line like: KERNEL=="gpib[0-9]*", MODE="0660", GROUP="gpib" in your udev rules. This is already done by default if you ran ./configure --sysconfdir=/etc. (see $(sysconfdir)/udev/rules.d/98-gpib-generic.rules installed by 'make install') In the unlikely case you are not using udev, you can use 'chmod' (or edit devfsd.conf if you are using devfs) to change the device file permissions. You may also need to manually create the device files /dev/gpibX if they don't already exist. This can be done by running 'make device_files_install'. o) Documentation The documentation is installed in the following directories of the DATAROOTDIR specified by the --datarootdir option to .configure. By default $DATAROOTDIR=/usr/local/share. - manpages in $DATAROOTDIR/man Ensure that your manpath includes this directory for direct access to the linux-gpib manpages. Normally it includes the default installation path /usr/local/share/man - html docs in $DATAROOTDIR/doc/linux-gpip-user/html Point your browser to the t1.html file there to start at the top index. The pdf version of the docs is not part of the installation and can be found at linux-gpib-user-x.x.x/doc/linux-gpib.pdf C) Configuring the driver modules ----------------------------- o) PCMCIA cards If you have a really old system (kernel_version 2.4.x) that uses cardmgr from pcmcia_cs please see below. For all other systems (pcmciautils): Load the appropriate module for your pcmcia card with modprobe. For example with an NI PCMCIA card: sudo modprobe tnt4882 For other cards consult Table 2 Supported Hardware Matrix in the linux-gpib.pdf doc for the name of the module to load that corresponds to your PCMCIA card. Then run gpib_config, for example: sudo gpib_config --minor 0 cardmgr based systems: These systems are supported by Linux-GPIB version 3.1.x. See the "linux-gpib for 2.4.x kernels" folder for the relevant linux-gpib package at: https://sourceforge.net/projects/linux-gpib/files/ o) USB devices USB devices can be configured automatically by the udev subsystem. When devices matching the udev rules are detected it triggers the execution of the gpib udev configuration scripts. By default the scripts are installed in /usr/local/lib/udev. The target install directory can be customized with the --with-udev-libdir=DIR option when running ./configure If your device requires external firmware you will need to install firmware files for your device. A tarball is available from https://github.com/fmhess/linux_gpib_firmware. Make sure you have the "fxload" and "udev" packages installed on your computer. The udev scripts will automatically upload the firmware to your device and load the driver module when the device is detected. If you have errors, check your system log files (not dmesg) for messages from the udev scripts: The udev rules in should be installed in /etc/udev/rules.d/. This is already done by default if you used ./configure --sysconfdir=/etc. The udev rules invoke the udev configuration scripts. Note: make install will not overwrite existing files in $sysconfdir/udev/rules.d/. The provided 99-xxx.rules files need not be edited. For an interface requiring a firmware load they will automatically invoke the fxload utility. Once the firmware is loaded the udev subsystem triggers the addition of the interface with the 'firmware loaded product id'. This runs 98-gpib-generic.rules if customized to recognise the interface will add the appropriate --minor, --pad or other options to the GPIB_CONFIG_OPTIONS environment variable. Then the 99-xxx.rules file is run again, this time with the actions for the interface with firmware. This will add the --board-type option in the GPIB_CONFIG_OPTIONS environment variable and invoke the gpib_udev_config script which runs gpib_config with the options contained in the GPIB_CONFIG_OPTIONS environment variable to initialise the interface. If you specify the --minor, --pad and --system-controller options in the 98-gpib-generic.rules file for a particular board by serial number or device path, that board does not need to have an entry in the gpib.conf file. Using multiple-boards of the same type requires udev support. This is because by default gpib_config will be invoked for minor 0 for each board. You can associate specific board indexes (aka minors) by serial number or device path. This is done by uncommenting, duplicating and editing the example entries in the 98_gpib_generic.rules file for each interface. Using serial number it does not matter which usb ports you use. Using device path the association will be made with the physical usb port in your system. To obtain the serial numbers or device paths for your adapters plug them in and check the syslog for the output from the gpib_udev_config script. The order of the messages will correspond to the order in which you plugged the adapters in: sudo tail -100 /var/log/messages | grep gpib_udev_config In order to reload the rules files after editing you can use sudo udevadm control -R lpvo self made usb gpib adapter: The lpvo DIY adapter uses a FTDI USB-Serial chip which by default loads the ftdi_sio driver module. The gpib adapter can be enabled after a reboot with the commands: sudo rmmod ftdi_sio lpvo_usb_gpib sudo modprobe lpvo_usb_gpi or, enabled automatically for all subsequent boots, by copying linux-gpib-user-x.x.x/usb/lpvo_usb_gpib/lpvo_usb_gpib.conf to /etc/modprobe.d D) Configuring the GPIB-Library ------------------------------- You may edit $sysconfdir/gpib.conf to set the interface defaults for gpib_config, and add any devices you wish to open via ibfind(). See the documentation in doc/linux-gpib.pdf for more information. For non-usb devices or systems without udev support you need to run the 'gpib_config' utility to setup the driver before you can use it (the 'minor' options specifies which board index you are setting up): gpib_config --minor 0 E) Trying it out ---------------- You may find the examples/ibtest program useful as a starting point in trying out your setup. The examples/ibterm program provides a simple terminal interface to send commands to a specific instrument and view the responses. F) Bindings for other languages ------------------------------- The bindings to other languages will be enabled by default in the './configure' script. They will not be built if you disable them with the appropriate configure option, or if the necessary header files/libraries are not found on your machine. Note: for the guile bindings you need to have the guile 1.8 package installed. G) Uninstalling --------------- Type 'make uninstall' as root in the same directory from which the package was originally installed. (linux-gpib-user-x.x.x/) Note: The configuration file and udev rules are not uninstalled by this procedure. They need to be removed manually if you wish to re-install the standard distribution configuration file and udev rules later since existing files are not overwritten by the install procedure. Check the following file and directory: $sysconfdir/gpib.conf $sysconfdir/udev/rules.d/Makefile.am000066400000000000000000000015171507046215500131230ustar00rootroot00000000000000# Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = include lib drivers examples test doc language usb EXTRA_DIST = etc util m4 README.HAMEG README.hp82335 bootstrap ACLOCAL_AMFLAGS = -I m4 distclean-local: $(RM) $(srcdir)/lib/ibVers.h dist-hook: -find $(distdir) -depth -name '.svn' -type d -exec $(RM) -r \{\} \; -find $(distdir) \( -name '*~' -o -name '.#*' \) -exec $(RM) \{\} \; $(RM) $(distdir)/lib/ibVers.h .PHONY : device_files_install device_files_install: $(MAKE) -C drivers $(AM_MAKEFLAGS) device_files_install NEWS000066400000000000000000000000001507046215500115500ustar00rootroot00000000000000README000066400000000000000000000017361507046215500117520ustar00rootroot00000000000000===================================================== The Linux GPIB Package ----------------------------------- (c) 1994-1996 by C.Schroeter (c) 2001-2011 by Frank Mori Hess ===================================================== This is the user space part of the Linux-GPIB the IEEE-488 card support package and measurement suite for LINUX. This version of Linux-GPIB requires a version 2.6.x or above of the Linux kernel. 2.6.x kernels older than 2.6.8 are not supported. 2.4.x kernels are supported by Linux-GPIB versions 3.1.x. See the INSTALL file for instructions on building and installing this software package. Send comments, questions and suggestions to to the linux-gpib mailing list linux-gpib-general@lists.sourceforge.net *************** COPYRIGHT NOTICE *********************** If you want to distribute software which makes use of this package, please read the COPYING file carefully. ******************************************************** README.HAMEG000066400000000000000000000053031507046215500125640ustar00rootroot00000000000000The HAMEG HO-80 IEEE-488 card is driven by an NEC |PD7210C controller. It supports the full IEEE 488-1978 standard. With Linux-IEEE this card is compatible to an PCII card. Against the PCII you have to pay attention on some different jumper setting. In opposit to the PCII th HO-80 contains an 8kB BIOS-ROM. This ROM is not used by Linux-IEEE. All settings ar taken using two DIL-switches (SW1 and SW2) and two jumper-blocks (K1 and K2). With SW1 the I/O adress, with K1 the IRQ, with SW2 the ROM-base and with K2 th DMA-channel is selected. SW1: Position: 1 2 3 4 5 6 7 8 Adress : A9 A8 A7 A6 A5 A4 A3 Bus-Master For setting the I/O Adress 2B8h you have to convert it to binary: 1 0 1 0 1 1 1 0 0 0 The last three Bits represent the adresslines A2, A1 and A0. These three Bits are not used. Now setting up SW1 is easy :-) To get an 1 the switch is turned off, an for an 0 the switch is turned on. So the following settings result: Position: 1 2 3 4 5 6 7 Setting : off on off on off off off With SW1-8 the Bus-Master for the IEEE-488 Bus is selected. SW1-8 off: HO-80 is Bus-Master SW2-8 on : HO-80 is not Bus-Master Remember: Only one device can be Bus-Master. Normally th PC is used for this job. SW2: Position: 1 2 3 4 5 6 7 Adress : A19 A18 A17 A16 A15 A14 A13 Count : 512K 256K 128K 64K 32K 16K 8K By default the ROM is at Adress DE000h. (SW1 settings: 00100000). To change the Adress of the ROM you can calculate the settings according to the settings of SW1. On most Systems these Setting will work. If this Memoryarea is used by an other Adapter (LAN, VGA....) you must change thes settings. The Area E0000h and above is not usable! At E0000h the System BIOS starts. K1 IRQ setting: o o IRQ7 LPT1 (normally usable) o o IRQ6 Floppy (normally not usable) o=o IRQ5 LPT2 (normally usable) o o IRQ4 COM1 (normally not usable) o o IRQ3 COM2 (normally not usable) o o IRQ2 (only usable when IRQ9 is not used) K2 DMA setting: o o DACK1 o=o DACK3 o o DRQ1 o=o DRQ3 o o not used On an AT-PC DACK3 and DRQ3 are recommended. If DMA3 ist used by an other Card try DMA1 (DACK1 and DRQ1). If both are used leave all jumpers open and compile the driver without DMA support. I use this Card with my Graphtec MP1000 flatbed Plotter, an CBM 4031 Floppy Drive and some Measurement equipment. If you have problems with tis Card feel free to mail me. I'll try to help you fixing up the problem. Andreas.Tauscher@allgaeu.org or tauscher@felix.rz.fh-ulm.deREADME.hp82335000066400000000000000000000161471507046215500127670ustar00rootroot00000000000000 HP 82335 and 27209 ----------------------------------------------------------------------------------- Configuring the cards: ----------------------------------------------------------------------------------- The 27209 and the 82335 cards are "memory mapped", and are different from most I/O cards, which use an port address space. The legal mappings are into 16 KB blocks of the "reserved" 384 KB of DOS RAM and are as follows: +---------------+ | select code 8 | E0000 <-- not recommended +---------------+ default switch setting --> | select code 7 | DC000 +---------------+ | select code 6 | D8000 +---------------+ | select code 5 | D4000 +---------------+ | select code 4 | D0000 +---------------+ | select code 3 | CC000 +---------------+ | select code 2 | C8000 +---------------+ The HP 27209 card is also known under the product numbers 82990, 61062, and 88500; it's the same card no matter what the number. The card has the layout: +-----------------------------------------+ | 27209 | | +---- | | | | | | | +--+ | | | | | | | | | | 1 +--------+ | | | | | Configuration Switches +--+ | 0 +--------+ (8) | | 87654321 | | | +---+ +-------+ | | | +-----------------------------+ | | The switches have the default settings: 27209 Default Switch Settings +---------------------------------+ 0 | +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | | |X| | | | | | | |X| | | |X| |X| | | +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | | | | |X| |X| |X| | | |X| | | | | | 1 | +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | +---------------------------------+ 1 2 3 4 5 6 7 8 Note that the diagram is upside-down relative to the DIP switch orientation in the board-layout diagram; this can be confusing, so I recommend that you hold the card upside-down while setting the switches so the orientation matches this illustration. => Switches 1 to 4 control the card's memory address as follows: ___________________________ switch select address 1234 code ___________________________ 0000 16 C0000 0001 1 C4000 0010 2 C8000 0011 3 CC000 0100 4 D0000 0101 5 D4000 0110 6 D8000 0111 7 DC000 1000 8 E0000 1001 9 E4000 1010 10 E8000 1011 11 EC000 1100 12 F0000 1101 13 F4000 1110 14 F8000 1111 15 FC000 ___________________________ The default address is DC000, or select code 7. Switch 5 was defined to allow certain antique HP Vectra PCs to boot DOS off an external HPIB disk drive (when the appropriate software was installed). This switch should always be set to 0, since you may hang your PC if it is set to 1. Switch 6 does nothing useful, but it should be left set to 1. Switches 7 and 8 control the PC IRQ level of the card: ________________ PC IRQ 7 8 ________________ 3 0 0 4 0 1 5 1 0 6 1 1 ________________ The default IRQ level is 3. * The HP 82335 has the same form-factor, but a different layout. (The two cards are easy to distinguish in practice. All the chips on the 27209 are laid out horizontally, parallel to the PC-bus edge connector; all the chips on the 82335 are laid out vertically, at a right angle to the PC-bus edge connector.) +-----------------------------------------+ | 82335 | | +---- | 1 0 | | 1 +----+ | | 2 | | | | 3 | | Configuration +--+ | 4 | | Switches | | | 5 | | (8) | | | 6 | | | | | 7 | | | | | 8 +----+ +--+ | | | | | | +---+ +-------+ | | | +-----------------------------+ | | The default settings of the switch are as follows: +-----------------+ 1 | +----+----+ | 0 | 1 | |XXXX| 0 | | +----+----+ | | 2 |XXXX| | 1 | | +----+----+ | | 3 |XXXX| | 1 | | +----+----+ | | 4 |XXXX| | 1 | | +----+----+ | | 5 | |XXXX| 0 | | +----+----+ | | 6 | |XXXX| 0 | | +----+----+ | | 7 | |XXXX| 0 | | +----+----+ | | 8 | |XXXX| 0 | | +----+----+ | +-----------------+ The switch numbering is on the left; the actual values of the default settings are on the right. Note that if the DIP uses slide switches, a "0" corresponds to the slide pushed to the right; if the DIP uses rocker switches, a "0" corresponds to the switch depressed on the right. Switches 1-4 control the card's PC bus address and interface select code (ISC); they operate the same as they do with the 27209: ___________________________ switch select address 1234 code ___________________________ 0000 16 C0000 0001 1 C4000 0010 2 C8000 0011 3 CC000 0100 4 D0000 0101 5 D4000 0110 6 D8000 0111 7 DC000 1000 8 E0000 1001 9 E4000 1010 10 E8000 1011 11 EC000 1100 12 F0000 1101 13 F4000 1110 14 F8000 1111 15 FC000 ___________________________ The default setting is ISC 7. Switches 5 & 6 control the PC interrupt level; they operate as do switches 7 and 8 on the 27209 card: ________________ PC IRQ 5 6 ________________ 3 0 0 4 0 1 5 1 0 7 1 1 ________________ The default setting is IRQ 3. Switches 7 and 8 are not used. TODO000066400000000000000000000027561507046215500115650ustar00rootroot00000000000000cleanup and improve organization of code - lots of work to do here generally make this software suck less fix crash on pcmcia card removal when program has board open have library parse dmesg automatically on error report error when user tries to read/write to interface board which is bus master a kcontrol module for configuring boards might be nice possible problems when autopoll happens without remote enable timeouts on write should handle data that was able to report number of bytes sent before timeout occurred. stuck SRQ handling add query to ibask() for support of IFC events fix support parallel poll timeout support (should be hardware-based) better error message when gpib_config has not been run specifying config file with gpib_config --file can cause problems, since library doesn't know anything about it unless IB_CONFIG is set in the environment as well. Should warn about this somewhere. add links to web page (maybe comedi and vimms) split off parts of library that need libpthread, so we can provide a pthread free version (that would lack ibwrta(), etc.). lock on board online/offline libgpib_test: add test for serial poll without autopolling remove devices that time out from autopoll list better error on unknown board_type being addressed as listener should abort writes, being addressed as talker should abort reads maybe use 1-1 relationship between file descriptors and gpib device/board descriptors instead of maintaining our own lists of gpib device descriptors. applications/000077500000000000000000000000001507046215500135515ustar00rootroot00000000000000applications/Makefile000066400000000000000000000011441507046215500152110ustar00rootroot00000000000000# # Makefile for ieee488 application suite # # Please don't change this file ! # Subdirectories will be automagically scanned # SUBDIRS = `../util/subdirs` GPIB_HOME= `(cd ..;pwd)` MAKE = make GPIB_HOME=$(GPIB_HOME) -C all: subdirs subdirs: set -e;for i in $(SUBDIRS); do $(MAKE) $$i ; done clean: set -e;for i in $(SUBDIRS); do $(MAKE) $$i clean; done -find . -name "*.o" -exec rm {} \; install: set -e;for i in $(SUBDIRS); do $(MAKE) $$i install; done rcsput: set -e;for i in $(SUBDIRS); do $(MAKE) $$i rcsput; done rcsget: set -e;for i in $(SUBDIRS); do $(MAKE) $$i rcsget; done bootstrap000077500000000000000000000004651507046215500130330ustar00rootroot00000000000000#!/bin/sh #run this script to create the 'configure' script if [ ! -f NEWS ] ; then touch NEWS fi # The common ChangeLog is maintained on the top level of trunk if [ ! -f ChangeLog ] ; then touch ChangeLog fi aclocal -I m4 && \ libtoolize --copy --force && \ autoheader && \ autoconf && \ automake -a -c configure.ac000066400000000000000000000204461507046215500133570ustar00rootroot00000000000000 dnl Process this file with autoconf to produce a configure script. AC_INIT([linux-gpib-user],[4.3.7]) # libtool version: current:revision:age # # If the library source code has changed at all since the last update, then # increment revision (`c:r:a' becomes `c:r+1:a'). # # If any interfaces have been added, removed, or changed since the last update, # increment current, and set revision to 0. # # If any interfaces have been added since the last public release, then # increment age. # # If any interfaces have been removed since the last public release, then set # age to 0. GPIB_SO_VERSION=4:0:4 AC_CONFIG_SRCDIR([lib/ibask.c]) AM_INIT_AUTOMAKE AM_MAINTAINER_MODE AC_CONFIG_MACRO_DIR([m4]) dnl create a config.h file (Automake will add -DHAVE_CONFIG_H) AC_CONFIG_HEADERS([config.h]) AC_SUBST([VERSION]) AC_SUBST([GPIB_SO_VERSION]) [ISODATE=`date +%Y-%m-%d`] AC_SUBST([ISODATE]) AC_CANONICAL_HOST AC_ENABLE_SHARED([yes]) AC_ENABLE_STATIC([no]) AC_ARG_ENABLE([all-bindings],[ --disable-all-bindings Disable all language binding to libgpib], [BINDING_DEFAULT=$enableval],[BINDING_DEFAULT="yes"]) AC_ARG_ENABLE([guile-binding],[ --disable-guile-binding Disable Guile binding to libgpib], [BIND_GUILE=$enableval],[BIND_GUILE=$BINDING_DEFAULT]) AC_ARG_ENABLE([perl-binding],[ --disable-perl-binding Disable Perl binding to libgpib], [BIND_PERL=$enableval],[BIND_PERL=$BINDING_DEFAULT]) AC_ARG_ENABLE([php-binding],[ --disable-php-binding Disable PHP binding to libgpib], [BIND_PHP=$enableval],[BIND_PHP=$BINDING_DEFAULT]) AC_ARG_ENABLE([python-binding],[ --disable-python-binding Disable Python binding to libgpib], [BIND_PYTHON=$enableval],[BIND_PYTHON=$BINDING_DEFAULT]) AC_ARG_ENABLE([tcl-binding],[ --disable-tcl-binding Disable TCL binding to libgpib], [BIND_TCL=$enableval],[BIND_TCL=$BINDING_DEFAULT]) AC_ARG_ENABLE([documentation],[ --disable-documentation Disable building pdf documentation from SGML sources], [BUILD_DOCS=$enableval],[BUILD_DOCS="yes"]) AC_ARG_ENABLE([html-docs],[ --disable-html-docs Disable building html documentation from SGML sources], [BUILD_HTML=$enableval],[BUILD_HTML="yes"]) AC_ARG_ENABLE([manpages],[ --disable-manpages Disable building man pages from SGML sources], [BUILD_MANPAGES=$enableval],[BUILD_MANPAGES="yes"]) dnl udev lib dir AC_ARG_WITH([udev-libdir], [AS_HELP_STRING([--with-udev-libdir=DIR], [location to install udev scripts [PREFIX/lib/udev]])], [UDEV_LIBDIR=$withval], [UDEV_LIBDIR='${prefix}'/lib/udev]) AC_SUBST([UDEV_LIBDIR]) dnl Checks for programs. AC_PROG_INSTALL AC_PROG_CC AM_PROG_CC_C_O dnl Cannot use AM_PROG_LEX since it does not pass the [noyywrap] option AC_PROG_LEX([noyywrap]) if test "$LEX" = ":" ; then LEX="$SHELL "$srcdir"/../missing flex" fi AM_MISSING_PROG(YACC,bison) LT_INIT #docs and manpages AC_PATH_PROGS([SGML2PDF_PATH], [dblatex jw], [no]) if test "$SGML2PDF_PATH" = "no" ; then AC_MSG_NOTICE([docbook-tools neither dblatex nor jw found, disabling pdf documentation]) BUILD_DOCS="no" fi AC_PATH_PROG([JW_PATH], [jw], [no]) if test "$JW_PATH" = "no" ; then AC_MSG_NOTICE([docbook-tools jw not found, disabling html documentation]) BUILD_HTML="no" fi # look for manpage xsl file in various locations AC_CHECK_FILE(/usr/share/sgml/docbook/xsl-ns-stylesheets/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL], ["/usr/share/sgml/docbook/xsl-ns-stylesheets/manpages/docbook.xsl"])) AC_CHECK_FILE(/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL], ["/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl"])) AC_CHECK_FILE(/usr/share/xml/docbook/xsl-stylesheets-1.79.2/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL], ["/usr/share/xml/docbook/xsl-stylesheets-1.79.2/manpages/docbook.xsl"])) AC_PATH_PROGS([SGML2XML_PATH], [sgml2xml osgml2xml], [no]) AC_PATH_PROG([XSLTPROC_PATH], [xsltproc], [no]) if test "$SGML2XML_PATH" = "no" || test "$XSLTPROC_PATH" = "no" || test -z $DOCBOOK_XSL ; then AC_MSG_NOTICE([sgml-man tools not found, disabling building man pages]) BUILD_MANPAGES="no" fi if test "$BIND_PYTHON" = "yes"; then AM_PATH_PYTHON([3.0],,[:]) if test "$PYTHON" = :; then AC_MSG_NOTICE([no usable python found, disabling python binding]) BIND_PYTHON="no" fi fi if test "$BIND_PERL" = "yes"; then AC_PATH_PROG([PERL], [perl], [no], []) if test "$PERL" = "no"; then AC_MSG_NOTICE([perl not found, disabling perl binding]) BIND_PERL="no" fi fi if test "$BIND_TCL" = "yes"; then SC_PATH_TCLCONFIG if [[ $no_tcl ]]; then AC_MSG_NOTICE([TCL config not found, disabling TCL binding]) BIND_TCL="no" else SC_LOAD_TCLCONFIG fi fi if test "$BIND_PHP" = "yes"; then AC_PATH_PROG([PHP_CONFIG], [php-config], [no],[]) if test "$PHP_CONFIG" = "no"; then AC_MSG_NOTICE([php-config not found, disabling PHP binding]) BIND_PHP="no" fi else PHP_CONFIG="no" fi dnl Checks for libraries. if test "$BIND_GUILE" = "yes"; then AC_CHECK_LIB([guile],[gh_define],[echo this prevents default actions from occurring > /dev/null], [BIND_GUILE="no";AC_MSG_NOTICE([libguile not found, disabling guile binding])],[]) fi AC_CHECK_LIB([readline], [readline], [readline_lib=yes;AC_SUBST([LIB_READLINE_LDFLAGS], ["-lreadline -lncurses"])], [], [-lncurses]) dnl Checks for header files. AC_CHECK_HEADERS(unistd.h sys/param.h sys/time.h time.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h ) if test "$BIND_PYTHON" = "yes"; then AM_CHECK_PYTHON_HEADERS([],[BIND_PYTHON=no;AC_MSG_NOTICE([python headers not found, disabling python binding])]) fi if test "$BIND_GUILE" = "yes"; then AC_CHECK_HEADER([libguile.h],[],[BIND_GUILE="no";AC_MSG_NOTICE([libguile headers not found, disabling guile binding])]) fi AC_CHECK_HEADER(readline/readline.h,[readline_h=yes]) AC_CHECK_HEADER(readline/history.h,[history_h=yes]) if test "$readline_lib" = "yes" && test "$readline_h" = "yes" && test "$history_h" = "yes"; then AC_SUBST([LIB_READLINE_CFLAGS], ["-DREADLINE"]) fi if test "$BIND_TCL" != "no"; then SAVE_CPPFLAGS=$CPPFLAGS CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC" AC_CHECK_HEADER([tcl.h],[],[BIND_TCL="no";AC_MSG_NOTICE([TCL headers not found, disabling TCL binding])]) CPPFLAGS=$SAVE_CPPFLAGS fi if test "$PHP_CONFIG" != "no"; then SAVE_CPPFLAGS=$CPPFLAGS CPPFLAGS="$CPPFLAGS $($PHP_CONFIG --includes) -D_GNU_SOURCE" AC_CHECK_HEADER([php.h],[],[BIND_PHP="no";AC_MSG_NOTICE([PHP headers not found, disabling PHP binding])]) CPPFLAGS=$SAVE_CPPFLAGS fi AC_HEADER_MAJOR AC_FUNC_ALLOCA AC_STRUCT_TM AC_STRUCT_ST_BLOCKS AC_FUNC_CLOSEDIR_VOID AC_CHECK_FUNCS([mkfifo]) AC_CHECK_FUNC([mknod]) dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for library functions. LIBGPIB_CFLAGS="-I\$(top_srcdir)/include -D_REENTRANT" LIBGPIB_LDFLAGS="\$(top_builddir)/lib/libgpib.la -lpthread" AC_SUBST([LIBGPIB_CFLAGS]) AC_SUBST([LIBGPIB_LDFLAGS]) IBMAJOR=160 AC_SUBST([IBMAJOR]) AC_DEFINE([IBMAJOR],[160],[Major number of device files]) echo echo Configuration: AM_CONDITIONAL([BUILD_DOCS], [test "$BUILD_DOCS" = "yes"]) echo "pdf documentation: $BUILD_DOCS" AM_CONDITIONAL([BUILD_HTML], [test "$BUILD_HTML" = "yes"]) echo "html documentation: $BUILD_HTML" AM_CONDITIONAL([BUILD_MANPAGES], [test "$BUILD_MANPAGES" = "yes"]) echo "man pages: $BUILD_MANPAGES" AM_CONDITIONAL([BIND_GUILE], [test "$BIND_GUILE" = "yes"]) echo "Guile binding: $BIND_GUILE" AM_CONDITIONAL([BIND_PERL], [test "$BIND_PERL" = "yes"]) echo "Perl binding: $BIND_PERL" AM_CONDITIONAL([BIND_PHP], [test "$BIND_PHP" = "yes"]) echo "PHP binding: $BIND_PHP" AM_CONDITIONAL([BIND_PYTHON], [test "$BIND_PYTHON" = "yes"]) echo "Python binding: $BIND_PYTHON" AM_CONDITIONAL([BIND_TCL], [test "$BIND_TCL" = "yes"]) echo "TCL binding: $BIND_TCL" AX_DEFINE_DIR([SYSCONFDIR], [sysconfdir], [System configuration directory]) AS_ECHO "sysconfdir: [$SYSCONFDIR]" AS_ECHO "" AC_CONFIG_FILES([\ Makefile \ drivers/Makefile \ lib/Makefile \ lib/libgpib.pc \ lib/gpib_config/Makefile \ examples/Makefile \ test/Makefile \ doc/Makefile \ include/Makefile \ include/gpib/Makefile \ language/Makefile \ language/guile/Makefile \ language/php/Makefile \ language/php/TESTS/Makefile \ language/python/Makefile \ language/tcl/Makefile \ usb/Makefile \ usb/ni_usb_gpib/Makefile \ usb/agilent_82357a/Makefile \ usb/lpvo_usb_gpib/Makefile \ ]) AC_OUTPUT contrib/000077500000000000000000000000001507046215500125235ustar00rootroot00000000000000contrib/Makefile000066400000000000000000000011441507046215500141630ustar00rootroot00000000000000# # Makefile for ieee488 application suite # # Please don't change this file ! # Subdirectories will be automagically scanned # SUBDIRS = `../util/subdirs` GPIB_HOME= `(cd ..;pwd)` MAKE = make GPIB_HOME=$(GPIB_HOME) -C all: subdirs subdirs: set -e;for i in $(SUBDIRS); do $(MAKE) $$i ; done clean: set -e;for i in $(SUBDIRS); do $(MAKE) $$i clean; done -find . -name "*.o" -exec rm {} \; install: set -e;for i in $(SUBDIRS); do $(MAKE) $$i install; done rcsput: set -e;for i in $(SUBDIRS); do $(MAKE) $$i rcsput; done rcsget: set -e;for i in $(SUBDIRS); do $(MAKE) $$i rcsget; done doc/000077500000000000000000000000001507046215500116305ustar00rootroot00000000000000doc/Makefile.am000066400000000000000000000035121507046215500136650ustar00rootroot00000000000000# doc/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. docs = linux-gpib.pdf SGML = linux-gpib.sgml gpib_version.txt EXTRA_DIST = linux-gpib.sgml fdl.xml gpib_version.txt $(docs) $(doc_DATA) $(manpages) if BUILD_DOCS all-local: $(docs) else all-local: endif if BUILD_HTML doc_DATA = doc_html/* else doc_DATA = endif if BUILD_MANPAGES man1_MANS = man/man1/* man3_MANS = man/man3/* man5_MANS = man/man5/* man8_MANS = man/man8/* manpages = man/man1/* man/man3/* man/man5/* man/man8/* man/man1/* man/man3/* man/man5/* man/man8/*: man man_stylesheet = $(DOCBOOK_XSL) else manpages = endif docdir = $(datadir)/doc/@PACKAGE@/html maintainer-clean-local: $(RM) gpib_version.txt $(RM) intEntities.dtf $(RM) -r $(docs) doc_html man linux-gpib.pdf: $(SGML) if test `basename $(SGML2PDF_PATH)` = "jw" ; then \ $(SGML2PDF_PATH) -f docbook -b pdf $(srcdir)/linux-gpib.sgml ; \ else \ $(SGML2PDF_PATH) $(srcdir)/linux-gpib.sgml -F sgml -P table.in.float=none -o linux-gpib.pdf ; \ fi doc_html/*: $(SGML) { $(JW_PATH) -f docbook -b html -o doc_html -V '%use-id-as-filename%' $(srcdir)/linux-gpib.sgml; } && { touch doc_html/* ; } man: $(SGML) { $(SGML2XML_PATH) -x no-expand-internal -x no-internal-decl -x preserve-case $(srcdir)/linux-gpib.sgml | \ $(XSLTPROC_PATH) --param man.authors.section.enabled 0 --param man.output.in.separate.dir 1 \ --xinclude $(man_stylesheet) -; } && { touch man; } gpib_version.txt: if [ ! -f gpib_version.txt ] || [ `echo $(VERSION)` != `cat gpib_version.txt` ]; then \ echo $(VERSION) > gpib_version.txt; \ fi doc/fdl.xml000066400000000000000000000540001507046215500131160ustar00rootroot00000000000000 GNU Free Documentation License Version 1.2, November 2002
PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.
APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.
VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies.
COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.
MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. State on the Title page the name of the publisher of the Modified Version, as the publisher. Preserve all the copyright notices of the Document. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. Include an unaltered copy of this License. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.
COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements".
COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.
AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.
TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.
TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.
ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this:
with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
doc/greg_goebel_hpib_tutorial.html000066400000000000000000006752231507046215500177230ustar00rootroot00000000000000 A Tutorial Introduction To HPIB

A Tutorial Introduction To HPIB

v4.1 / 01 jan 99 / greg_goebel / public domain / hpib_tutorial

* This document is a tutorial introduction to the HPIB interface, covering theory and use of the HPIB from fundamental specs to instrument programming and HPIB card configuration.


Table Of Contents

[1.0] HPIB Tutor (1): Introduction

[2.0] HPIB Tutor (2): HPIB 488.1 / HPIB Fundamentals

[3.0] HPIB Tutor (3): IEEE 488.2 -- Overview & Data Formats

[4.0] HPIB Tutor (4): 488.2 Common Commands & Status

[5.0] HPIB Tutor (5): Introduction To SCPI

[6.0] HPIB Tutor (6): A SCPI-Based HPIB Instrument -- The 34401 DMM

[7.0] HPIB Tutor (7): Notes & Comments


[1.0] HPIB Tutor (1): Introduction

* This section provides a tutorial overview of the Hewlett-Packard Interface Bus (HPIB) interface system, also known as the General-Purpose Interface Bus (GPIB) or by its Institute of Electrical and Electronic Engineers (IEEE) specification number, IEEE-488. HPIB is a scheme by which groups of devices may be connected to a controlling computer and communicate under its direction. It is highly standardized and instruments from multiple vendors can be operated in the same HPIB system.

The HPIB standard is defined at several levels:

  • The original 488.1 specification defines the mechanical and electrical characteristics of the interface and its fundamental protocols.
  • The 488.2 specification refines the 488.1 spec to define an acceptable minimum configuration, and adds specifications for a basic set of instrument commands and common data formats.
  • The SCPI (Standard Commands for Programmable Instrumentation) specification provides a detailed description of instrument commands that can be transferred over the HPIB. Strictly speaking, the SCPI commands can be implemented on an instrument using any sort of interface -- HPIB, serial/RS-232, VXI backplane, tins and strings, or whatever -- but they are so applicable to HPIB that no discussion of HPIB would be complete without them.

This document is divided into modules to discuss the following topics:

  • Fundamental HPIB (488-1) operation.
  • 488.2 specs and data formats.
  • 488.2 commands.
  • SCPI commands.
  • A SCPI instrument, the 34401A DMM.
  • Comments on benchmarking and passing control.

There are plenty of source materials available for these topics and I have made full use of them. Materials on 488.1 and 488.2 are derived from the HP publication A TUTORIAL DESCRIPTION OF THE HEWLETT-PACKARD INTERFACE BUS, while the SCPI material is derived from Barry Eppler's A BEGINNER'S GUIDE TO SCPI. Of course, the section on the ALF draws heavily on the 34401A manual.

This document requires a knowledge of fundamental computer concepts and nomenclature. A small knowledge of electronics technology is also useful. Little other knowledge is assumed.

* If you are using this document for self-study rather than reference, a few guidelines should help you make the best use of it:

  • All the material on 488.1 is fundamental and very useful, except possibly for the discussion of parallel poll (one of the few features of the basic spec that is of questionable use).

    Very careful attention should be paid to the example program, which shows how the protocols actually work in practice. The section on "HPIB IN PRACTICE" helps give more background on the actual environment in which HPIB is used.

  • The discussion of 488.2 data formats does not need to be absorbed in detail. Just read it to get a general idea of the different types of formats, and refer back to it if necessary.
  • The discussion of 488.2 commands provides a core command set for modern instrument programming. Some 488.2 commands are commonly used, however, while some are not, and this module has separate sections to discuss the two classes of commands. Please pay close attention to the section on important commands, and simply skim through the section on secondary commands. The section on status and triggering should be read carefully, but you don't need to absorb it in detail.
  • The discussion of SCPI and the ALF should be read carefully, but you don't need to absorb it in detail. That will come when you work on a particular instrument in practice. Tinkering with ALF programming is highly recommended, however.

* I wrote this document out of a sense of frustration. HPIB has been a core concern of my work for many years, but at the same time I never really felt like I understood the topic through its full spectrum, in the proper balance between minor details and broad application.

The fact that there was no document available that described HPIB all the way from the fundamental definitions up to implementations led me to want to write one myself. I wanted to not only ensure that I did in fact have an understanding of that full range, but also to spare others the roundabout path I took to get there.

The first major version was basically a ripoff of the source materials. The second major version was a complete rewrite and reorganization of the first (that started out, ironically, as an attempt to correct a single typographic error and got remarkably out of hand).

The second version is far superior to the first since it focuses on practical concepts rather than some of the (sometimes bewildering and excessive) theory devised to support the 488.2 and (in particular) SCPI specs.

While this document is necessarily terse -- it covers a very wide range of material -- you should find it informative and (if you can get into this sort of thing) even entertaining.

* Some of the intermediate versions of this tutorial included materials on actual programming interfaces for HPIB, and how to configure PC HPIB and GPIB cards for the PC. For various reasons, this turned out to be a clumsy organization, and so those intermediate versions evolved into three independent document: this tutorial overview; a document on programming interfaces; and a document on HPIB card configuration.


[2.0] HPIB Tutor (2): HPIB 488.1 / HPIB Fundamentals

* This module provides an overview of the fundamental HPIB specification, IEEE 488.1



BACK TO INDEX

[2.1] 488.1 OVERVIEW

* The Hewlett-Packard Interface Bus (HPIB) is a strictly-defined general-purpose computer interface system, in effect an external computer bus that allows interconnection of instruments and other devices to a controlling computer. General specifications of HPIB include:

  • A bus configuration will consist of a single Active Controller (though on occasions several controllers may reside on the same bus and "pass control" among each other) and one or more devices that can be instructed to "talk" or "listen" as instructed by the controller.
  • Fifteen devices may be connected to one continuous bus.
  • Total transmission path lengths over the interconnecting cables does not exceed 20 meters or 2 meters per device, whichever is less (when not using a bus extension technique).
  • Data rate across the interface does not exceed 1 megabyte per second. (This data rate is rarely achieved in practice.)

Investigations for an interface system that led to the HPIB spec began in 1965, and eventually resulted in the first HPIB spec, now designated IEEE 488.1-1975. Further work and investigations led to the additional spec for common commands and data formats, designated IEEE-488.2-1987.

There are other specifications related to IEEE-488.1. The ANSI MC1.1 spec provides a definition identical to 488.1. The IEC 625-1 and BS 6146 standards are the same as 488.1, except that they provide interconnections through a 25-pin subminiature "D" connection, identical to that used on serial (RS-232) interfaces. These IEC and BS standards are very little used.

The 488.1 and related specifications cover the logical, electrical, and mechanical specs of the HPIB system. The 488.2 spec extends this definition to provide a small set of common instrument commands and specifications for data to be sent over the HPIB. A further new specification, known as SCPI (Standard Commands for Programmable Instrumentation), defines instrument command sets for use over HPIB or other interfaces. 488.2 and SCPI are discussed in later modules in this series.

* The key specifications of IEEE 488.1 are listed below:

  • Interconnected devices: Up to 15 maximum on one contiguous bus.
  • Interconnection path: Star or linear (or mixed) bus network, up to 20 meters total transmission path length.
  • Signal lines: 16 active lines, consisting of 8 data lines and 8 communications management lines.
  • Message transfer scheme: Byte-serial, bit-parallel, asynchronous data transfer using an interlocking 3-wire handshake.
  • Maximum data rate: 1 megabyte per second over limited distances, 250 to 500 kilobytes per second typical maximum over a full transmission path. The actual data rate is determined by the devices on the bus.
  • Address capability: Primary addresses, 31 Talk and 31 Listen; secondary addresses, 961 Talk and 961 Listen. There can be a maximum of 1 Talker and up to 14 Listeners at a time on a single bus.
  • Pass control: In systems with more than one controller, only one can be active at a time. The currently active controller can pass control to one of the others. A non-active controller may request control. Only the controller designated as System Controller can demand control.

[2.2] HPIB FUNCTIONS & CAPABILITIES

* The operation of the HPIB can be compared to that of a committee. A committee chairman controls which member talks and implies that the others should listen. IEEE 488.1 has one device that controls, deciding who talks and who listens (under normal circumstances the controlling device will be one half of the conversation, but it doesn't have to be). Every IEEE 488.1 device must be capable of performing one or more of the following interface functions:

  • Listener: A device capable of receiving data over the interface when addressed to Listen by the Active Controller. Examples of such devices are printers, programmable power supplies, or any other programmable instrument. There can be up to 14 Listeners on the HPIB at one time; usually the Active Controller will be a Talker while a single device is a Listener.
  • Talker: A device capable of transmitting data over the interface when addressed to Talk by the Active Controller. Examples of such devices are voltmeters, data-acquisition systems, or any other programmable instrument. There can be only one addressed Talker on the HPIB at one time. Usually the Active ontroller will be a Listener while a device is a Talker.
  • Controller: A device capable of specifying the Talker and Listeners for a data or command transfer. Note that the Active Controller will be configured as Listener or Talker to support its end of the transfer. There can be only one addressed controller on the interface at one time; in multiple controller systems active control may be passed between controllers, but only one can be a master "System Controller".

The IEEE 488.1 spec defines these functions in (agonizingly) concise terms using abstract state machines labeled with rigorously-defined nomenclature. These functions are referred to as interface capabilities.

There are other interface capabilities besides Listener, Talker, or Controller, which are also defined in the 488.1 spec as state machines. These functions are listed below, along with their abbreviations:

  • Talker / Extended Talker (T / TE): Capability required for a device to Talk. Extended Talker is a Talker that supports secondary addressing.
  • Listener / Extended Listener (L / LE): Capability required for a device to Listen. Extended Listener is a Listener that supports secondary addressing.
  • Source Handshake (SH): Allows a device to send command or data bytes over the HPIB using the HPIB "three-wire handshake" (to be explained presently).
  • Acceptor Handshake (AH): Allows a device to receive command or data bytes over the HPIB using the three-wire handshake.
  • Remote / Local (RL): Provides the capability to switch a device between response to its front-panel controls (LOCAL) and response to commands sent over the HPIB (REMOTE).
  • Service Request (SR): Allows a device to assert an interrupt, or "service request" (SRQ), over the HPIB to obtain service from the Active Controller.
  • Parallel Poll (PP): Provides the capability for a device to identify that it needs service when the Active Controller requests such status. This particular capability is little used.
  • Device Clear (DC): Allows a device to be reset. Its actions are implementation-dependent.
  • Device Trigger (DT): Allows a device to be "triggered" by an HPIB command to perform some implementation-dependent function.
  • Controller (C): Allows a device to send addresses, universal commands, and addressed commands to other devices on the HPIB. It may also include the capability to conduct polling to determine devices requiring service.
  • Drivers (E): Describes the type of electrical bus drivers used in a device.

The IEEE 488.1 spec also defines subsets of these functions, given by a number appended to the function code. The spec recommends that each device be marked near its connector with the interface capability codes for the functions the device supports.

For example, a device with:


   Talk capability.
   The ability to send status bytes.
   Listen capability.
   A Listen-only mode switch.
   Service request capability.
   Full remote-local capability without local lockout.
   Local configuration of the parallel poll capability.
   Complete device clear capability.
   No capability for device trigger.
   No Controller capability.

-- would be identified with these codes:


   SH1  AH1  T6  L3  SR1  RL2  PP2  DC1  DT0  C0  E1

A full description of the IEEE 488.1 spec's discussion of these capabilities is far beyond the scope of this document, and is in fact generally only useful for design engineers building HPIB devices.

[2.3] HPIB SIGNAL LINES & COMMANDS

* The physical interconnection system used in HPIB uses a shared-bus structure, with 16 signal lines and 8 ground lines. The bus signal lines all use a low-true logic convention, and can be grouped into 3 sets:

  • data lines
  • byte transfer (handshake) lines
  • general bus managment lines

The organization of the signal lines is shown below:


   DIO1 ---------------------------------  -+
   DIO2 ---------------------------------   |
   DIO3 ---------------------------------   |
   DIO4 ---------------------------------   | data lines
   DIO5 ---------------------------------   |
   DIO6 ---------------------------------   |
   DIO7 ---------------------------------   |
   DIO8 ---------------------------------  -+
 
   NDAC ---------------------------------  -+
   NRFD ---------------------------------   | handshake lines
    DAV ---------------------------------  -+

    EOI ---------------------------------  -+
    REN ---------------------------------   |
    SRQ ---------------------------------   | general bus management lines
    ATN ---------------------------------   |
    IFC ---------------------------------  -+

The signal lines use TTL voltage levels. The pinouts are as follows:


                                            * 
                                       *      * 
                                  *           *
                  SIGNAL GROUND   * [24] [12] *   SHIELD (to earth ground)
   twisted-pair ground with ATN   * [23] [11] *   ATN
   twisted-pair ground with SRQ   * [22] [10] *   SRQ
   twisted-pair ground with IFC   * [21] [ 9] *   IFC
   twisted-pair ground with NDAC  * [20] [ 8] *   NDAC
   twisted-pair ground with NRFD  * [19] [ 7] *   NRFD
   twisted-pair ground with DAV   * [18] [ 6] *   DAV
                            REN   * [17] [ 5] *   EOI
                           DIO8   * [16] [ 4] *   DIO4
                           DIO7   * [15] [ 3] *   DIO3
                           DIO6   * [14] [ 2] *   DIO2
                           DIO5   * [13] [ 1] *   DIO1
                                  *           *
                                       *      *
                                            * 

The data lines allow information transfer a byte at a time. Device commands and data are often transferred as strings of ASCII characters for ease of use, while large blocks of data are often transferred as binary data for speed and compactness. The data lines are also used by the HPIB protocol to send HPIB interface commands and addresses as bytes.

The three handshake lines are used to transfer bytes over the data lines from a source (an addressed Talker or an Active Controller) to an acceptor (an addressed Listener or all devices receiving interface commands). The byte transfer controlled by the handshake lines allows more than one device to accept bytes simultaneously, and is "asynchronous": that is, the rate of byte transfer is determined both by the source and acceptor(s), and can in principle take as long as necessary. When there are multiple acceptors, the byte transfer will take place at the speed of the slowest one.

The three handshake lines are defined as follows:

  • DAV (DAta Valid): Used by the source to indicate that a byte is ready to be read.
  • NRFD (Not Ready For Data): Used by acceptor to indicate that it is not ready to receive a byte.
  • NDAC (Not Data Accepted): Used by the acceptor to indicate that it has not yet read the byte.

The low-true logic of the handshake lines can be confusing. The protocol can be outlined as follows:


   1:  NRFD HIGH   All acceptors ready for byte.
   2:  DAV LOW     Source says byte is valid ...
   3:  NRFD LOW    ... so acceptors drop NRFD line.
   4:  NDAC HIGH   All acceptors have accepted byte ...
   5:  DAV HIGH    ... so source raises DAV line ...
   6:  NDAC LOW    ... and acceptors drop NDAC line.
   1:  NRFD HIGH   All acceptors ready for next byte, cycle begins again.
 

Neither NRFD nor NDAC will go high unless all acceptors make them high. This allows the speed of the byte transfer to be controlled by the slowest acceptor. all

The following illustration shows the handshake in a different way:


      +---------------------------------------------------------------+
      |                                                               |
      |             .......................               ........... |
 byte | ............                       ...............            |
      |             .......................               ........... |
      |                                                               |
      | ..............                   ....................         |
 DAV  |              :                   :                  :         |
      |              :...................:                  :........ |
      |                                                               |
      |       ...........                            ...........      |
 NRFD |       : : :     :                            : : :     :      |
      | ......:.:.:     :............................:.:.:     :..... |
      |                                                               |
      |                           ...........                         |
 NDAC |                           : : :     :                         |
      | ..........................:.:.:     :........................ |
      |                                                               |
      +-----------+--+--+-------------+--+--+------------+--+--+------+
                  |  |  |             |  |  |            |  |  |
                  1  2  3             4  5  6            1  2  3
 

* The five general bus management lines are used to manage the orderly flow of information over the HPIB:

  • ATN (ATtentioN): The ATN line is used by the Active Controller to indicate to all the devices on the HPIB that command and address bytes are being sent. These bytes are used to address Listeners and Talkers, obtain device status, and the like. When ATN is asserted, all devices must be able to respond to it within 200 nanoseconds and cease their current HPIB operations.
  • IFC (InterFace Clear): The IFC line is used by the System Controller to reset the HPIB. When IFC is asserted, all devices must respond within 100 microseconds: the Talker and Listeners are unaddressed and Serial Poll is disabled.
  • REN (Remote ENable): The REN line is used by the System Controller to put devices in the remote programming mode. When asserted, all Listeners are placed in remote mode when addressed to Listen.

    The 488.1 spec was relaxed in 1987 to permit devices to ignore the state of this line, but older devices will honor it.

  • SRQ (Service ReQuest): The SRQ line is used by HPIB devices to interrupt the Active Controller, which then performs a Serial Poll or Parallel Poll to determine which device requested service, and why. The poll clears the SRQ.
  • EOI (End Or Identify): When ATN is asserted, the EOI line is used by the Active Controller to conduct a Parallel Poll. When ATN is false, the EOI line may be used by the Talker to indicate the last byte of a stream of bytes.

The signal lines are driven either by open-collector or tristate drivers. Maximum data rate is 250 kilobytes per second for open-collector drivers and 1 megabyte per second for tristate drivers.

The connector for the HPIB cable allows connectors to be stacked on top of each other, to allow for daisy-chained or star connections (though the stack grows clumsy above three levels of stacking). Some specialized HPIB cables (such as those often used on personal computers, where access to I/O cards is mechanically restricted) may have a connector that does not permit stacking.

* Note the important distinction between the operation of the HPIB when ATN is asserted and when it is released. When ATN is asserted by the Active Controller, the HPIB is in Command Mode: the Active Controller configures the HPIB or performs other control tasks. When ATN is released, the HPIB is in data mode: the addressed Talker sends bytes to the addressed Listeners.

In Command Mode, the Active Controller sends four classes of commands:

  • Talk and Listen addresses are bytes that define which device on the HPIB will be the active Talker and which will be the active Listeners. When ATN is asserted, all devices will be waiting for commands. All will receive the address bytes, and those who match those addresses will accept them.
  • Universal commands are commands the Active Controller sends to all devices on the HPIB, and all instruments capable of reacting to the commands do so. The universal commands include five commands encoded as bytes sent over the DIO lines ("multiline" commands) and four commands sent using the general bus management lines ("uniline" commands).
  • Addressed commands are byte commands similar to the universal multiline commands, except that they apply only to those devices that have been addressed.
  • Secondary commands are byte commands that are always used in addition to addresses, multiline universal commands, or addressed commands (the "primary commands") to add command functionality. They are used, for example, to support secondary addressing.

In data mode (ATN released), device-dependent data (device programming command bytes, measurement data bytes, and status bytes) is transferred from the addressed Talker to the addressed Listeners. Only the addressed Listeners actually handshake the byte.

The actual format for the device-dependent data is beyond the scope of the 488.1 spec. It can, and does, have any format desired by the device manufacturers. The 488.2 and SCPI specs have made substantial progress in clearing up this chaotic situation, however.

* Most common operations on an HPIB consist of byte transfers between an addressed Talker and addressed Listener(s), as well as capabilities to clear devices either singly or universally, and trigger them to perform some device-dependent function. The signal lines and command set, as described above, also support some other functionality:

  • A device can interrupt the Active Controller by asserting the SRQ line, as discussed above. The SRQ is a single line, however, and if there are multiple devices on the HPIB that have been configured to assert an SRQ, the Active Controller will have to "poll" the devices to figure out which one actually asserted the SRQ.

    More than one device could in principle assert an SRQ at the same time. The Active Controller can poll the devices in one of two ways: serial poll or parallel poll.

  • In a serial poll, the Active Controller asks each device in turn to send back a status byte that indicates whether the device has asserted the SRQ.

    Bit 6 of this byte (where the bits are numbered 0 through 7) is set if the device is requesting service. The definition of the other bits is device-dependent (under 488.1 at least; 488.2 provides a much more concise definition of the status byte).

    The Active Controller performs a serial poll by addressing the device to Talk, then sends the SPE (Serial Poll Enable) command byte. The Active Controller releases ATN, and the device returns the status byte. The Active Controller then reasserts ATN and sends the SPD (Serial Poll Disable) command byte to end the poll sequence. The Active Controller performs this same sequence with every device it needs to poll.

  • That makes serial poll of a large system relatively slow, so the 488.1 spec also defines a parallel poll that allows multiple devices to respond simultaneously. However, this scheme is so complicated that it is almost never used. (We had an HPIB product that implemented parallel poll, but did it with an unavoidable bug. We didn't find out about it for almost three years after it was introduced.)

    In a parallel poll, each device is assigned one of the 8 DIO lines to respond on, as well as whether to respond with a 1 or with a 0. This assignment is made by sending the PPC (Parallel Poll Configure) command byte to the addressed Listeners, followed by a PPE (Parallel Poll Enable) secondary command (which can take on a range of values large enough to encode all the response options).

    To parallel poll the devices, the Active Controller asserts the EOI and ATN lines simultaneously, and all the devices capable of responding to parallel poll put their approriate 1 or 0 on their appropriate DIO line in response. The Active Controller reads this composite byte and uses it to determine which devices have requested service.

    To disable parallel poll, the Active Controller sends a PPC command byte to the addressed Listeners, followed by a PPD (Parallel Poll Disable) secondary command byte.

  • It is also possible to have multiple controllers on the same HPIB. One is designated System Controller; it is the only one that has control of the IFC line. It can pass active control of the HPIB to another controller, which can pass control in turn to a third controller, and so on. The System Controller can always take back control from the Active Controller by asserting IFC to bring the HPIB back to its reset configuration.

    The Active Controller can pass control to another controller by addressing it to Talk and then sending it the TCT (Take Control) addressed command byte. This capability is infrequently used (and tends to lead to a lot of trouble when people use it and don't understand it).

The addressing scheme and command bytes are discussed in more detail in the following sections.

[2.4] HPIB ADDRESSING

* Every 488.1 device has at least one Talk and Listen address (with the exception of freak antique devices that only Talk or Listen). A device's address is normally set at the factory, but can traditionally be changed (in older devices) by adjusting a set of DIP switches or (in more modern instruments) with front-panel inputs. Many devices display their HPIB address on power-up.

If the device has DIP switches, they are usually arranged as follows:


       1    2    4    8   16
   +---------------------------+
   |  +-+  +-+  +-+  +-+  +-+  | 1
   |  |X|  | |  |X|  | |  | |  |
   |  | |  |X|  | |  |X|  |X|  |
   |  +-+  +-+  +-+  +-+  +-+  | 0
   +---------------------------+
       A1   A2   A3   A4   A5
 

This switch setting gives an address of 5. In nearly all cases an instrument has the same Talk and Listen address. The 488.1 spec allows them to be different, but in practice that is a useless complexity. Most modern instruments allow the user to press a button to display the current HPIB address to eliminate the need to turn the instrument around and figure out the switch settings.

The switch settings allow the device to be set to Talk/Listen addresses from 0 to 30. The Listen address bytes are defined by adding a decimal value of 32 to the address, while the Talk address bytes are defined by adding a decimal value of 64 to the address. For the example given by the switch settings above, this gives the following address bytes:


   Listen address 5 = 32 + 5 = 37 decimal = 001 00101 binary
   Talk address 5 =   64 + 5 = 69 decimal = 010 00101 binary
 

The Talk and Listen address bytes are often referred to in documentation by the mnemonics TAD (Talk ADdress) and LAD (Listen ADdress). The full range of Talk addresses is therefore given by TAD0 through TAD30, and the full range of Listen addresses is given by LAD0 through LAD30.

Remember that a Controller also has a Talk and Listen address to allow it to transfer bytes in data mode to other devices on the HPIB. 21 and 30 are common Controller Talk / Listen addresses in HP equipment, though it can be any address. Note that adding a device with the same address as the Controller is a common error, and can lead to baffling problems.

The Controller's Talk and Listen address are often referred to as MTA (My Talk Address) and MLA (My Listen Address) for convenience, but there's no difference between the address format used by the Controller and by devices. Note that the Controller has to send the address bytes even when it is addressing itself!

Note also that the address switches can physically be set to a value of 31, but that is not a valid HPIB address! The address byte that has the value 32 + 31 = 63 decimal is not LAD31, it's a special address byte called Unlisten (UNL), which tells the currently addressed Listeners to stop being Listeners, usually preparatory to addressing new Listeners.

Similarly, the address byte that has the value 64 + 31 = 95 decimal is not TAD31, it's a special address byte called Untalk (UNT), which tells the currently addressed Talker to stop being a Talker, usually preparatory to assigning a new Talker.

Actually Untalk is a little redundant, since sending out a new TAD will automatically Untalk the current Talker -- as there can be only one Talker at a time.

* As noted, the 488.1 spec allows the 31-address limit to be extended to 961 addresses with a "secondary address" byte. This byte is sent after a LAD or TAD byte and consists of the decimal value 96 added to an address in the range of 0 through 30. This secondary address byte is referred by the mnemonic SC, giving the secondary address bytes SC0 through SC31.

There is no secondary address 31, even though that byte is not otherwise used. Apparently this convention was specified for consistency with the primary Talk/Listen address bytes.

Secondary addresses are not normally used to allow addressing of more devices on the HPIB. As noted, the HPIB cannot accommodate more than 15 instruments under normal conditions, and the idea of a system having anywhere near 961 devices is hard to take seriously. It is more often used to allow individual access to different modules in a modular instrument system, such as a VXI mainframe or data-acquisition box, which in either case consist of a chassis containing multiple plug-in cards that perform separate functions.

There are modular devices in which different modules are selected by sending a high-level command to the mainframe in which they are plugged. Such schemes are not standardized and vary widely, but are collectively referred to as "subaddressing", if only as a term of convenience. Please take care when programming a modular instrument to determine if the instrument supports secondary addressing or subaddressing.

[2.5] HPIB COMMANDS

* The five universal multiline (byte) commands are, as noted, accepted by all devices on the HPIB. The commands consist of:

  • DCL (Device CLear): The universal DCL command causes all devices to return to a device-dependent initial state.
  • LLO (Local LockOut): The LLO command disables the return-to-local front panel key on the device; the user can no longer change the device settings from its front panel.
  • SPE (Serial Poll Enable): The SPE command tells the addressed Talker to return a single status byte. This status byte tells whether the device has asserted an SRQ (indicated by bit 6 set to 1).
  • SPD (Serial Poll Disable): The SPD command takes the device out of serial poll mode and returns it to normal Talker activity.
  • PPU (Parallel Poll Unconfigure): The PPU command resets all parallel poll devices to an idle state. As noted earlier, parallel poll is little used.

* The four complementary uniline universal commands consist of the three general bus managements lines IFC, REN, and ATN executing their normal functions, plus the combination of EOI and ATN, which is used to conduct a parallel poll, as described earlier.

* The addressed command bytes are only accepted by addressed devices. Whether the devices are the Listeners or the Talkers depends on the command. The five commands are as follows:

  • GET (Group Execute Trigger): The GET command tells all the addressed Listeners to perform some device-dependent function, like take a measurement. GET allows for synchronizing a measurement function between multiple devices. This is only used in specialized cases.
  • SDC (Selected Device Clear): The SDC command resets the addressed Listeners to a device-dependent state. It performs the same function as DCL, but only resets the addressed Listeners, not all the devices.
  • GTL (Go To Local): The GTL command sets the addressed Listeners back to local mode.
  • PPC (Parallel Poll Configure): The PPC command causes the addressed Listeners to be configured by the Parallel Poll Enable secondary command byte that immediately follows this byte.
  • TCT (Take Control Talker): The TCT command tells the addressed Talker to become the active Controller.

* The two secondary commands consist the PPE (Parallel Poll Enable) and PPD (Parallel Poll Disable). Both are send to the addressed Listeners after they receive the PPC byte.

PPE actually consists of a set of commands that have the exact same values (96 plus 0 through 30) as the secondary address bytes. A PPE command byte is distinguished from the matching secondary address byte by the fact that a PPE byte follows a PPC command byte, while the secondary address byte follows a Talk or Listen address.

PPE configures the addressed Listeners that receive it to respond to a parallel poll by setting a given DIO line to a particular polarity (1 or 0). PPD tells the addressed Listeners not to respond to a parallel poll.

[2.6] HPIB IN OPERATION -- AN HP BASIC EXAMPLE

* Now that we have considered the theoretical aspects of the 488.1 specification, let's put all these details together by observing the HPIB transactions of a typical HPIB controller.

In this case, the controller is a computer running HP's measurement-oriented HP BASIC language, connected to a 34401 digital multimeter (DMM) over HPIB. The Controller's HPIB interface is designated by a one-digit number code called an "interface select code", or ISC. The default ISC is usually 7.

The DMM is set to its default HPIB address of 22. HP BASIC locates the instrument by tacking the HPIB address onto the end of the ISC, so the DMM is identified by the number 722. The controller itself in this case has a default Talk/Listen address of 30.

The following HP BASIC program clears the DMM, reads a DC voltage from it, prints it, serial-polls the DMM, and prints the results. The only reason that the serial poll is conducted is to give the program another thing to show off. There normally isn't any reason to do a serial poll after taking a measurement, though it is a simple way to determine if any gross instrument errors have occurred.


   10    REAL Rdg
   20    INTEGER Stat
   30    ASSIGN @Dmm TO 722                    ! Define DMM HPIB address.
   40    CLEAR 7                               ! Clear HPIB interface.
   50    OUTPUT @Dmm;"*RST"                    ! Reset DMM. 
   60    OUTPUT @Dmm;"*CLS"                    ! Clear DMM.
   70    OUTPUT @Dmm;"MEASURE:VOLTAGE:DC? DEF" ! Measure DC voltage.
   80    ENTER @Dmm;Rdg                        ! Get value back.
   90    PRINT "Reading Value:      ";Rdg      ! Print it.
   100   Stat=SPOLL(@Dmm)                      ! Serial poll DMM.
   110   PRINT "Serial Poll status: ";Stat     ! Print status value.
   120   END
 

Let's take a look at the statements in the program in detail.

* The first three lines simply declare variables. "Rdg" is a REAL variable used to store the voltage reading; "Stat" is an INTEGER variable used to store the status byte returned by the serial poll; and "@Dmm" is an "I/O path" or "I/O handle" that stores the device address of 722.

The statement:


   CLEAR 7

-- simply clears all the devices on the HPIB, though there's only one in this case. The HPIB operations performed are as follows:


   REN  ATN      : DCL
 

This table and the ones that follow give the byte(s) transferred by the HP BASIC statement and the status of the bus-management lines. The 3-wire handshake is implied in each byte transfer, and so will not be mentioned. Just remember that each line in a table defines a single byte transfer using the 3-wire handshake.

The right side of the table gives the byte transferred. In this case it is the universal command byte, DCL, or Device CLear, which clears the interfaces of the instruments on the HPIB.

The left side of this table gives the status of the three control lines REN, ATN, and EOI. SRQ and IFC are always inactive in this sequence of examples, so they won't be shown. REN and ATN are active, indicating a command byte, so they are shown. EOI is inactive and is not shown.

The next statement is:


   OUTPUT @Dmm;"*RST"
 

The OUTPUT statement is used by HP BASIC to send bytes over the HPIB to the remote device, the DMM. In this example, the following bytes are sent:


   REN  ATN      : TAD30 (MTA)
   REN  ATN      : UNL
   REN  ATN      : LAD22
   REN           : "*"
   REN           : "R"
   REN           : "S"
   REN           : "T"
   REN           : CR
   REN           : LF
 

The first three bytes are sent to set up the Controller as a Talker and the DMM as a Listener, and then the ASCII string "*RST" (device Reset) is sent to the DMM. The string is "terminated" by the carriage-return (CR) and line-feed (LF) control characters -- that is, when the DMM receives the CR-LF, it assumes that the command is complete and acts upon it.

Note how ATN is active when sending the three HPIB command bytes, and how it is inactive when sending the instrument command string.

Another OUTPUT statement follows:


   OUTPUT @Dmm;"*CLS"
 

This performs roughly the same actions as the first OUTPUT statement but with a different string, "*CLS" (clear status):


   REN  ATN      : TAD30 (MTA)
   REN  ATN      : UNL
   REN  ATN      : LAD22
   REN           : "*"
   REN           : "C"
   REN           : "L"
   REN           : "S"
   REN           : CR
   REN           : LF
 

Note that the OUTPUT statement sends the same MTA-UNL-LAD22 addressing sequence that was sent in the previous step. In theory that is redundant -- the Controller is already the addressed Talker and the DMM is already the addressed Listener -- and in fact there is a way in HP BASIC to eliminate the addressing sequence, but in practice that is generally a useless micro-efficiency.

Note also that "*RST" and "*CLS" are "common commands" that are defined by the 488.2 spec. They will be discussed in more detail in a later chapter.

The question arises: why send these commands if we've already sent a DCL? Simple answer: DCL only resets the HPIB interface on the DMM, and returning the instrument to a completely known state requires a little more work.

The third OUTPUT statement:


   OUTPUT @Dmm;"MEASURE:VOLTAGE:DC? DEF"
 

-- sends the DMM command bytes needed to tell the DMM to read a DC voltage:


   REN  ATN      : TAD30 (MTA)
   REN  ATN      : UNL
   REN  ATN      : LAD22
   REN           : "M"
   REN           : "E"
   REN           : "A"
   REN           : "S"
   REN           : "U"
   REN           : "R"
   REN           : "E"
   REN           : ":"
   REN           : "V"
   REN           : "O"
   REN           : "L"
   REN           : "T"
   REN           : "A"
   REN           : "G"
   REN           : "E"
   REN           : ":"
   REN           : "D"
   REN           : "C"
   REN           : "?"
   REN           : " "
   REN           : "D"
   REN           : "E"
   REN           : "F"
   REN           : CR
   REN           : LF
 

Other than the string being longer, this is identical in logic to the previous two output statements. Note that the DMM command conforms to the SCPI command set, which will be discussed in detail in a later chapter. The command string's meaning in this case should be obvious, except for the "DEF" string, which specifies the DEFault voltage range for the DMM.

Now that the HP BASIC program has told the DMM to read the voltage using an OUTPUT statement, the program has to read the voltage value back, using the matching ENTER statement:


   ENTER @Dmm;Rdg
 

This performs the actions:


   REN ATN       : UNL
   REN ATN       : LAD30 (MLA)
   REN ATN       : TAD22
   REN           : "-"
   REN           : "1"
   REN           : "."
   REN           : "4"
   REN           : "5"
   REN           : "0"
   REN           : "5"
   REN           : "2"
   REN           : "0"
   REN           : "4"
   REN           : "0"
   REN           : "E"
   REN           : "+"
   REN           : "0"
   REN           : "1"
   REN       EOI : LF
 

The ENTER statement is similar to the OUTPUT statement, except that the direction of byte transfer is reversed: the Controller is the Listener and the DMM is the Talker. The DMM returns the voltage value as a string; the terminator at the end of the value is a line-feed combined with assertion of the EOI line. This particular termination scheme is defined in the 488.2 spec.

Once the program receives the voltage value back, it is printed to the computer's display with:


   PRINT "Reading Value:      ";Rdg
 

The HP BASIC program then queries the DMM for serial-poll status with:


   Stat=SPOLL(@Dmm)
 

This performs the following actions:


   REN ATN       : UNL
   REN ATN       : LAD30 (MLA)
   REN ATN       : TAD22
   REN ATN       : SPE
   REN           : 0
   REN ATN       : SPD
   REN ATN       : UNT
 

The Controller sets itself up as an addressed Listener and sets up the DMM as an addressed Talker. The Controller then send the SPE (Serial Poll Enable) command byte to tell the DMM to respond to the poll. The DMM returns a byte with the value of 0 (same as the NULL character) indicating it has nothing to report. Note that ATN is released when the poll-response byte is returned, as only the Controller can send bytes while it is asserted. ATN is then asserted again, the Controller sends the SPD (Serial Poll Disable) command byte, and then UNTalks the DMM.

* This example covers the vast majority of what is in practice done by HPIB users: it sends a command to one device and reads back a value from it, then polls the device for errors.

To be sure, this example is oversimplified, in that instruments often return large amounts of data. Sending numeric data in string format is time-consuming and clumsy, so in practice large blocks of data are sometimes sent in binary format. It would have been nice to have had the DMM assert an SRQ, but configuring the DMM to do so is too complicated for a simple example.

It is also appropriate in most cases to set an I/O timeout on a device in an HP BASIC program (using the ON TIMEOUT statement) to prevent the program from hanging if the DMM doesn't respond in the 3-wire handshake, but again, for simplicity, this was not done.

Note that in this example, there is only one addressed Talker and one addressed Listener. While the 488.1 spec does allow for multiple addressed Listeners, in practice there is usually only one. No parallel poll is performed; as noted, it is virtually never done. A pass control is not performed; this can be a complicated procedure, and the situations that require it are rare.

[2.7] HPIB IN PRACTICE

* After its introduction in the 1970s, HPIB was commonly used to interface instruments, printers and plotters, and disk drives to early personal computers and workstations. HP, not surprisingly, was strongly dedicated to HPIB and came out with a wide range of HPIB devices that were hooked up to dedicated BASIC-language workstation computers that often had built-in HPIB ports.

Over time, HPIB printers, plotters, and disk drives, as well as dedicated BASIC-language workstations, became extinct, but HPIB remained and remains important for constructing instrumentation systems, using UNIX (tm) workstations and (in particular) personal computers as Controllers. A plug-in HPIB card is used to connect the controller to a benchtop or rack of instruments; standard languages, such as C or BASIC, are generally used to direct the system.

There are a variety of different plug-in cards available from different vendors for different platforms, generally based on the Texas Instruments 9920 chip or the Nippon Electric 7210 chip. National Instruments (NI) introduced an IC of their own that can be switched to function either as the TI chip or the NEC chip, and have used it on their own HPIB cards. The different vendors' cards are not in general compatible at a hardware level.

For the most part, the HPIB cards are controlled by standard programming languages such as C or BASIC, through a special library of subprogram calls provided with the HPIB card. Traditionally, these libraries have not been compatible, either, though NI did provide a driver for Windows named GPIB.DLL that other vendors emulated.

HP devised their own standardized interface control library, named SICL (Standard Instrument Control Language), and further efforts have been made to create a "universal" interface control library that is supported by multiple vendors. This universal library has the name VISA (Virtual Instrument Standard Interface). So far, VISA has met with limited success.

The libraries are useful for writing programs to control instruments from a controller. HPIB is very well thought-out and interfacing from a controller to an instrument is easy.

However, it is much more difficult to use them to write a program that allows a computer to be used as a "device" by a separate controller, since this requires a low-level knowledge of the HPIB spec. An experienced programmer will take many months to master the specs. Similarly, multiple-controller applications are difficult to set up, and should be regarded with caution.

External HPIB interfaces are also available that plug into a parallel port. Software drivers allow such interfaces to be accessed as if they were directly plugged into the PC.

A particularly interesting new technology is the LAN-HPIB bridge, which is a small box that contains a LAN and HPIB interface and allows communications with an HPIB device over a network. With the proper software, such a LAN-HPIB bridge can be largely transparent to software, though the user has to remember that the LAN is a mutual-access interface and that latency times can be long.

HPIB bus extenders are available that allow operation of HPIB systems over long distances, using a coaxial-cable or fiber-optic link. There are also extenders that operate as modems, allowing in principle operation over any distance, but they are suspect since they don't always meet HPIB timing specs.

National Instruments has defined a "TNT" spec extension to HPIB to allow extremely high operation speeds, but such a claim should be regarded skeptically: the TNT spec will only work if the remote devices support it, and few do.

In general, maximum performance over an HPIB system is in the 100 KB to 250 KB range when performing long data transfers. In all but the most highly optimized systems, overall program operations determines the speed, not raw HPIB throughput. Specs for HPIB cards claiming much higher speeds should also be regarded skeptically: such performance figures are based on unrealistic tests, and in practice one HPIB card is just about as fast as the other.

[2.8] ASCII TABLE FOR HPIB

* The table below gives the full standard 7-bit ASCII character set and the values of each character in decimal (D), hexadecimal (H), and octal (0), along with the corresponding HPIB address or command byte (if one exists).

Note that LAD0-LAD30 is abbreviated to L0-L30, and TAD0-TAD30 is abbreviated to T0-T30. The secondary command bytes (secondary addresses and the PPE / PPD commands) are listed in the right-hand column as SC0-SC31.


  __________________________________________________________________________

  ASCII Table For HPIB                                                        
  __________________________________________________________________________

  ch ctl cmd   D  H  O ch cmd  D  H  O  ch cmd  D  H   O  ch cmd    D  H   O 
  ___________________  ________________ ________________  __________________ 

  NUL ^@      0  0  0  sp L0  32 20 40   @ T0  64 40 100   ' SC0   96 60 140 
  SOH ^A GTL  1  1  1   ! L1  33 21 41   A T1  65 41 101   a SC1   97 61 141 
  STX ^B      2  2  2   " L2  34 22 42   B T2  66 42 102   b SC2   98 62 142 
  ETX ^C      3  3  3   # L3  35 23 43   C T3  67 43 103   c SC3   99 63 143 
  EOT ^D SDC  4  4  4   $ L4  36 24 44   D T4  68 44 104   d SC4  100 64 144 
  ENQ ^E PPC  5  5  5   % L5  37 25 45   E T5  69 45 105   e SC5  101 65 145 
  ACK ^F      6  6  6   & L6  38 26 46   F T6  70 46 106   f SC6  102 66 146 
  BEL ^G      7  7  7   ` L7  39 27 47   G T7  71 47 107   g SC7  103 67 147 
  ___________________  _______________  ________________  __________________ 

  BS  ^H GET  8  8 10   ( L8  40 28 50   H T8  72 48 110   h SC8  104 68 150 
  HT  ^I TCT  9  9 11   ) L9  41 29 51   I T9  73 49 111   i SC9  105 69 151 
  LF  ^J     10  a 12   * L10 42 2a 52   J T10 74 4a 112   j SC10 106 6a 152 
  VT  ^K     11  b 13   + L11 43 2b 53   K T11 75 4b 113   k SC11 107 6b 153 
  FF  ^L     12  c 14   , L12 44 2c 54   L T12 76 4c 114   l SC12 108 6c 154 
  CR  ^M     13  d 15   - L13 45 2d 55   M T13 77 4d 115   m SC13 109 6d 155 
  SO  ^N     14  e 16   . L14 46 2e 56   N T14 78 4e 116   n SC14 110 6e 156 
  SI  ^O     15  f 17   / L15 47 2f 57   O T15 79 4f 117   o SC15 111 6f 157 
  ___________________  _______________  ________________  __________________ 

  DLE ^P     16 10 20   0 L16 48 30 60   P T16 80 50 120   p SC16 112 70 160 
  DC1 ^Q LLO 17 11 21   1 L17 49 31 61   Q T17 81 51 121   q SC17 113 71 161 
  DC2 ^R     18 12 22   2 L18 50 32 62   R T18 82 52 122   r SC18 114 72 162 
  DC3 ^S     19 13 23   3 L19 51 33 63   S T19 83 53 123   s SC19 115 73 163 
  DC4 ^T DCL 20 14 24   4 L20 52 34 64   T T20 84 54 124   t SC20 116 74 164 
  NAK ^U PPU 21 15 25   5 L21 53 35 65   U T21 85 55 125   u SC21 117 75 165 
  SYN ^V     22 16 26   6 L22 54 36 66   V T22 86 56 126   v SC22 118 76 166 
  ETB ^W     23 17 27   7 L23 55 37 67   W T23 87 57 127   w SC23 119 77 167 
  ___________________  _______________  ________________  __________________ 

  CAN ^X SPE 24 18 30   8 L24 56 38 70   X T24 88 58 130   x SC24 120 78 170 
  EM  ^Y SPD 25 19 31   9 L25 57 39 71   Y T25 89 59 131   y SC25 121 79 171 
  SUB ^Z     26 1a 32   : L26 58 3a 72   Z T26 90 5a 132   z SC26 122 7a 172 
  ESC ^[     27 1b 33   ; L27 59 3b 73   [ T27 91 5b 133   { SC27 123 7b 173 
  FS  ^\     28 1c 34   < L28 60 3c 74   \ T28 92 5c 134     SC28 124 7c 174 
  GS  ^]     29 1d 35   = L29 61 3d 75   ] T29 93 5d 135   } SC29 125 7d 175 
  RS   ^^    30 1e 36   > L30 62 3e 76   ^ T30 94 5e 136   ~ SC30 126 7e 176 
  US   ^_    31 1f 37   ? UNL 63 3f 77   _ UNT 95 5f 137 DEL SC31 127 7f 177 
  __________________________________________________________________________ 

  GTL   Go To Local.               PPU        Parallel Poll Unconfigure.      
  SDC   Selected Device Clear.     SPE        Serial Poll Enable.             
  PPC   Parallel Poll Configure.   SPD        Serial Poll Disable.            
  GET   Group Execute Trigger.     L0-L30     Listen addresses (32+ADDR).     
  TCT   Take Control.              UNL        Unlisten (= L31).               
  GTL   Go To Local.               T0-T30     Talk addresses (64+ADDR).       
  LLO   Local Lockout.             UNT        Untalk (= T31).                 
  DCL   Device Clear.              SC0-SC31   Secondary commands (96+ADDR).   
  __________________________________________________________________________ 
 

[3.0] HPIB Tutor (3): IEEE 488.2 -- Overview & Data Formats

* This chapter and the next discusses the IEEE 488.2 specification.



BACK TO INDEX

[3.1] OVERVIEW

* The 488.1 spec addressed the fundamental problems of interconnecting digital devices, defining the mechanical and electrical requirements and the basic communications protocols.

Clearly that wasn't enough. Even though HPIB devices could be connected in a mechanical, electrical, and logical fashion, that didn't guarantee that they could communicate. Devices from different vendors had wildly differing HPIB capability sets, and used incompatible data formats, serial-poll status formats, and entirely different command formats.

IEEE 488.2-1987 was defined to address these problems. 488.2 provides:

  • A minimum required set of interface capabilities.
  • Data formats.
  • Device message protocols.
  • A core common command set.
  • A well-defined status-reporting model.

This chapter discusses the details of data formats and protocols. The following chapter discusses the common command set and status reporting.

* The minimum required set of interface capabilities defined by 488.2 is given below:

  • Source Handshake / SH1 / Full capability.
  • Acceptor Handshake / AH1 / Full capability.
  • Talker / T(TE)5 or T(TE)6 / Basic Talker, serial poll, unTalk on MLA.
  • Listener / L(LE)3 or L(LE)4 / Basic Listener, unListen on MTA.
  • Service Request / SR1 / Full capability.
  • Device Clear / DC1 / Full capability.
  • Remote Local / RL0 or RL1 / None or full capability.
  • Parallel Poll / PP0 or PP1 / None or full capability.
  • Device Trigger / DT0 or DT1 / None or full capability.
  • Controller / (C0 or C4) and (C5 or C7 or C8 or C11) / None or respond to SRQ, send interface messages, pass & receive control.
  • Electrical Interface / E1 or E2 / Open collector or tristate.

This minimum capability set states that all HPIB devices must be able to send and receive data, request service, and respond to a device clear command. It also details the minimum capabilities that a device must have when it implements controller, parallel poll, and remote-local functions.

* 488.2 defines a set of data formats. For example, it defines a format for binary, octal, and hexadecimal numbers, as well as formats to send long blocks of 8-bit bytes or strings of ASCII characters. The table below lists the supported formats:

  • Listener Formats
    • <Decimal Numeric Program Data> / REQUIRED
    • <Character Program Data> / optional
    • <Suffix Program Data> / optional
    • <Non-Decimal Numeric Program Data> / optional
    • <String Program Data> / optional
    • <Arbitrary Block Program Data> / optional
    • <Expression Program Data> / optional
  • Talker Formats:
    • <NR1 Numeric Response Data> / REQUIRED
    • <Arbitrary ASCII Response Data> / REQUIRED
    • <Character Response Data> / optional
    • <NR2 Numeric Response Data> / optional
    • <NR3 Numeric Response Data> / optional
    • <Hexadecimal Numeric Response Data> / optional
    • <Octal Numeric Response Data> / optional
    • <Binary Numeric Response Data> / optional
    • <String Response Data> / optional
    • <Definite Length Arbitrary Block Response Data> / optional
    • <Indefinite Length Arbitrary Block Response Data> / optional
    • <Expression Response Data> / optional

488.2 introduced a new concept that makes it possible for older devices to communicate with devices that use this new standard: "forgiving listening -- precise talking."

Forgiving listening means that a 488.2 device can accept a wide range of data formats. Precise talking means that a 488.2 device will transmit data in a rigorous set of formats.

* Device message protocols allow devices to communicate by defining how to send device commands, parameters, and data. 488.2 "syntax" defines what to do when a device receives multiple commands, an incomplete command, or is interrupted while processing a command.

488.2 also defines the protocols by which devices exchange data. For example, it describes the order in which data is sent; requires that a device cannot send data until commanded to do so; and specifies that when a device receives a new command it will flush its output queue, and respond to that command.

[3.2] DATA CODING & FORMATS

* 488.2 specifies three sets of codes for operation with HPIB devices:

  • US ASCII 7-bit (ANSI X3.4-1977) for alphanumerics.
  • Binary 8-bit integer.
  • Binary floating-point codes (IEEE 32- and 64-bit floating-point codes).

Using these codes, 488.2 defines data formats for decimal, octal, and hexadecimal integers, decimal floating point numbers, strings, character strings, and arbitrary strings. Most of these formats use ASCII characters to represent the data.

In sending ASCII and 8-bit binary, the order of the bits in the byte sent over the HPIB matches the numbering of the DIO lines. That is, bit 1 of an ASCII character matches DIO line 1. When sending streams of bytes, the most-significant byte in the stream is sent first.

The data formats are concisely described in 488.2 using "railroad track" diagrams, which provide a flowchart of the approved order of the elements of the data format. The detail provided by these diagrams is not necessary for this discussion, so we will base our descriptions on a simple description and some examples.

The device listening formats are described below. They are known as "program formats" since they are used to configure the instrument, though the formats do not necessarily define device programming commands as such.

* The <Decimal Numeric Program Data> format is also known as <NRf> for "flexible Numeric Representation". This is basically an ASCII decimal numeric string floating-point format. Legal numbers in this scheme include:


      .123        
     0.123
   123.        
    12.3
   +12.3
   -12.3       
   +12.3e10    
   -12.3E10
    12.3E+10    
    12.3E-10    
    12.3 E-10   
    12.3 e - 10
 

The mantissa cannot have more than 255 characters, and the exponent must be in the range of -32,000 to 32,000.

If a device receives an <NRf> of greater precision than it can handle, it rounds off the number. Rounding ignores the sign of the number; values less than 1/2 round down, and values greater than or equal to 1/2 round up. For example, suppose we have an instrument that can only handle two digits; rounding is performed as follows:


    1.3499 -->  1.3    
    1.35   -->  1.4      
   -2.456  --> -2.5   
   -2.447  --> -2.4
 

A suffix, used to define the units and (optionally) the multipliers of the data, may also be used with <NRf> data. The defined unit suffixes are as follows:


   _________________________________________________________________________

   Class                Preferred Suffix           Allowed Suffix
   _________________________________________________________________________

   Ratio                DB     Decibel                   
                        PCT    Percent                   
                                                   PPM    Parts Per Million

   Angle                RAD    Radian                    
                        SR     Steradian                 
                                                   DEG    Degree
                                                   GON    Grade
                                                   MNT    Minute of arc
                                                   SEC    Second
                                                   REV    Revolution

   Time                 S      Second                    
                                                   D      Day
                                                   HR     Hour
                                                   MIN    Minute
                                                   ANN    Year

   Frequency            HZ     Hertz                     
                                                   MHZ    Megahertz

   Temperature          CEL    Degree Celsius            
                        K      Degree Kelvin             
                                                   FAR    Degree Fahrenheit

   Length               M      Meter                     
                                                   FT     Feet
                                                   IN     Inch
                                                   MI     Mile
                                                   NAMI   Nautical Mile
                                                   ASU    Astronomical Unit
                                                   PRS    Parsec

   Volume               L      Liter                     
   Mass                                            G      Gram
                                                   TNE    Tonne

   Atomic Mass          U      Atomic Mass Unit          
   Energy               J      Joule                     
                                                   EV     Electronvolt

   Power                W      Watt                      
                        DBM    DB On 1 Milliwatt         

   Force                N      Newton                    
   Pressure             ATM    Atmosphere                
                        INHG   Inches of Mercury         
                        PAL    Pascal                    
                        TORR   Torr                      

   Fluid Pressure       BAR    Bar                       
   Chemical Measure     MOL    Mole                      
   Viscosity            ST     Stokes                    
                        P      Poise                     

   Charge               C      Coulomb                   
   Current              A      Ampere                    
   Potential            V      Volt                      
   Resistance           OHM    Ohm                       
                                                   MOHM   Megohm

   Conductance          SIE    Siemens                   
   Capacitance          F      Farad                     
   Inductance           H      Henry                     
   Luminous Intensity   CD     Candela                   
   Illuminance          LX     Lux                       
   Luminous Flux        LM     Lumen                     
   Magnetic Induction   T      Tesla                     
   Magnetic Flux        WB     Weber                     
   Radioactivity        BQ     Becquerel                 
   Absorbed Dose        GY     Gray                      
   Dose Equivalent      SV     Sievert                   
   _________________________________________________________________________
 

The defined multipliers are as follows:


   ___________________________

   exponent   mnemonic   name
   ___________________________

   1E18       EX         EXA
   1E15       PE         PETA
   1E12       T          TERA
   1E9        G          GIGA
   1E6        MA         MEGA
   1E3        K          KILO
   1E-3       M          MILLI
   1E-6       U          MICRO
   1E-9       N          NANO
   1E-12      P          PICO
   1E-15      F          FEMTO
   1E-18      A          ATTO
   ___________________________
 

In the latest incarnation of 488.2, <Suffix Program Data> may also be used on its own, without use of a preceding <NRf> element.

* The <Non-Decimal Numeric Program Data> format is a numeric string representation of hexadecimal, octal, and binary numbers:


   #HA2F      a hexadecimal A2F
   #ha3e      a hexadecimal a3e
   #hA3f      a hexadecimal A3f
   #Q73       an octal 73
   #q54       an octal 54
   #B01101    a binary 01101
   #b10010    a binary 10010
 

* The <String Program Data> format is for sending ASCII strings (using 7-bit USASCII characters):


   'this is a legal string'
   "this is also a legal string"
   "this string contains an embedded ' that is not a delimiter"
   'this string contains an embedded " that is not a delimiter'
   "this string contains an embedded "" that is not a delimiter"
 

Note that the two last examples do exactly the same thing, but in different ways.

* The <Arbitrary Block Program Data> spec provides a scheme for sending binary or 8-bit ASCII) data. There are two formats: a definite-length format and an indefinite-length format.

Both formats start with a "#" character to distinguish them from other device-listening formats. In the definite-length format, the "#" character is followed by:

  • A single ASCII digit that gives the number of ASCII digits in the field following it.
  • A string of ASCII digits (where the field length was defined as above) that gives the number of data bytes to follow the field.
  • A stream of data bytes of a length given by the field above.

This format may be a little easier to understand with some examples (note that <DAB> stands for some arbitrary data byte):


    #15<DAB><DAB><DAB><DAB><DAB>
    #213<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>
 

In the first example, the length field is 1 digit long and specifies 5 following data bytes. In the second example, the length field is 2 digits long and specifies 13 following data bytes.

In the indefinite-length format, the length field evaluates to 0 and is followed by a stream of data bytes that is terminated by a newline (line-feed) character, along with assertion of the EOI line. (It is necessary to use EOI because arbitrary data bytes will often evaluate to a line-feed character, a revelation that novice I/O programmers usually find out about the hard way.) For example:


   #0<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>NL&EOI
 

* The <Expression Program Data> format evaluates to a scalar, vector, matrix, or string value. It is very general-purpose and consists solely of a string of ASCII characters in the range of codes 32 to 126, with the exception of 5 characters: very


   [ " ]     [ # ]     [ ' ]     [ , ]     [ ; ]
 

-- with the entire string enclosed in parentheses. This format basically evaluates to ANY sequence of characters enclosed in parenthesis. It can be considered an "escape" format that allows for command formats not allowed by the rest of the 488.1 spec.

The device listening formats discussed above are very broad and forgiving. The device talking formats are much more precise.

* The <NR1 Numeric Response Data -- Integers> format defines integer decimal numbers with no decimal point or fractional part. For example:


      123
     +123
   -12345
 

* The <NR2 Numeric Response Data -- Fixed Point> format defines decimal numbers with a fractional part but no exponent. For example:


   12.3
   +1.234
   -0.12345
 

* The <NR3 Numeric Response Data -- Floating Point> format defines decimal numbers with a fractional part and an exponent. For example:


        1.23E+5
      123.4E-56
   -12345.678E+90
 

* The <Hexadecimal Numeric Response Data> format is exactly the same as the listening format for hex numbers, except that lowercase letters are not allowed. For example:


   #HAD0E
   #H01F2
   #HF3B
 

* The <Octal Numeric Response Data> format is exactly the same as the listening format for octal numbers, except that lowercase letters are not allowed. For example:


   #Q7035
   #Q30572
   #Q765432
 

* The <Binary Numeric Response Data> format is exactly the same as the listening format for binary numbers, except that lowercase letters are not allowed. For example:


   #B01101
   #B10101010
   #B1011
 

* The <Character Response Data> format defines the means by which mnemonic strings are sent between devices. These strings contain only ASCII numeric digits, upper-case ASCII alphabetic characters, and the "_" character. They must start with an upper-case ASCII alphabetic character, and cannot be more than 12 characters long. For example:


   START
   R2_D2
 

* The <String Response Data> format defines how a device sends an arbitrary text string. It is the same as the listening format, except that double-quotes are legal characters but single-quotes are not. For example:


   "You say hello"
   "I say ""Goodbye""."
 

* The <Definite Length Arbitrary Block Response Data> format is for sending binary data of a specified length. It is exactly the same as the listening format:


   #3128<DAB1><DAB2><DAB3> ... <DAB128>
 

* The <Indefinite Length Arbitrary Block Response Data> format is for sending binary data of an unspecified length. It is exactly the same as the listening format:


   #0<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>NL&EOI
 

* The <Arbitrary ASCII Response Data> format allows a device to respond with undelimited ASCII text. It consists of a stream of ASCII bytes terminated by a newline-with-EOI. This is a very general (and somewhat ill-defined) format -- note that it allows for responses that could easily be confused for other response types -- and its use is discouraged. very

* The <Expression Response Data> format is the response counterpart to the <Expression Program Data> type. It is also general-purpose and consists solely of a string of ASCII characters in the range of codes 32 to 126, with the exception of 5 characters:


   [ " ]     [ # ]     [ ' ]     [ , ]     [ ; ]
 

-- with the entire string enclosed in parentheses. Like the response data format, this format is used to cover any format not otherwise covered in the 488.2 spec.

[3.3] SYNTAX

* In the previous section we discussed the data formats defined by 488.2 -- the "words" of the "language", so to speak. In this section we move up from simple "words" to the syntax that provides a framework for those "words".

As with the data formats, the syntax that a device will recognize is much less precise than the syntax that it will generate -- "forgiving listening, precise talking" again.

* The elements of listening syntax fall into the following categories:

  • Terminators
  • Separators
  • Commands
  • Queries

There is only one form of terminator. The <Program Message Terminator> defines how to terminate a message to a listening device. There are three possible terminators:

  • A newline.
  • A newline with EOI.
  • An EOI.

A terminator is also sometimes informally referred to as an "arnold", but this usage is clearly outside of the 488.2 spec.

* Separators fall into three categories. The <Program Message Separator> is just a ";" (semicolon), and is placed between commands in a single message to create a complex command.

The <Program Header Separator> is just blank ("white") space, and is used to separate commands and their parameters. This is the only case where white space is significant in 488.2. In other listening formats it is ignored, and in talking formats is not usually generated.

The <Program Data Separator> is just a "," (comma), and is used to separate data in a data stream.

* Commands, or more properly <Command Program Headers>, also fall into three categories, though in this case the categories are less distinct.

The <Simple Program Header> is just a command string, or <Program Mnemonic>. Legal command strings consist of lowercase and uppercase letters, plus the "_" (underscore) character. For example:


   MEASURE
 

The <Compound Command Program Header> is a set of <Program Mnemonic> strings, separated by ":" (colon) characters. A ":" may be added in front as well. For example:


   MEASURE:VOLTAGE
   :MEASURE:VOLTAGE
 

The <Common Command Program Header> is the format for the common commands defined by 488.2. Their distinguishing feature is that they are preceded by a "*" (asterisk). For example:


   *IDN
   *RST
   *SRE
 

* There are three queries, or more properly <Query Program Headers>. The queries are used to interrogate a device for information. The three queries are complementary to the three commands, and include:

  • <Simple Query Program Header>
  • <Compound Query Program Header>
  • <Common Query Program Header>

The three have the same syntax as the complementary commands, except that a "?" is tacked on to the end.

* The talking syntax is similar to the listening syntax, but much more concise. The talking syntax applies to two types of data that a device may return in response to a query:

  • Response Data: This is data returned by the instrument in response to a query. Since a <Compound Query Program Header> may ask for multiple responses, a single response data stream may contain the responses to multiple queries.
  • Learn String: This is the data returned in response to a query that interrogates a device for a setting. This data includes not only the value of the setting but the command header that tells the device to make that setting. This learn string can be sent later, verbatim, to restore the setting.

There are only four elements to the talking syntax:

  • <Response Message Terminator>: The only legal terminator for the talking syntax is a newline along with an EOI. This is used at the end of a stream of response data.
  • <Response Message Unit Separator>: This separator is defined as a ";" (semicolon), and is used to separate different responses in the response stream.
  • <Response Data Data Separator>: This separator is defined as a "," (comma), and is used to separate data items in a response.
  • <Response Header Separator>: This separator is defined as a " " (space), and is used to separate the response header from the response data.

[4.0] HPIB Tutor (4): 488.2 Common Commands & Status

* The 488.2 spec also includes a "common command" set that provides a minimal subset of instrument commands, as well as a consistent way of returning status information. This chapter describes these issues in detail.



BACK TO INDEX

[4.1] 488.2 COMMON COMMANDS & STATUS OVERVIEW

* The common commands defined under 488.2 are not bus commands, but strings sent as data with ATN off. (These common commands include both commands and queries, but for convenience they are collectively referred to as commands.) The complete common command set is as follows:

  • AUTO CONFIGURE COMMANDS: Set device addresses via software.
    • *AAD / Assign Address / optional
    • *DLF / Disable Listener Function / optional
  • SYSTEM DATA COMMANDS: Store or retrieve information about HPIB devices, such as device descriptions and options.
    • *IDN? / Identification Query / REQUIRED
    • *OPT? / Option Identification Query / optional
    • *PUD / Protected User Data / optional
    • *PUD? / Protected User Data Query / optional
    • *RDT / Resource Description Transfer / optional
    • *RDT? / Resource Description Transfer Query / optional
  • INTERNAL OPERATION COMMANDS: Control or read the internal operation of a device through resets, self-tests, or self-calibration.
    • *CAL? / Calibration Query / optional
    • *LRN? / Learn Device Setup Query / optional
    • *RST / Reset / REQUIRED
    • *TST? / Self-Test Query / REQUIRED
  • SYNCHRONIZATION COMMANDS: Control device synchronization within an HPIB system.
    • *OPC / Operation Complete / REQUIRED
    • *OPC? / Operation Complete Query / REQUIRED
    • *WAI / Wait to Continue / REQUIRED
  • MACRO COMMANDS: Allow the user to define new commands as "macros" of other commands.
    • *DMC / Define Macro / optional
    • *EMC / Enable Macro / optional
    • *EMC? / Enable Macro Query / optional
    • *GMC? / Get Macro Contents Query / optional
    • *LMC? / Learn Macro Query / optional
    • *PMC / Purge Macros / optional
    • *RMC / Remove Individual Macro / optional
  • PARALLEL POLL COMMANDS: Control how a device responds to a parallel poll, and allow access to the same information without performing a parallel poll.
    • *IST? / Individual Status Query / required if PP1
    • *PRE / Parallel Poll Enable Register Enable / required if PP1
    • *PRE? / Parallel Poll Enable Register Enable Query / required if PP1
  • STATUS & EVENT COMMANDS: Control device status reporting.
    • *CLS / Clear Status / REQUIRED
    • *ESE / Event Status Enable / REQUIRED
    • *ESE? / Event Status Enable Query / REQUIRED
    • *ESR? / Event Status Register Query / REQUIRED
    • *PSC / Power On Status Clear / optional
    • *PSC? / Power On Status Clear Query / optional
    • *SRE / Service Request Enable / REQUIRED
    • *SRE? / Service Request Enable Query / REQUIRED
    • *STB? / Read Status Byte Query / REQUIRED
  • DEVICE TRIGGER COMMANDS: Perform a Device Trigger and control how a device responds to a trigger command.
    • *DDT / Define Device Trigger / optional if DT1
    • *DDT? / Define Device Trigger Query / optional if DT1
    • *TRG / Trigger / required if DT1
  • CONTROLLER COMMANDS: Defines the means of passing control between devices.
    • *PCB / Pass Control Back / required if ctl
  • STORED SETTING COMMANDS: Save and restore the state of the device.
    • *RCL / Recall Instrument State / optional
    • *SAV / Save Instrument State / optional
    • *SDS / Save Default Device Settings / optional

The spec defines some of these commands as required, and some as optional. In practice the required commands are always implemented on any respectable modern instrument, while most of the optional commands are implemented only on certain classes of instruments or never at all.

* 488.2 provides a major enhancement of the definition of the serial poll status byte defined in 488.1 spec. The original definition only defined bit 6 as the "request service" flag; 488.2 also defines two more bits, the Event Status Bit (ESB) and Message Available (MAV), plus an additional status register and provisions for others. (488.2 also includes an expansion of the definition of parallel poll provided in 488.1.)

* The 488.2 common command set makes programming a device somewhat simpler as it predefines certain elementary commands common to many devices. However, it does not address the command syntax relevant to the specific functions of the devices. That domain is covered by the SCPI standard, the subject of the following chapter.

[4.2] ESSENTIAL COMMON COMMANDS

* In practice, the most important common commands are those outlined below:

  • SYSTEM DATA COMMANDS
    • *IDN? / Identification Query / REQUIRED
  • INTERNAL OPERATION COMMANDS
    • *LRN? / Learn Device Setup Query / optional
    • *RST / Reset / REQUIRED
    • *TST? / Self-Test Query / REQUIRED
  • SYNCHRONIZATION COMMANDS
    • *OPC / Operation Complete / REQUIRED
    • *OPC? / Operation Complete Query / REQUIRED
    • *WAI / Wait to Continue / REQUIRED
  • STATUS & EVENT COMMANDS
    • *CLS / Clear Status / REQUIRED
    • *ESE / Event Status Enable / REQUIRED
    • *ESE? / Event Status Enable Query / REQUIRED
    • *ESR? / Event Status Register Query / REQUIRED
    • *PSC / Power On Status Clear / optional
    • *PSC? / Power On Status Clear Query / optional
    • *SRE / Service Request Enable / REQUIRED
    • *SRE? / Service Request Enable Query / REQUIRED
    • *STB? / Read Status Byte Query / REQUIRED
  • DEVICE TRIGGER COMMANDS
    • *TRG / Trigger / required if DT1

* The *IDN? (Identification) query causes a device to return a string to identify itself; this string has the format:


   <manufacturer>,<model>,<serial_number>,<firmware_rev_level>
 

Note that the serial number and firmware revision level are returned as "0" if not available. For example, a device might return a string of the form:


   HEWLETT-PACKARD,347A,222101113,A1
 

* While the *LRN? (Learn Device Setup) query is optional, many devices implement it; it tells the device to return a "learn string" to the controller that contains the commands necessary to put the device back into its current state. This string can either be in ASCII or binary format, since the format isn't specified by 488.2. Oddly, there is no *LRN command, just a *LRN? query.

* The *RST (Reset) command resets the device. It performs the following actions:

  • Sets device functions to a known state.
  • Sets the Device Defined Trigger (see *DDT command) to a known state.
  • Disables macros (see the section on macro commands).
  • Aborts all pending operations.
  • Clears any received *OPC or *OPC? commands in progress.

The *RST command does not affect:

  • The state of the HPIB address or its address.
  • The bytes in the output queue.
  • The service request enable register.
  • The standard event status register.
  • The power-on flag.
  • Macro definitions (though they are disabled), calibration data, protected user data, or the Resource Description Transfer Query Response.

Note that *RST is the highest of three levels of resets defined under 488.1 and 488.2. These three levels are:

  • The 488.1 IFC line causes a level-1 reset. It unaddresses all devices and returns control to the system controller.
  • The 488.1 DCL and SDC (universal device clear and selected device clear) command bytes perform a level-2 reset. They clear the device input and output buffers and allow it to receive new commands.
  • The 488.2 *RST command performs a level-3 reset: it actually clears the device itself as described above.

* The *TST? (Self-Test) query causes the device to perform an internal selftest and report back the status of the test. It is similar to the *CAL? command and, like the *CAL? command, returns "0" if successful, and an error code in the range "-32767" to "32767" if not.

* The *OPC (Operation Complete) command tells the device to set bit 0 in the Standard Event Status Register (described in the next section) when it completes all pending operations.

The matching *OPC? query tells the device to place an ASCII "1" in the device's output queue when it completes all pending operations.

* The *WAI (Wait to Continue) command makes the device wait until all previous commands or queries complete, rather than execute a new command in an overlapped fashion. The device then continues executing commands that follow the *WAI command.

* The *CLS (Clear Status) command clears the status register and associated status data structures summarized in the Status Byte, such as the Event Status Register (described in the next section).

* The *ESE (Standard Event Status Enable) command allows you to set the contents of the Standard Event Status Enable Register. It takes a decimal numeric string in the range "0" to "255", representing the bit pattern in the register. If a bit is set, the corresponding bit in the Standard Event Status Register will be flagged into the Status Byte.

The *ESE? query interrogates the Standard Event Status Enable Register. It returns a decimal numeric string in the range "0" to "255".

The *ESR? (Event Status Register) query reads the contents of the Standard Event Status Register; the SESR is then cleared. A decimal numeric string in the range "0" to "255", representing the bit pattern in the SESR, is returned. This is explained in more detail in the next section.

* The *PSC (Power-On Status Clear) command (which is optional, but often implemented) controls the clearing of the Service Request Enable Register, the Standard Event Status Enable Register, the Parallel Poll Enable Register, and (in the latest flavor of 488.2) such device-specific registers as the implementor may find useful to reset.

Sending a "0" with the "*PSC" command sets the power-on clear flag, causing the three registers to be cleared at power-up. Sending any other number in the range "-32767" to "32767" clears the power-on clear flag, but leaves the registers in their previous state.

The *PSC? query returns the status of the power-on clear flag. It returns "1" if the flag is set, and "0" if the flag is cleared.

* The *SRE (Service Request Enable) command sets the Service Request Enable Register (discussed in next section). It takes a decimal numeric string in the range "0" to "255" as a parameter, with the string representing the bit pattern to be stored in the register. Any bit enabled will cause an SRQ when the matching bit in the status byte is activated.

The *SRE? query returns the contents of the Service Request Enable Register. The contents are returned as a decimal numeric string in the range "0" to "63", "128" to "191". (The gap in the range is due to the fact that bit 6, the RQS bit, cannot be set and is always returned as "0".)

The *STB? (Status Byte) query reads the device Status Byte, with bit 6 representing the Master Summary Status (MSS) bit instead of the RQS bit. The query returns a decimal numeric string in the range "0" to "255". This is explained in more detail in the next section.

* The *TRG (Trigger) command performs the same function as the GET command byte.

[4.3] STATUS REPORTING

* The 488.1 spec, as described in previous chapters, defined a status byte to be returned by a device in response to a serial poll. However, the only thing that 488.1 defined in this byte was bit 6, which was set if the polled device had asserted a service request.

488.2 expands on this status reporting scheme and allows the status to be retrieved not only via through a serial poll, but also through the 488.2 *STB? query. 488.2 also extends the definition of the status byte and provides an additional, second-level status register, plus a mechanism for determining whether or not a status flag can cause an SRQ. The following illustration diagrams the 488.2 status model (explanations follow):


                                             Status Byte
                                         +-----+   +-----+   
                                         | 0   +-->| 0   +-->-+
                                         |     |   |     |    |
                                         | 1   +-->| 1   +-->-+
                                         |     |   |     |    |
                                         | 2   +-->| 2   +-->-+
                                         |     |   |     |    |
                                         | 3   +-->| 3   +-->-+
                                         |     |   |     |    +-[OR]-+
                  from output queue ---->| MAV +-->| MAV +-->-+      |
                                         |     |   |     |    |      |
  +-----+   +-----+           +--------->| ESB +-->| ESB +-->-+      |
  | OPC |   | OPC +-->-+      |          |     |   |     |    |      |
  |     |   |     |    |      |    +---->| RQS +-->| --- +-->-+      |
  | RQC |   | RQC +-->-+      |    |     |     |   |     |    |      |
  |     |   |     |    |      |    |     | 7   +-->| 7   +-->-+      |
  | QYE |   | QYE +-->-+      |    |     +-----+   +-----+           |
  |     |   |     |    |      |    |      *STB      *SRE <mask>      |
  | DDE +-->| DDE +-->-+      |    |                *SRE?            |
  |     |   |     |    +-[OR]-+    +---------------------------------+
  | EXE +-->| EXE +-->-+
  |     |   |     |    |
  | CME +-->| CME +-->-+
  |     |   |     |    |
  | URQ +-->| URQ +-->-+
  |     |   |     |    |
  | PON +-->| PON +-->-+
  +-----+   +-----+
   *ESR?     *ESE <mask>
             *ESE?
 

In 488.2 bits 4, 5, and 6 in the status byte are defined as follows:

  • Bit 4 is the message available bit, or MAV, which indicates whether or not the device's data output queue is empty. Whenever the device has data available, this bit will be set.
  • Bit 5 is the event-status bit, or ESB, which captures events generated from the Standard Event Status Register, which is defined below.
  • Bit 6 is defined slightly differently depending on whether the status byte is read via a serial poll or through the *STB? query. In a serial poll, bit 6 is defined as the RQS (request service) bit, and tells the HPIB controller whether the device has requested service or not. If it has requested service, the serial poll clears the bit.

    In a *STB? query, bit 6 is the master status summary (MSS) bit and indicates that the device has requested service, even if the device has been serial polled and the RQS bit has been cleared. That is, MSS is "sticky" and RQS is not.

The other bits, as before, are undefined. However, the other bits are intended to be used as status-summary bits for device-dependent event registers. (The SCPI spec defines these bits in more detail.)

The second status register defined by 488.2, the Standard Event Status register (SRER), contains the following flags:

  • Bit 0 -- Operation Complete (OPC) -- indicates that the device has completed any pending operations and is ready to accept new commands. This bit is generated only in response to the Operation Complete (*OPC) command.
  • Bit 1 -- Request Control (RQC) -- indicates that the device wants to become the active controller.
  • Bit 2 -- Query Error (QYE) -- indicates an error occurred while the controller was trying to read the device's data output queue. The cause will be either the queue was empty, or the queue overflowed.
  • Bit 3 -- Device-Dependent Error (DDE) -- indicates some unspecified device error occurred.
  • Bit 4 -- Execution Error (EXE) -- indicates that the device detected an error while trying to execute a command. The cause will be either the device received a command that was inappropriate to the device, or the device could not execute a valid command due to some device condition.
  • Bit 5 -- Command Error (CME) -- indicates that the device has detected a command error. These errors include being sent commands that do not conform to 488.2 format or commands that are incorrectly spelled.
  • Bit 6 -- User Request (URQ) -- indicates that the user has activated some device-dependent control to request service.
  • Bit 7 -- Power On (PON) -- indicates that the device has been power-cycled since the last time it was queried.

As noted earlier, the ESB bit in the status bit register is set if any standard events occur -- that is, if any enabled bit in the SESR is set.

The SESR can be read with the *ESR? query. The corresponding standard event status enable register can be set (to enable events on the SESR bits) with the *ESE <mask> command, and read with the *ESE? query.

The SESR is cleared by a *CLS command, reading the SESR with *ESR?, or by a power cycle (though in this last case the PON bit will be set after the SESR is cleared).

The 488.2 spec allows other event registers to be implemented and summed into the unused bits of the status byte, but does not define what these other registers to be. (The SCPI spec added these definitions with a vengeance!)

* The device data output queue has been mentioned several times in this discussion; it stores output messages to be read from the device, and can be read simply by addressing the device to talk and then handshaking the bytes. The MAV bit will be set as long as there are bytes available.

The *CLS command does not clear the output queue. It can only be cleared by the *RST command, the 488.1 DCL (device clear) command byte, or by power-cycling. This reduces the chances of losing data.

* 488.2 enhances the parallel poll protocol defined in 488.1 by adding a Parallel Poll Enable Register. Again, as Parallel Poll is rarely used, this will not be discussed further.

* The following example program -- which is for a 34401 DMM, but will work on any 488.2-compatible instrument -- uses the common commands to conduct a device verification. Note how the results of the self-test are obtained by programming the DMM to assert SRQ when done.


   10    DIM S$[50]                    ! Dimension a string.
   20    CLEAR SCREEN                  ! Clear display.
   30    ASSIGN @Dmm TO 722            ! Assign path to DMM.
   40    !
   50    ON TIMEOUT 7,5 GOTO Timetrap  ! Jump on 5-second timeout.
   60    !
   70    DISP "Clearing DMM!"
   80    CLEAR @Dmm                    ! Send SDC to DMM.
   90    OUTPUT @Dmm;"*RST;*CLS"       ! Reset & clear status.
   100   !
   110   DISP "Getting DMM status!"
   120   OUTPUT @Dmm;"*IDN?"           ! Get ID from DMM.
   130   ENTER @Dmm;S$
   140   DISP S$
   150   !
   160   WAIT 2                        ! Delay 2 seconds.
   170   DISP "Testing DMM!"
   180   ON INTR 7 GOTO Srqtrap        ! Set up interface event.
   181   ENABLE INTR 7;2               ! Enable trap on SRQ.
   190   OUTPUT @Dmm;"*ESE 1;*SRE 32"  ! Enable SRQ on OPC.
   191   OUTPUT @Dmm;"*OPC?"           ! Clear any current pending OPC.
   192   ENTER @Dmm;S$
   200   OUTPUT @Dmm;"*TST?;*OPC"      ! Test DMM, flag OPC.
   210   LOOP                          ! Wait for SRQ.
   220   END LOOP
   230   !
   240 Timetrap:                       ! Go here on timeout.
   250   DISP "Timed out -- done!"
   260   STOP
   270   !
   280 Srqtrap:                        ! Go here on SRQ.
   281   DISP "Got SRQ!"
   290   ENTER @Dmm;S$
   300   DISP "Test result: ";S$;" - done!"
   310   END
 

Note how the device is cleared with a CLEAR command and by sending the *RST;*CLS string. This is the recommended means of clearing a 488.2 device back to a known state.

Note also how this program sets up a "timeout" on the HPIB interface which causes a jump if an HPIB action takes longer than the specified timeout. For the sake of keeping things simple, most of the examples in this document don't set a timeout, but you should always do this in your own programs, since your program will hang indefinitely if you don't.

As a self-test takes a long time, it is likely to exceed a specified timeout, so this program configures the DMM to do an SRQ when the test operation is complete. It would actually be just as simple in this case to use SPOLL to query the Status Byte and check for Bit 6 set, but knowing how to set up an SRQ is useful in general.

[4.4] SECONDARY COMMON COMMANDS

* The remaining commands are implemented only in certain classes of instruments, or aren't implemented at all.

* The optional Macro Commands allow a device to accept "macro" strings that designate and instruct the device to execute a specific series of commands.

The *DMC (Define Macro) command sets up a relationship between a macro name and the commands the macro will execute. The macro is defined by sending the *DMC command, followed by a arbitrary block program element or string designating the label, followed by a string defining the macro; for example:


   *DMC "HOME",#18MOVE 0,0
 

-- defines a command that moves a pen plotter to its home position.

Macro definitions also allow the user to pass parameters within the macro; dummy parameters appear as a "$", followed by a single digit in the range "1" to "9", within the macro definition. The dummy parameter can be used several times within the macro definition string.

The macro label may be either in the form of a command or query, though it cannot be the same as a common command or query. It may be the same as a device-dependent command; when the macro label is the same as a device-dependent command, the device will execute the macro instead of the device command (as long as macros are enabled).

The *EMC (Enable Macro) command enables and disables operation of macros; if it is sent with a parameter of "0" it disables macros, if it is sent with a parameter in the range "-32767" to "32767" will enable macros. Note that this command only disables macro operation. The macros will retain their definitions and will regain their functions when enabled again. The matching *EMC? (Enable Macro) query returns "1" if macros are enabled and "0" if they are disabled.

The *GMC? (Get Macro Contents) query allows the user to inspect the definition of a particular macro; the user send "*GMC?" followed by the macro label, and the device sends back the macro definition. For example, sending:


   *GMC? "HOME"
 

-- returns the definition for "HOME", which is "#18MOVE 0,0", as shown in an earlier example.

The *LMC? (Learn Macro) query returns the labels of all currently-defined macros, as strings separated by commas. If no macros are defined the device will return a null string (""). The response will be the same whether macros are enabled or disabled.

The *PMC (Purge Macro) command wipes all defined macros from device memory.

The *RMC (Remove Individual Macro) command (added in the latest version of 488.2) allows the user to get rid of a single macro. The name of the macro to be deleted is included as a string parameter to the command.

* The auto-address commands -- *AAD and *DLF -- allow a controller to software-configure an HPIB system. Since this capability is optional, however, there is no necessity that all the devices in an HPIB system implement auto-addressing even if they are 488.2-compliant, and so this capability is in practice useless.

* The *OPT? (Option Identification) query tells the device to return its options as a string containing fields separated by commas. Note that missing options are returned as a "0", and that if the device has no options, it also returns a "0". The maximum length of the response is 255 characters.

* The *PUD (Protected User Data) command stores up to 63 bytes of device-dependent data. The data can be retrieved with a *PUD? query.

* The *RDT (Resource Description Transfer) command is similar to *PUD, but it writes a data that provides information describing the device. A matching *RDT? query retrieves the stored data.

* The *CAL? (Calibration) query tells the device to perform a self-calibration. It returns "0" if successful, or an error code from "-32767" to "32767" if not.

* The parallel poll commands -- *IST?, *PRE, and *PRE? -- support Parallel Poll operations, which almost nobody uses to begin with. They will not be discussed further.

* The *DDT (Define Device Trigger) command stores a sequence of commands that a device will execute when it receives a GET command byte or a *TRG common command. It has a matching *DDT? query.

* The *PCB (Pass Control Back) command is used by the active controller to tell what device to return control to after control has been passed to it. The command takes a decimal numeric string in the range of "0" to "30", representing the controller's address, as a parameter.

* The instrument state commands allow a device to store a configuration in its own memory and then recall it later. The *RCL (Recall Instrument State) command restores the device state from a state definition stored in local (device) memory. The command takes a number defining which memory block to use, with the numbers starting at "0" and going up to a device-defined upper limit. The state restored by the *RCL command are the same functions affected by the *RST command. (The device may have a protection mechanism that prevents the recall unless it is enabled.)

The *SAV (Save Instrument State) command stores the device state in local memory. The command is followed by a numeric parameter defining which block to use. (The device may have a protection mechanism that prevents the store unless it is enabled.)

The *SDS (Save Default Device Settings) command allows a default state definition to be stored in a given memory block in the device. The command takes a number (as defined for *RCL and *SAV) defining which memory to restore to its default setting.


[5.0] HPIB Tutor (5): Introduction To SCPI

* This chapter provides an overview of the Standards Commands for Programmable Instruments (SCPI) command set spec.



BACK TO INDEX

[5.1] SCPI OVERVIEW

* The SCPI specification defines a programming language used to control test and measurement instruments such as oscilloscopes, function generators, power supplies, and spectrum analyzers. Such instruments implement SCPI in their firmware.

SCPI is in some senses a follow-on to IEEE 488.2. The 488.2 spec defined general commands, while SCPI provides the commands required for the operation of specific types of instruments.

The first pass at a more comprehensive programming language spec was HP's Test & Measurement Language (TMSL), announced in August 1989 and offered as an industry standard. This first attempt defined 850 commands. In April 1990, a consortium of manufacturers adopted the TMSL definition as the basis for SCPI, incorporating some features (a Data Interchange Format, or DIF) proposed by Tektronix.

The initial SCPI consortium consisted of HP, Tektronix, Fluke, Phillips, Wavetek, Racal-Dana, Keithley, Bruel & Kjaer, and National Instruments. The SCPI Consortium now maintains the SCPI definition and the formal document that describes it.

The benefit of SCPI is compatibility -- that is, interoperability between different instruments. The same command that performs a certain function on one instrument will perform exactly that same function on an entirely different instrument, as long as both share that capability. An instrument control program designed for a certain type of instrument, such as a function generator, will work for a comparable function generator from a different vendor with few or no changes.

SCPI is designed with commands at several levels of generality to help provide this compatibility. A high-level SCPI command such as MEASURE:VOLTAGE:AC? ("read an AC voltage") will work on both an oscilloscope and a DVM. At the same time, SCPI also provides commands for low-level instrument control that allow precise instrument programming, but are not likely to work on another instrument.

While SCPI may seen a little intimidating and obscure at first (some refer to it as "C for instruments"), it is much more consistent and understandable than other instrument command sets. Since it does cover the full range of programmable instrumentation, the full SCPI spec is of course complicated, but the basic rules are not hard to understand and you can pick them up easily.

[5.2] SCPI COMMAND SYNTAX

* SCPI is, as noted, a superset of the 488.2 spec in terms of its data formats, its usage of common commands, and the 488.2 status system, and uses much of the same nomenclature. SCPI "program messages", for example, are the data sent from the controller to the instrument. Similarly, SCPI "response messages" are the formatted data returned from the instrument to the controller. They both adhere to the 488.2 principle of "forgiving listening, precise talking".

Also as with 488.2, SCPI defines both commands and queries. One of the nicer principles on which SCPI is based, in fact, is if there is a command that sets a value, there is a matching query that reads back that value.

The 488.2 commands encompassed by SCPI were explained in the previous chapter and will not be examined in any more detail here. The "subsystem commands" are the heart of SCPI and the focus of the rest of this discussion.

* SCPI organizes commands into various sets that match "subsystems" of the target instrument. The commands for each subsystem are defined in a hierarchical structure similar to the hierarchical file system found on most computers. In SCPI, this command structure is called a "command tree". A simplified example, for the SENSe command as implemented on a DMM, is shown below:


                              SENSe
                                |
                +---------------+---------------+
                |                               |
             CURRent                         VOLTage
                |                               |
         +------+------+                 +------+------+
         |             |                 |             |
       RANGe       RESolution          RANGe        RESolution
         |             |                 |             |
     +---+---+         |             +---+---+         |
     |       |         |             |       |         |
   UPPer    AUTO      AUTO         UPPer    AUTO      AUTO
 

Definitions of the other subsystems are irrelevant for the moment. The SENSe subsystem is just a good way to discuss the syntax of SCPI, and other subsystems will be illustrated in the next section.

The command tree is described with nomenclature similar to that used for file systems. The command at the top of the tree is the "root" command, and subsystem commands are linked into "paths" through the tree. For example, one path through the tree is defined by the command sequence:


   :SENSe:VOLTage:RANGe:AUTO
 

-- which sets the DMM to read voltages and uses autoranging. Note how colons (":") are used as path separators. Another path is:


   :SENSe:CURRent:RANGe:UPPer
 

-- which sets the DMM to read currents and uses the upper current range of the DMM. Note that the full path of a command does not need to be sent to the DMM each time, but how and why that is so needs more detailed explanation. not

Commands sent to an instrument are intrepreted by a software routine called a "parser". When decoding SCPI subsystem commands, the parser has to keep track of the "current path" of the command, which is something like the "current directory" in a hierarchical file system: it specifies the subsystem block the DMM is decoding commands for.

The parser navigates through the tree as directed by subsystem command strings according to the following rules:

  • After power-on or the *RST common command is sent, the current path is set to the root.
  • A message terminator, usually a <newline> (line-feed) character, also sets the current path to the root.
  • A colon (":") is, as shown above, a path separator. Each time the parser finds a colon in the subsystem command string it moves down through the command tree one level. If the colon is the first character in the string, however, it specifies the root. (The extensive use of colons in SCPI subsystem command strings has led to a slightly disrespectful description of the language as "colon cancer".)
  • A semicolon (";") separates two commands in the same subsystem command string without changing the current path.
  • Whitespace characters, such as <tab> and <space>, are generally ignored. However, whitespace inside a subsytem command keyword is forbidden. For example, MEAS ure is not a legal keyword.

    Whitespace is also required to separate a parameter from a command. For example, :SOURce:VOLTage6.2 is incorrect, you must use :SOURce:VOLTage 6.2.

  • Commas (",") are used to separate multiple parameters for a single subsystem command.
  • Common commands, such as *RST, are not subsystem commands and are not interpreted as part of a path.

For example:


   :SENSe:VOLTage ; RANGe:AUTO ; RESolution:AUTO
 

-- is the same as executing:


   :SENSe:VOLTage:RANGe:AUTO
   :SENSe:VOLTage:RESolution:AUTO
 

Note that the spaces around the ";" are strictly window-dressing. The parser ignores them, they're just there to make the string easier to read. Similarly:


   :SENSe:VOLTage:RANGe:AUTO ; :SENSe:CURRent:RANGe:UPPer
 

-- is the same as executing both commands separately, since the ":" immediately following the separating ";" resets the current path to root.

* The command tree is specified concisely through a "subsystem command table" that define the commands and their parameters. For example, the SENSE command tree illustrated previously evaluates to the following command table:


   _______________________________________

   Command                 Parameters
   _______________________________________

   [:SENSe]               

      :CURRent            
         :RANGe           
            :AUTO          Boolean or ONCE
           [:UPPer]        numeric
         :RESolution       numeric
            :AUTO          Boolean or ONCE

      :VOLTage            
         :RANGe           
            :AUTO          Boolean or ONCE
           [:UPPer]        numeric
         :RESolution       numeric
            :AUTO          Boolean or ONCE
   _______________________________________
 

The hierarchy of the command paths is given by the level of indenting in the "Command" column of the table. Following the indenting yields subsystem command strings of the form:


   :SENSe:CURRent:RANGe:AUTO ON
 

As you should have noticed by now, most of the keywords are listed as strings of uppercase letters, followed by lowercase letters. This mixing of cases is not part of the SCPI definition as such. SCPI isn't case-sensitive, and so you can send subsystem commands all upppercase, all lowercase, or any mixture of the two. not

What the lowercase letters in the definitions specify is that those characters are optional, and may be discarded if desired. To illustrate:


   :SENS:CURR:RANG:AUTO ON
 

-- is the same as:


   :SENSe:CURRent:RANGe:AUTO ON
 

The keywords in square brackets are "implied" keywords, meaning that if a subsystem command at that path level is not specified, it is assumed. For example:


   :SENSe:VOLTage:RANGe:UPPer 6.5
 

-- is the same as:


   :VOLTage:RANGe 6.5
 

An implied keyword should not be used in a command string unless it is necessary to do so. Implied keywords often are defined to define enhancements of SCPI. They are left implied to keep from "breaking" programs that use commands that conform to earlier revs. Avoiding the use of implied keywords makes it more likely a program will work with an earlier type of SCPI instrument.

For almost all commands that can set a value, there is a matching query that can read one back. This is similar to 488.2 common command queries in that the query string is the same as the comparable command string, but with a "?" tacked on. For example, the command:


   :SENSe:VOLTage:RANGe
 

-- has the matching query:


   :SENSe:VOLTage:RANGe?
 

If a table contains a keyword that ends in a "?", that means that the subsystem command string only exists as a query, and there is no command form. Other subsystem commands may not have matching queries, as they initiate events, such as device triggers, and do not set values that can be queried.

The parameters for each command, if any, are listed in the right column of the table. If any parameters are optional, they are listed in square brackets, just like the implied keywords. The ranges of optional values are defined in the documentation for a specific instrument.

Commands are sent to the instrument followed by their parameters, if any are required. Note that parameters must be separated from the command by a space, and multiple parameters are separated by commas (","). The full command sequence is terminated by a newline, an EOI, or both.

[5.3] EXAMPLE SCPI COMMAND SETS

* For examples of SCPI syntax, consider simplified command sets for a hypothetical signal generator, DVM, and relay scanner.

These devices are examples of the three classes of programmable instruments: source, sense, and switch devices:

  • Source instruments output some kind of signal, such as power supplies and pulse generators.
  • Sense instruments are those which measure signals, such as power meters and counters.
  • Switch instruments use relays or solid-state switches to route signals between an instrument and devices under test.

More sophisticated instruments may combine multiple instrument functions in a single package.

Our hypothetical signal generator can produce sine, triangle, or square wave outputs. The output is programmable from 1 Hz to 100 kHz at levels of 0 to 500 mV RMS. The output impedance can be switched between 50 and 75 ohms.

At power-on, or after *RST, the signal generator is set to output a 1 millivolt RMS, 1 kHz sine wave with an output impedance of 75 ohms, although the actual output is disabled. The signal generator is programmed in fixed units of Hz, volts RMS, and ohms. The command table is illustrated below:


   __________________________________________

   Command                  Parameters 
   __________________________________________

    :OUTPut
      [:STATe]              Boolean
       :IMPedance           50 or 75

   [:SOURce]
       :FREQuency
         [:FIXed]           1 to 1e5
       :VOLTage
         [:LEVel]
            [:IMMediate]
               [AMPlitude]  0 to 0.5
       :FUNCtion
         [:SHApe]           SINe or SQUare or
                            TRIangle
   __________________________________________
 

This device incorporates two subsystems, an OUTPut subsystem and a SOURce subsystem. Note how the command set incorporates a large number of implied keywords -- a common feature of practical SCPI implementations that greatly reduces the number of commands you actually need to remember -- and simplifies to only five distinct command forms:


   :FREQ 100        Set output frequency (to 100 Hz).
   :VOLT 0.1        Set output voltage (to 100 mV RMS).
   :FUNC TRI        Set output function (to triangle wave).
   :OUTPut:IMP 50   Set output impedance (to 50 ohms).
   :OUTPut ON       Turn on outputs.
 

The matchinq queries consist of:


   :FREQ?         Query output frequency.
   :VOLT?         Query output voltage.
   :FUNC?         Query output function.
   :OUTPut:IMP?   Query output impedance.
   :OUTPut?       Query output state.
 

Note that the :OUTPut:IMP command only has two values, 50 or 75. Other values will be rounded to the allowed value.

Note also the :OUTPut ON command, which can cause problems for novices, since the output terminals of a SCPI instrument are disabled after power-on or *RST. The programmer has to use :OUTPut ON to specifically enable the outputs.

* The hypothetical DVM is capable of making either AC or DC voltage measurements. It measures input voltages from 0 to 100 volts DC or AC RMS. The DVM has two rear panel BNC ports, for the "measurement complete" output and an "external trigger" input. For better noise rejection, the DVM provides a low-pass input filter that is programmable to frequencies of 100, 200, or 1000 Hz.

After power-on or *RST, the DVM is configured to read DC voltages using autoranging and the best possible resolution. The input impedance is set to 10 megohms, and the input filter is set to 1000 Hz. The trigger source is set to IMMediate. Its command table is shown below:


   _______________________________________________

   Command                   Parameters
   _______________________________________________

    :CONFigure              
      [:SCALar]             
          :VOLTage          
             :AC             numeric,numeric (*)
            [:DC]            numeric,numeric (*)

    :FETCh                  
      [:SCALar]             
          :VOLTage          
             :AC?            numeric,numeric (*)
            [:DC]?           numeric,numeric (*)

    :INITiate               
      [:IMMediate]          

    :INPut                  
       :IMPedance            50 or 1e6
       :FILTer              
         [:LPASs]            100 or 200 or 1000

    :MEASure                
      [:SCALar]             
          :VOLTage          
             :AC             numeric,numeric (*)
            [:DC]            numeric,numeric (*)

    :READ                   
      [:SCALar]             
          :VOLTage          
             :AC?            numeric,numeric (*)
            [:DC]?           numeric,numeric (*)

   [:SENSe]                 
       :FUNCtion             AC or DC

    :TRIGger                
      [:IMMediate]          
       :SOURce               IMMediate or EXTernal
       :COUNt                numeric
   _______________________________________________

   (*):  The first numeric parameter specifies the 
   input voltage range from 0.001 to 100 volts by 
   powers of 10; the second specifies the voltage 
   resolution, which is rounded to 0.001, 0.01, 
   or 0.1 volts.  
   _______________________________________________
 

This device has 8 command subsystems that provide somewhat overlapping functionality. The commands :MEASure, :CONFigure & :READ, and :INITiate & :FETCh demonstrate how SCPI allows you to take measurements at differing levels of detail. :MEASure, for example, is very easy to use; all you need to know is what quantity you want to measure. :CONFigure & :READ are not quite as easy to use, but they are very flexible; and :INITiate & :FETCh are hard to use, but offer maximum flexibility.

The high-level commands are actually equivalent to sequences of low-level commands, so it makes sense to study the low-level commands first and then work our way up. However, in practice, a smart programmer will never use a low-level command when a higher-level one will do the job, since the higher-level commands make the job easier to implement and understand, as well as easier to port to other systems.

Most measurements can be modeled as a three-step process:

  • Set up the instrument.
  • Trigger the measurement.
  • Retrieve the reading.

When you use low-level commands, you must do each of these steps explicitly. Typically, you begin setup by sending *RST to place the instrument into a known state, and then you change each setting, one by one, until you have the instrument configured. Then you trigger the measurement. The trigger may be generated automatically by your setup commands, or you can send an explicit trigger command. For example, an :INITiate:IMMediate command, forces the measurement to occur as soon as the command is interpreted. Finally, you can read the measurement using a :FETCh query.

For the DVM, a low-level sequence of commands to read an AC voltage looks like this:


   10 OUTPUT @Dvm;"*RST"              ! Reset into a known state.
   20 OUTPUT @Dvm;":FUNC AC"          ! Change function to AC volts.
   30 OUTPUT @Dvm;":INP:IMP 50"       ! Change input impedance to 50 ohms.
   40 OUTPUT @Dvm;":INIT:IMM"         ! Trigger a reading.
   50 OUTPUT @Dvm;":FETCH:VOLT:AC?"   ! Query for the reading.
   60 ENTER @Dvm;Vac                  ! Get the reading.
 

Let's compare this to programming the instrument with high-level commands. :MEASure is the simplest (and generally most useful) way to make and read a measurement. A single :MEASure command is equivalent to programming an instrument setting, sending an :INITiate:IMMediate, followed by a :FETCh query. The same AC volts measurement shown above can be simplified using :MEASure to:


   10 OUTPUT @Dvm;":MEAS:VOLT:AC?"    ! Measure AC volts.
   20 ENTER @Dvm;Vac                  ! Get the reading.
 

Using :MEASure does have its disadvantages. When you use :MEASure, the instrument chooses the "best" default settings to accomplish the measurement you want. Usually instrument documentation lists the settings associated with :MEASure. However, sometimes the instrument's idea of a "best" setting conflicts with your needs. For example, suppose you want to use the DVM to read an AC voltage through a 1 megohm input impedance. :MEASure won't work, because it always sets the input impedance to 50 ohms for an AC measurement.

:CONFigure and :READ offer a reasonable compromise between :MEASure and low-level commands. :CONFigure performs an instrument setup, while :READ triggers a measurement and reads back the voltage, and so :CONFigure followed by :READ is equivalent to a :MEASure. This is how you could read an AC voltage through a 1 megohm input impedance:


   10 OUTPUT @Dvm;"*RST"              ! Reset to a known state.
   20 OUTPUT @Dvm;":CONF:VOLT:AC"     ! Set up to read AC volts.
   30 OUTPUT @Dvm;":INP:IMP 1e6"      ! Set input impedance.
   40 OUTPUT @Dvm;":READ:VOLT:AC?"    ! Trigger and query for reading.
   50 ENTER @Dvm;Vac                  ! Read back the voltage.
 

* Our hypothetical scanner is a simple, 8-channel multiplexer switch. It includes two rear panel BNC ports: "channel closed" and "external trigger". At power on or after *RST, all channels are open and the trigger source is set to immediate. The command table follows:


   _______________________________________________ 

   Command                   Parameters
   _______________________________________________

   [:ROUTe]
       :CLOSe                (@0:7)
       :OPEN                 (@0:7)
       :SCAN                 (@0:7)

    :TRIGger
      [:IMMediate]
       :SOURce               IMMediate or EXTernal
   _______________________________________________
 

This is, like the source, a simple device, with only two command subsystems. Note how the Scanner uses a "channel list" as a parameter. This is a special parameter used in some :ROUTe subcommands. Typical examples of channel lists include:


   (@1)       Channel 1.
   (@1:4)     Channels 1 through 4.
   (@1,3)     Channels 1 and 3 only.
   (@1:4,7)   Channels 1 through 4, and 7.
 

The :OPEN and :CLOSe commands simply open and close switches in the channel list. The :SCAN command places a channel list into the internal memory of the switch box. Once a :SCAN has been programmed, the scanner closes channels in sequence using break-before-make as it receives each trigger, and begins again at the first channel in the list when it completes the last.

The following statements configure the scanner to scan channels 1 through 3 using the rear panel BNC external trigger:


   40 OUTPUT @Scan;"*RST;*CLS"
   50 OUTPUT @Scan;":SCAN (@1:3)"
   60 OUTPUT @Scan;":TRIG:SOUR EXT"
 

You can query the condition of any individual channel or channel list. SCPI instruments always return a 1 or a 0 in the same order that the channel list in the query was specified. The meaning of 1 or 0 depends on whether you query using the :OPEN or :CLOSe command. If you query using :OPEN, a 1 means open and a 0 means closed, while if you query using :CLOSe, a 1 means closed and a 0 means open.

The following statements perform some simple queries:


   10 OUTPUT @Scan;"OPEN? (@1)"     ! Is channel 1 open?
   20 ENTER @Scan;Ch1               ! Read back state (1=TRUE=OPEN).
   30 OUTPUT @Scan;"CLOSE? (@1)"    ! Is channel 1 closed?
   40 ENTER @Scan;Ch1               ! Read back state (1=TRUE=CLOSED).
   50 OUTPUT @Scan;"OPEN? (@1:4)"   ! Are any of channels 1 through 4 open?
   60 ENTER @Scan;Ch1,Ch2,Ch3,Ch4   ! Read back states of four channels.
 

* As an example consider programming the three instruments to test the gain of a three-stage amplifier. The signal generator drives a sine wave into the input stage of the amplifier, the scanner routes signals from the output of each stage into the DVM, and gains are computed using simple voltage ratios, not DB.

Measurement speed is optimized in this application by setting the DVM to a fixed range and performing "hardwired handshaking" between the DVM and the switch box. This is done by linking the DVM's "measurement complete" output to the switch box's "external trigger" input, and linking the switch box's "channel closed" output back to the DVM's "external trigger" input.

Each time the DVM completes a measurement, it pulses the "measurement complete" output, which is turn causes the switch box to move to the next channel in its scan list. When the switch box closes this channel, the box pulses its "channel closed" output, which feeds back to the DVM to trigger the next measurement.

The program to perform these measurements follows below:


   10   CLS
   15   INTEGER Dummy
   20   REAL Readings(0:3)
   30   !
   40   ASSIGN @Dvm TO 722                  ! Set up paths to devices.
   50   ASSIGN @Switch TO 711
   60   ASSIGN @Siggen TO 719
   70   !
   80   CLEAR @Dvm                          ! Clear device interfaces.
   90   CLEAR @Switch
   100  CLEAR @Siggen
   110  !
   120  OUTPUT @Dvm;"*CLS;*RST"             ! Reset the devices.
   130  OUTPUT @Switch;"*CLS;*RST"
   140  OUTPUT @Siggen;"*CLS;*RST"
   150  !
   160  ! Configure the DVM to measure a 500 mV RMS signal with 5 mv
   170  ! resolution.
   180  !
   190  OUTPUT @Dvm;":CONF:VOLT:AC 0.5,0.005"
   200  !
   210  ! Once armed, accept four triggers from the external trigger.
   220  !
   230  OUTPUT @Dvm;":INIT ; :TRIG:COUNT 4; SOUR EXT"
   240  !
   250  ! Set the signal generator's output frequency to 100 kHz at 500 mV
   260  ! RMS.  The output function is SINE (default at *RST).
   270  !
   280  OUTPUT @Siggen;":FREQ 1e5 ; :VOLT 0.5"
   290  !
   300  ! Change the source output frequency to 50 ohms.
   310  !
   320  OUTPUT @Switch;":SCAN (@1:4) ; :TRIG:SOUR EXT"
   330  !
   340  ! Begin measurement -- turn on the source output signal; the *OPC?
   350  ! query returns a 1 only after the output has settled.
   360  !
   370  OUTPUT @Siggen;":OUTPUT ON ; *OPC?"
   380  ENTER @Siggen;Dummy
   390  !
   400  ! Close the first channel in the switch, the hardwired triggering  
   410  ! does the rest.
   420  !
   430  OUTPUT @Switch;":INIT ; :TRIG:IMM"
   440  !
   450  ! Put readings in the output queue.
   460  !
   470  OUTPUT @Dvm;":READ:VOLT:AC?"
   480  DISP "Waiting for the measurement to complete."
   490  !
   500  ! Get readings into array as they become available.
   510  !
   520  ENTER @Dvm;Readings(*)
   530  DISP "Measurement complete."
   540  !
   550  ! Turn off signal generator output.
   560  !
   570  OUTPUT @Siggen;":OUTPUT OFF"
   580  !
   590  ! Calculate and print gains.
   595  !
   600  PRINT "Stage 1 gain = ";Readings(1)/Readings(0)
   610  PRINT "Stage 2 gain = ";Readings(2)/Readings(1)
   620  PRINT "Stage 3 gain = ";Readings(3)/Readings(2)
   630  !
   640  END
 

[5.4] SCPI DATA FORMATS

* SCPI data types are essentially derived (with some small additions) from the program data types defined in 488.2. The formats are flexible ("forgiving listening") and a quick survey should be easily understood.

Simple numeric parameters encompass familiar integer and floating-point formats:


   100
   100.
    -1.23
     4.5e3
    -7.89E-01
      .5
 

Numeric parameters are a superset of simple numeric parameters, and add certain constant values to that definition. All instruments will recognize the constants:


   MAXimum
   MINimum
 

-- though the exact value of these constants is device-dependent. Other special values, such as:


   UP
   INFinity
   DEFault
 

-- may be defined for specific instruments. For example:


   100 OUTPUT @Dvm;":VOLT:DC MAX"
   110 OUTPUT @Dvm;":CONF:VOLT:DC 10.0,Min"
 

Discrete parameters are keywords associated with a list of discrete settings in a device. Like subsystem commands, they have a long and a short form. Upper- and lower-case letters may be mixed, but the value returned for a discrete parameter by a subsystem query will always be uppercase. Samples of discrete parameters include:


   INTernal:         Specify internal trigger source.
   EXTernal:         Specify external trigger source.
   POSitive:         Specify trigger arm on positive transition.
   NEGative:         Specify trigger arm on negative transition.
   BOTH:             Specify trigger arm on either transition.
 

For some practical examples:


   100 OUTPUT @Dvm;":TRIGGER:SOURCE INT"
   110 OUTPUT @Dvm;":ARM:SLOPE NEGATIVE"
 

Boolean parameters should be familiar:


   ON
   OFF
   TRUE
   FALSE
   1
   0
 

When you query a Boolean setting, you will always get back a "1" or "0". For example:


   100 OUTPUT @Dvm;":OUTPUT ON"
   110 OUTPUT @Dvm;":OUTPUT 0"
 

String parameters allow ASCII strings to be sent as parameters. For example:


   'this is a STRING'
   "this is also a string"
   "one double quote inside brackets: [""]"
   'one single quote inside brackets: ['']'
 

Single quotes are the most convenient format for HP BASIC:


   110 OUTPUT @Dvm;":DISPLAY:TEXT 'STOP!'"
 

Block parameters are sent using the indefinite-length and definite-length block formats defined by 488.2, where the formats for indefinite-length and definite-length blocks are respectively:


   #0<DAB><DAB> ... <DAB>NL&EOI
   #<num_digits_in_byte_count><byte_count><DAB1><DAB2> ... <DABn>
 

For example, the following HP BASIC commands send the same 7 bytes of ASCII text as indefinite- and definite-length blocks respectively:


   120 OUTPUT @Dvm;"#0ABC_XYZ",END  ! END asserts EOI.
   OUTPUT @Dvm;"#17ABC_XYZ"         ! <num_digits>=1, <byte_count>=7
 

Non-decimal numeric parameters allow numeric information to be sent as binary, octal, or hexadecimal:


   #b010110100
   #Q773662
   #h3FA1
 

The header may be upper- or lower-case characters.

* As mentioned earlier, data returned to a host in response to a SCPI query is known as "response data". The response data types, which are also derived from 488.2 response data types, match the data types defined for parameters but with more concise and restricted syntax ("precise talking").

Note that multiple data elements returned in response to a query are separated by commas (","). Note also that, since multiple queries can be sent as a single program message:


   :QUERY1?;:QUERY2?
 

-- then multiple responses can also be sent as a single response message, with the responses separated by semicolons (";"). (Sending multiple queries in a single program message is bad form, though it is not illegal.) Response data is always terminated with a newline and EOI. always

Real response data defines floating-point data types with a uniform format:


      1.23E+0
     -1.0E+2
     -1.23
   -100.0
     -7.89E-01
      0.5
 

Integer response data defines an integer-only data format:


       0
    +100
    -100
     256
   65535
       4
 

Discrete response data is defined exactly as is discrete parameter data, but the response data, unlike the discrete parameter data, is always uppercase: always


   INT
   EXT
   POS
   NEG
 

String response data is defined like string parameter data, except that only double-quotes are legal:


   "this is a string"
   "one double quote inside brackets: [""]"
 

Definite-length and indefinite-length block response data types are totally identical to their parameter equivalents.

Binary, octal, and hexadecimal response data types are identical to their parameter equivalents, except that lower-case headers are not allowed:


   #B00001111
   #Q0707
   #H0F1F
 

[5.5] STATUS & TRIGGERING

* SCPI specifies advanced features for status and triggering. In fact, it defines more features than anyone could ever want.

The status system is in particular extremely complicated. As it turns out, most of the features were simply due to different HP instrument divisions promoting their own pet features when the spec was being defined, with the end result being a system that can be extremely confusing.

As a way of getting a grasp of the SCPI status system, consider a simple example: the status system of the 34401 (ALF) DMM, which is illustrated below:


         +-----+   +-----+
         | VOV +-->| VOV +-->-+
         |     |   |     |    |
         | COV +-->| COV +-->-+        VOV:  voltage overload
         |     |   |     |    |        COV:  current overload
         | 2   +-->| 2   +-->-+        OOV:  ohms overload
         |     |   |     |    |        TLO:  limit test fail lo
         | 3   +-->| 3   +-->-+        THI:  limit test fail hi
         |     |   |     |    |
         | 4   +-->| 4   +-->-+
         |     |   |     |    |
         | 5   +-->| 5   +-->-+
         |     |   |     |    |
         | 6   +-->| 6   +-->-+
         |     |   |     |    |
         | 7   +-->| 7   +-->-+
         |     |   |     |    +------------+
         | 8   +-->| 8   +-->-+            |
         |     |   |     |    |            |
         | OOV +-->| OOV +-->-+            |
         |     |   |     |    |            |
         | 10  +-->| 10  +-->-+            |
         |     |   |     |    |            |
         | TLO +-->| TLO +-->-+            |
         |     |   |     |    |            |
         | THI +-->| THI +-->-+            |
         |     |   |     |    |            |        Status Byte
         | 13  +-->| 13  +-->-+            |    +-----+   +-----+   
         |     |   |     |    |            |    | 0   +-->| 0   +-->-+
         | 14  +-->| 14  +-->-+            |    |     |   |     |    |
         |     |   |     |    |            |    | 1   +-->| 1   +-->-+
         | 15  +-->| 15  +-->-+            |    |     |   |     |    |
         +-----+   +-----+                 |    | 2   +-->| 2   +-->-+
 STAT:QUES:EVEN?   STAT:QUES:ENAB <mask>   |    |     |   |     |    |
                   STAT:QUES:ENAB?         +--->| QUE +-->| QUE +-->-+
                                                |     |   |     |    +-[OR]-+
                         from output queue ---->| MAV +-->| MAV +-->-+      |
                                                |     |   |     |    |      |
         +-----+   +-----+           +--------->| ESB +-->| ESB +-->-+      |
         | OPC +-->| OPC +-->-+      |          |     |   |     |    |      |
         |     |   |     |    |      |    +---->| RQS +-->| --- +-->-+      |
         | RQC +-->| RQC +-->-+      |    |     |     |   |     |    |      |
         |     |   |     |    |      |    |     | 7   +-->| 7   +-->-+      |
         | QYE +-->| QYE +-->-+      |    |     +-----+   +-----+           |
         |     |   |     |    |      |    |      *STB      *SRE <mask>      |
         | DDE +-->| DDE +-->-+      |    |                *SRE?            |
         |     |   |     |    +-[OR]-+    +---------------------------------+
         | EXE +-->| EXE +-->-+
         |     |   |     |    |
         | CME +-->| CME +-->-+
         |     |   |     |    |
         | URQ +-->| URQ +-->-+
         |     |   |     |    |
         | PON +-->| PON +-->-+
         +-----+   +-----+
          *ESR?     *ESE <mask>
                    *ESE?
 

This is a consistent extension of the 488.2 status system. In this case, an additional status bit, QUE (Questionable Data), is used to reflect the status of an additional status register, the Questionable Data register, which contains a subset of SCPI bit definitions required by the ALF. (Note that the bit acronyms specified are not defined by SCPI, I just made them up to make the diagram simpler.) not

The Questionable Data Register can be queried with: STAT:QUES:EVEN?. Its event enable register can be set with STAT:QUES:ENAB <mask>, and the event masks can be read with STAT:QUES:ENAB?.

While only 5 bits are defined in the Questionable Data Register on the ALF, the SCPI standard provides definitions for most of the other bits as well. Note that SCPI also defines bit 7 of the Status Byte as OPR, which reflects the status of a another 16-bit status register, the Standard Operation Status Register, that is not implemented on the ALF.

* The SCPI trigger system is also very sophisticated, but more useful. An instrument trigger system synchronizes an instrument's actions -- such as making a measurement or generating an output signal -- with specific events -- such as a software command or an external trigger input.

The SCPI triggering system can become quite complicated but a simple subset of it incoporates three levels:

  • An INIT level that simply tells the device to trigger.
  • A TRIG level that adds triggering conditions.
  • An ARM level that adds pretriggering setup conditions.

This is more than enough for most purposes, and in fact many instruments don't implement even this level of triggering capabilities.

* Example commands using INIT include:


   :ABORt           Abort operations, go to idle.
   :INIT:IMM        Execute programmed operation.
   :INIT:CONT ON    Execute programmed operations continuously.
   :INIT:CONT OFF   Stop programmed operations after current one is done.
 

On their own, the INIT commands simply tell the device to do something immediately, either once, using :INIT:IMM, or continuously, using :INIT:CONT ON (with the sequence broken by :INIT:CONT OFF or ABORT).

* The TRIG commands add a layer of qualification to the triggering. The TRIG commands are very complicated, so a list of typical commands will have to do:


   :TRIG:SOURCE IMM    Trigger on INIT:IMM (default action).
   :TRIG:SOURCE INT    Trigger on internal signal (input signal).
   :TRIG:SOURCE EXT    Trigger on external trigger input.
   :TRIG:SOURCE MAN    Trigger on front-panel button or the like.
   :TRIG:SOURCE BUS    Trigger on HPIB GET or *TRG command.

   :TRIG:LEVEL 3       Specify level at which trigger occurs (5 volts).

   :TRIG:SLOPE POS     Trigger on rising edge of signal.
   :TRIG:SLOPE NEG     Trigger on falling edge of signal.
   :TRIG:SLOPE BOTH    Trigger on both edges of signal.

   :TRIG:COUPL AC      Specify AC coupling to trigger input.
   :TRIG:COUPL DC      Specify DC coupling to trigger input.
   :TRIG:DELAY 5       Specify delay of action after triggering (5 seconds).
   :TRIG:ECOUNT 4      Specify number of trigger events to cause trigger (4).
   :TRIG:HYST 0.05     Specify noise margin in trigger signal.

   :TRIG:TTL           Specify trigger on TTL signal levels.
 

This should be self-explanatory, except for the :TRIG:HYST command. It is necessary to specify a noise margin with a trigger because the input signal that causes the trigger may be noisy, and if the noise jumps around the trigger level during a signal transition, the trigger may occur multiple times when it's only supposed to happen once.

For example, suppose we trigger off an input signal hitting 3 volts on a positive slope. The hysteresis spec tells the triggering system not to trigger again until the input signal travels downward again by at least the noise margin.

To demonstrate a TRIG configuration, assume that you want to make a measurement when the input signal passes through 5 volts, with either a positive or negative slope. The signal contains noise that averages about 2 millivolts peak to peak. This could be done with the following sequence of trigger commands:


   10  OUTPUT @Dev;"*RST;*CLS"           ! Clear the device.
   20  CALL Config_dev(@Dev)             ! Set up device configuration.
   25  !
   30  OUTPUT @Dev;":TRIG:SOURCE EXT"    ! Trigger on external trigger input.
   40  OUTPUT @Dev;":TRIG:LEVEL 5"       ! Trigger at 5 V level.
   50  OUTPUT @Dev;":TRIG:SLOPE BOTH"    ! Trigger at any crossing.
   60  OUTPUT @Dev;":TRIG:HYST 0.002"    ! Compensate for noise.
   65  !
   70  OUTPUT @Dev;":INIT:IMM"           ! Wait for it.
   75  !
   80  CALL Get_trace(@Dev,Data(*))      ! Get trace from device.
 

Note how :INIT:IMM is used to tell the device to wait for a trigger. The TRIG statements merely qualify what the trigger will be. Note also the CALL statements in this listing. These invoke user-defined subprograms to perform the indicated actions.

* The ARM commands offer a second level of triggering to provide pretriggering conditions. Their syntax is effectively the same as the TRIG commands, with the keyword "ARM" substituted for "TRIG".

For example, assume that you want to measure a TTL signal input. Before triggering the measurement, you want to first capture two negative TTL edges on an input fed to the external trigger input, and then capture three negative TTL edges on the input signal itself.


   10   OUTPUT @Dev;"*RST;*CLS"         ! Clear the device.
   20   CALL Config_dev(@Dev)           ! Set up device configuration.
   25   !
   30   OUTPUT @Dev;":ARM:SOURCE EXT"   ! Arm on external trigger input.
   40   OUTPUT @Dev;":ARM:TTL"          ! Arm signal is TTL.
   50   OUTPUT @Dev;":ARM:EDGE NEG"     ! Arm on negative edges.
   60   OUTPUT @Dev;":ARM:ECOUNT 2"     ! Count two edges to arm.
   65   !
   70   OUTPUT @Dev;":TRIG:SOURCE INT"  ! Trigger on input signal.
   80   OUTPUT @Dev;":TRIG:TTL"         ! Trigger is TTL.
   90   OUTPUT @Dev;":TRIG:EDGE NEG"    ! Trigger on negative edges.
   100  OUTPUT @Dev;":TRIG:ECOUNT 3"    ! Count three edges to trigger.
   105  !
   110  OUTPUT @Dev;":INIT:IMM"         ! Wait for trigger.
   115  !
   120  CALL Get_trace(@Dev,Data(*))    ! Get trace from device.
 

The illustration below shows the operation of this trigger sequence:


          A             B
      +-------------------------------------------------------------+
      |       1         2                                           |
      |........    ......    ...................................... |
  EXT |       :    :    :    :                                      |
      |       :....:    :....:                                      |
      |                                                             |
      |     ......    ......    ......    ......    ......    ..... |
  INT |     :    :    :    :    :    :    :    :    :    :    :     |
      | ....:    :....:    :....:    :....:    :....:    :....:     |
      |                                                             |
      |                    1         2         3                    |
      +-------------------------------------------------------------+
                                               C          

    A: The :INITiate:IMMediate command begins the arming sequence.
    B: The arming conditions are satisfied (2 negative edges on D01).
    C: The trigger conditions are satisfied (3 negative edges after arm).
 

Even more complicated triggering actions could be defined as needed.


[6.0] HPIB Tutor (6): A SCPI-Based HPIB Instrument -- The 34401 DMM

* This chapter illustrates the implementation of SCPI by showing how it is implemented in a practical instrument, the popular 34401 digital multimeter (DMM), known informally as the "Alf".

Due to its relative simplicity and wide range of functionality, the Alf is an excellent demonstration of a SCPI-based instrument. This chapter will outline the functionality of the DMM, describe its SCPI command set, and provide short programming examples of its use.



BACK TO INDEX

[6.1] 34401 OVERVIEW

* The 34401 DMM has the following measurement capabilities:

  • AC and DC volts, with a range from 0.1 to 1000 volts (750 volts AC).
  • Resistance, with a range from 100 ohms to 100 megohms.
  • AC and DC current, with a range from 10 milliamps (DC only) to 3 amps.
  • Frequency and period, with ranges from 3 hertz to 300 kilohertz.
  • Continuity and diode checking.
  • Display resolution from 4.5 to 6.5 digits.
  • Several math functions, and a capability to store 512 readings in memory.
  • A menu-driven front-panel interface and a vacuum-fluorescent display.

Both HPIB and RS-232 interfaces are standard for remote programming and for direct printer output. The RS-232 output can be modified to provide a digital pass-fail output.

The Alf features a SCPI-based command set (with some extensions for features not included in the SCPI standard at the time the DMM was designed), plus the ability to emulate the HP 3478A DMM or the Fluke 8840A/8842A DMM.

Note that the 34401 was described as having "relative" simplicity. Due to its wide range of capabilities, there is still a lot of detail to consider. These capabilities are broken down into the following categories:

  • Measurement configuration.
  • Math operations.
  • Triggering.
  • System-related operations.
  • Remote interface configuration.
  • Calibration.
  • Power-on and reset state.

* The DMM's measurement configuration features include the following:

  • AC signal filter: You can select one of three different AC input filters to optimize reading speed or low-frequency accuracy. The slow filter takes 7 seconds to take a reading, the medium filter takes 1 second, and the fast filter takes a tenth of a second.

    The AC filter selection is stored in volatile memory. The DMM defaults to the medium filter on power-on or *RST. (Unless otherwise specified, all other settings and values are stored in volatile memory, and "go away" if you turn off the DMM.)

  • Continuity threshold resistance: When measuring continuity, the DMM emits a continuous tone if the measured resistance is less than a "threshold resistance". You can set the threshold to any value from 1 to 1000 ohms. The threshold resistance can only be set from the front panel. It cannot be set programmatically.
  • DC input resistance: By default, the DMM's input resistance is fixed at 10 megohms for all DC voltage ranges to minimize noise pickup. To reduce the effects of measurement loading errors, you can set the input resistance to greater than 10 gigohms for the 100 millivolts DC, 1 volt DC, and 10 volts DC ranges.
  • Resolution: Resolution is expressed in terms of the number of digits the DMM can measure or display. You can set the resolution to 4.5, 5.5, or 6.5 digits. Setting the DMM to 6.5 digits provides the greatest accuracy, while setting it to 4.5 digits provides the greatest measurement speed. The DMM defaults to 5.5 digits on power-on or *RST.

    The resolution is fixed at 4.5 digits for continuity and diode tests. For AC measurements, the resolution is actually fixed at 6.5 digits, but it will be masked to the appropriate resolution setting.

    For DC and resistance measurements, changing the number of digits also changes the "integration time", or the length of time the DMM takes to make a measurement. The more digits, the more power-line cycles (PLCs) needed to establish the measurement. The integration time can be set programmably.

  • Front-rear input terminal switching: The DMM has input terminals on both the front and the back, and you can make any measurement from either set of terminals. Terminal switching can only be performed from the front panel buttons. There is no way to do it programmatically.
  • Autozero: When autozero is enabled (the default), the DMM internally disconnects the input signal following each measurement, and takes a "zero reading". It then subtracts the zero reading from the preceding reading. This nulls out the effect of input offset voltages.

    If autozero is disabled, the DMM takes one zero reading and subtracts it from all following measurements. It takes a new zero reading each time you change the function, range, or integration time.

  • Ranging: You can let the DMM select the range using autoranging or you can select a fixed range using manual ranging. The range is fixed for continuity tests and diode tests. For ratio measurements, the specified range applies to the signal connect to the INPUT terminals, and autoranging is automatically selected for reference voltage measurements on the SENSE terminals. The DMM defaults to autoranging on power-on or *RST.

* There are five math operations, only one of which can be enabled at a time. Each performs a mathematical operation on each reading, or stores data on a series of readings. The math operations use one or more internal registers, while others hold the results of the math operation.

The table below shows the allowed math / measurement function combinations:


   ___________________________________________________

             Null    Min-Max    dB       dBm     Limit  
   ___________________________________________________

   DC V        X        X        X        X        X    
   AC V        X        X        X        X        X    
   DC I        X        X                          X    
   AC I        X        X                          X    
   OHMS 2W     X        X                          X    
   OHMS 4W     X        X                          X    
   FREQ        X        X                          X    
   PER         X        X                          X    
   CONT                                                 
   DIODE                                                
   RATIO                X                          X    
   ___________________________________________________
 

Note that only one math operation can be set at a time; setting a new math operation clears the previous one. The operations are as follows:

  • The min-max operation stores the minimum and maximum readings during a series of measurements. The DMM then calculates the average of all readings and records the number of readings taken since min-max was enabled.
  • In null or relative measurements, each reading is the difference between a stored null value and the input signal. The null value can be set to any value between 0 and +/-120% of the highest range for the present function. The null value can be set directly as a number from the front-panel or SCPI command, or it can be directly read in from a measurement.
  • The DMM AC measurements can be made in dB as referenced to some stored reference value. The reference value is defined in dBm, and can be set from any value between 0 dBm and +/-200 dBm. The value can be set directly from the front panel or SCPI command -- or it can be directly entered from a measurement.

    The dBm operation calculates the power delivered by an AC signal to a resistance, referenced to 1 milliwatt. You can choose from 17 different resistance values, from 50 to 8000 ohms, with the default being 600 ohms.

  • The limit test operation allows you to perform pass/fail testing on upper and lower that you specify. You can set the upper and lower limits to any value between 0 and +/-120% of the highest range for the present function. The upper limit should be a more positive number than the lower limit. The default limits are both 0.

    The DMM can be programmed to generate a service request on a failed reading. There are also jumpers inside the DMM that allow you to use the DMM's serial port to output pass-fail indication signals; pin 1 will provide a low-going pulse (from 5 VDC to 0, for 2 milliseconds minimum) on a passed test, while pin 9 will provide a similar low-going pulse on a failed test. (Note that setting this configuration means that the RS-232 port can no longer be used for serial communications.)

    You can set limits from the front panel either programmatically, or by making a measurement.

* The DMM's triggering system allows you to generate triggers manually or automatically, take multiple readings per trigger, and insert a delay before each reading. Normally, the DMM takes one reading per trigger, but you can specify multiple readings -- up to 50,000 -- per trigger.

You can trigger the DMM from the front panel using a single trigger, an external trigger, or auto triggering. Single triggering takes one reading each time you press the "Single" button. External triggering is like single triggering, but the DMM waits for a pulse on the rear-panel EXTERNAL TRIGGER BNC input before taking a reading. Auto triggering takes continuous readings at the fastest possible rate for the current configuration.

Setting up a trigger requires the following steps:

  • The DMM must be configured for a measurement by selecting the function, range, resolution, and so on.
  • The trigger source must be selected: either a software (HPIB) trigger, a hardware trigger from the EXTERNAL TRIGGER terminal, or an immediate internal trigger.
  • Finally, the DMM must be placed into the "wait for trigger" state and wait for the trigger to come along.

The actions required to perform these steps are outlined below.

  • Trigger source choices: The DMM can be configured from the front panel to accept a single pushbutton trigger, a hardware trigger from the EXTERNAL TRIGGER input, or continuously take readings using auto trigger. Auto triggering is the default. The DMM can be configured programmatically to accept a software trigger over the HPIB, a hardware trigger from the EXTERNAL TRIGGER, or an immediate internal trigger.

    Note that the EXTERNAL TRIGGER queues up one trigger input. If a measurement is in progress and a trigger pulse comes in, that trigger pulse will initiate the next measurement immediately after the current one is completed.

    Software triggering is accomplished with the *TRG common command or the GET byte command. The DMM must be configured to the wait-for-trigger state for these trigger commands to operate.

  • Number of Samples: By default, the DMM takes one reading each time it receives a trigger from the selected trigger source (if the DMM is in the wait-for-trigger state). You can, however, instruct the DMM to take multiple readings for each trigger received. The number of samples can range from 1 to 50,000, and can be set either from the front panel or programmatically.
  • Number of Triggers: By default, the DMM accepts only one trigger before taking a measurement and then returning to idle mode. You can, however, instruct the DMM to accept multiple triggers before taking a reading. The number of triggers can range from 1 to 50,000. Note that it can only be set programmatically, there is no front-panel capability.
  • Trigger Delay: You can insert a delay between the trigger signal and each sample that follows. This may be useful in a system where an output has a certain settling time. The delay time can be set from 0 to 3600 seconds, and can be set either programmatically or from the front panel. If you specify multiple readings on a trigger, the delay time applies to each measurement.

    The default delay time depends on the function, range, integration time, and AC filter setting of the DMM; refer to DMM documentation for details.

  • Reading Hold: This feature allows you to "latch" a reading and leave it on the display. This is useful for troubleshooting systems where you cannot place the probes and see the DMM display at the same time. This feature can only be set from the front panel.
  • EXTERNAL TRIGGER & VOLTMETER COMPLETE: The triggering system interfaces to the outside world through two BNC connectors on the back panel. The EXTERNAL TRIGGER connector triggers a reading (if configured to do so) when a low-true (5 VDC to 0) pulse occurs on that input. The VOLTMETER COMPLETE terminal generates a similar low-true pulse when the reading is complete.

* System-related operations include such topics as reading memory, errors, self-test, and display control:

  • Reading Memory: The DMM can store up to 512 readings in an internal memory queue. You can recall the readings to the display, or read buffered readings back programmatically.
  • Error Conditions: The DMM can queue up to 20 error codes in internal memory. The error codes can be read back from the front panel or programmatically, and are read out as oldest-first. If more than 20 errors have occurred, the most recent is replaced with "too many errors" (error 350) error message, and no more errors will be stored until you remove some from the queue.

    If no errors have occurred when you read the error queue, the DMM responds with a "no error" (error 0) error message.

    The display error flag will not be cleared until all the errors have been read. The error queue is cleared at power-on or *RST.

  • Self-Test: The DMM performs a power-on self-test that checks a minimum amount of the DMM's functionality. A longer, more complete self-test (taking 15 seconds) can be initiated from the front panel or programmatically. The self-test will clear readings memory, but otherwise the settings will not be disturbed.
  • Display Control: You can turn the front-panel display or off, either from the front panel or programmatically. You can also programmatically display a message on the front panel.
  • Beeper Control: The DMM contains a speaker that will beep under certain conditions. You can turn it off (for a subset of those conditions) and back on again, either from the front panel or programmatically.
  • Comma separators: You can set the DMM to display comma separators in long numbers. This feature can only be set from the front panel.
  • Firmware revision query: The DMM has three microprocessors. You can query the DMM, either from the front panel or programmatically, for the revision levels of their firmware.
  • SCPI Language Version: You can query the DMM programmatically to determine its SCPI revision level.

* You can set configuration operations for the DMM's remote programming interface (HPIB or RS-232) from the front panel. Of course it is impossible to do it programmatically. You can also select the DMM's command set. (If you are having troubles communicating with the DMM, you might check to see what interface or language option is set.)

All these configuration settings are stored in non-volatile memory. It will be retained even if the DMM is switched off.

  • Remote interface selection: You can select remote operation over either the HPIB or RS-232 port from the front panel.
  • HPIB configuration: You can set the DMM's address anywhere from 0 to 31. The factory-set default is 22. If you set the address to 31, the DMM will be in talk-only mode, which will allow it to talk directly to a printer.
  • RS-232 configuration: You can select standard baud rates from 300 to 9600 baud. You can also set parity as "None" (8 data bits), "Even" (7 data bits), or "Odd" (7 data bits). The factory preset is 9600 baud and even parity.
  • Programming language selection: You can select one of three command sets for the DMM: SCPI (default), HP3478A, or Fluke 8840A. Note that you can only perform remote interface programming over RS-232 with the SCPI language, since the other selections only support HPIB.

* The DMM allows you to lock out unauthorized calibrations, as well as obtain a count of the number of times it has been calibrated or a message stored during calibration. Of course, this information is stored in nonvolatile memory.

  • Calibration security: This allows you to enter a security code to prevent accidental or unauthorized calibrations of the DMM. It is set to secured at the factory, with the calibration code "HP033401".

    You can set the security code programmatically or from the front panel. If you set it programmatically, it may consists of up to 12 alphanumeric characters, the first of which must be a letter. If you set it from the front panel, the code consists of the characters "HP" plus 6 digits (all 8 characters are required).

  • Calibration count: The number of times the DMM has been calibrated can be read from the front panel or over the remote programming interface.
  • Calibration message: You can store a string of up to 40 characters in the DMM to identify calibration information, such as the date of last calibration, due date of next calibration, and so on.

[6.2] PROGRAMMING THE 34401

* The simplest way to obtain a reading from the DMM is via the MEASure? command. However, this command does not offer much flexibility, since the DMM gives you the settings it thinks best for you and then makes the measurement. Optional features, such as setting NULL operation, won't work.

The only settings you can set are function, range, and resolution. You can set these as parameters to the MEASure? command itself:


   MEASure:<function> <range>, <resolution>
 

The relevant functions include:


   VOLTage:DC?               DC voltage.
   VOLTage:DC:RATio?         DC voltage ratio.
   VOLTage:AC?               AC voltage.
   CURRent:DC?               DC current.
   CURRent:AC?               AC current.
   RESistance?               Ohms.
   FRESistance?              4-wire ohms.
   FREQuency?                Frequency count.
   PERiod?                   Period.
   CONTinuity?               Continuity.
   DIODe?                    Diode test.
 

For example:


   100 OUTPUT @Dmm;"MEAS:VOLT:DC? 10,0.003" ! DC, 10 V range, 3 mV resolution.
   110 ENTER @Dmm;Volts
 

For more programming flexibility, use the CONFigure command. This will also preset the DMM to the settings it thinks best, but it won't take a reading; if you want to change some of the settings you may do so, and then take a reading with the READ? command.

READ? will arm the DMM into the wait-for-trigger state. On triggering, the DMM will obtain the reading and place it in the output buffer.

Note that if READ? is used, the output data will not be buffered in internal memory. You have to enter the readings as they arrive in the output buffer or they are lost. Note also that you can provide the same function, range, and resolution parameters for CONFigure that you can with MEASure?

For example:


   100 OUTPUT @Dmm;"CONF:VOLT:DC 10,0.003" ! DC, 10 V range, 3 mV resolution.
   110 OUTPUT @Dmm;"TRIG:SOUR EXT"         ! Trigger on external source.
   120 OUTPUT @Dmm;"READ?"                 ! Wait for trigger and get value.
   130 ENTER @Dmm;Volts
 

The INITiate and FETCh? commands provide the lowest level of control. To read the DMM, you configure it using other commands, and then put it in the wait-for-trigger state with INITiate. Once the DMM has triggered and taken measurements, you can retrieve them with FETCh?; the readings are buffered in internal memory, and FETCh? retrieves them one at a time.

For example:



   100 OUTPUT @Dmm;"CONF:VOLT:DC 10,0.003" ! DC, 10 V range, 3 mV resolution.
   110 OUTPUT @Dmm;"TRIG:SOUR EXT"         ! Trigger on external source.
   120 OUTPUT @Dmm;"INIT"                  ! Wait for trigger.
   130 OUTPUT @Dmm;"FETC?"                 ! Get value.
   140 ENTER @Dmm;Volts
 

This example uses the CONF command to set up the DMM. You can also use the FUNCtion, RANGe, and RESolution low-level configuration commands to perform the precise setup you need:


   100 OUTPUT @Dmm;"FUNC:VOLT:DC"          ! DC volts.
   110 OUTPUT @Dmm;"RANG 10"               ! 10 V range.
   120 OUTPUT @Dmm;"RES 0.003"             ! 3 mV resolution.
   130 OUTPUT @Dmm;"TRIG:SOUR EXT"         ! Trigger on external source.
   140 OUTPUT @Dmm;"INIT"                  ! Wait for trigger.
   150 OUTPUT @Dmm;"FETC?"                 ! Get value.
   160 ENTER @Dmm;Volts
 

There are a wide range of such low-level configuration commands, besides FUNCtion, RANGe, and RESolution:


   NPLCycles              Set number of power-line cycles for a measurement.
   FREQuency:APERture     Set aperture gate time for period measurements.
   PERiod:APERture        Set aperture gate time for period measurements.
   DETector:BANDwidth     Set filter frequency for input signal.
   ZERO:AUTO              Enable or disable autozero mode.
   INPut:IMPedance:AUTO   Enable or disable auto input resistance mode.
 

Each of these commands has a matching query. There is also a query, ROUTe:TERMinals?, to determine if the front or back input terminals are enabled.

* The five math operations are set as follows:


   CALCulate:FUNCtion NULL (default)
   CALCulate:FUNCtion DB
   CALCulate:FUNCtion DBM
   CALCulate:FUNCtion AVERage
   CALCulate:FUNCtion LIMit
 

You can query the function setting with the CALCulate;FUNCtion? query. Once the function has been set, you then have to enable it to get it to operate:


   CALCulate:STATe ON
 

You can disable the math using the OFF parameter instead of the ON parameter. You can interrogate the state with a CALCulate:STATe? query.

You set the parameters for the math operations with the commands listed below. Note that the appropriate operation must be set before setting the parameters:


   CALCulate:NULL:OFFSet
   CALCulate:DB:REFerence
   CALCulate:DBM:REFerence
   CALCulate:LIMit:LOWer
   CALCulate:LIMit:UPPer
 

You can interrogate one of these values from the DMM with the matching query. Finally, you can determine the results for those math operations that return them with:


   CALCulate:AVERage:MINimum?   Gives minimum of min-max operation.
   CALCulate:AVERage:MAXimum?   Gives maximum of min-max operation.
   CALCulate:AVERage:AVERage?   Gives average of min-max operation.
   CALCulate:AVERage:COUNt?     Gives number of values in min-max operation.
 

The following sample program shows how to use the CONFigure command with a dBm math operation:


   10  DIM Ohms(1:5)
   20  ASSIGN @Dmm TO 722
   30  CLEAR 7                            ! Clear HPIB and DMM.
   40  OUTPUT @Dmm;"*RST;*CLS"            ! Reset DMM.
   60  OUTPUT @Dmm;"CALC:DBM:REF 5.0"     ! 50 ohm reference resistance.
   70  OUTPUT @Dmm;"CONF:VOLT:AC 1,0.001" ! Set DMM to 1 amp AC range.
   80  OUTPUT @Dmm;"DET:BAND 200"         ! Select 200 Hz (fast) AC filter.
   90  OUTPUT @Dmm;"TRIG:COUN 5"          ! DMM will accept 5 triggers.
   100 OUTPUT @Dmm;"TRIG:SOUR IMM"        ! Trigger source is IMMediate.
   110 OUTPUT @Dmm;"CALC:FUNC DBM"        ! Select dBm function.
   120 OUTPUT @Dmm;"CALC:STAT ON"         ! Enable math.
   130 OUTPUT @Dmm;"READ?"                ! Get readings, put in output buffer.
   140 ENTER @Dmm; Ohms(*)
   150 PRINT USING "K,1"; Ohms(*)
   160 END
 

* The DMM's triggering capabilities were outlined in the last section. You can generate triggers either manually or automatically, take multiple readings per trigger (up to 50,000), and insert a delay before each reading. To trigger the DMM, you must perform the following steps:

  • You must configure the DMM for the measurement by selecting the function, range, resolution, and so on.
  • Then you must select the trigger source: command trigger (GET or *TRG), EXTERNAL TRIGGER input, or an immediate internal trigger.
  • Then you must make sure that the DMM is ready to accept a trigger by being placed in the wait-for-trigger state. A trigger will not be accepted until the DMM is in this state.

The triggering system is controlled by the following commands:


   INITiate              Set DMM to wait-for-trigger state.
   FETCh?                Get reading from DMM.
   READ?                 Set DMM to wait-for-trigger state, get readings.
   TRIGger:SOURce        Set trigger source.
   TRIGger:DELay         Set trigger delay.
   TRIGger:DELay:AUTO    Enable or disable automatic trigger delay.
   SAMPLe:COUNt          Set number of readings per trigger.
   TRIGger:COUNt         Set number of triggers per reading.
 

Note that all these commands except INITiate and READ? have matching queries. Note also that FETCh?, unlike READ, actually doesn't perform any triggering action, but it is closely related to INITiate, and so is included with the triggering commands.

* The DMM's system-related commands cover a grab-bag of functions, such as display control, beeper control, queries for DMM errors and status, and reset and self-test commands. They include:


   DISPlay               Turn the DMM display on or off.
   DISPlay?              Query the display state.
   DISPlay:TEXT          Display up to 12 characters on the DMM display.
   DISPlay:TEXT?         Query the display text.
   DISPlay:TEXT:CLEar    Clear the message displayed on the front panel.
   SYSTem:BEEPer         Issue a single beep immediately.
   SYSTem:BEEPer:STATe   Disable or enable a front-panel beeper.
   SYSTem:BEEPer:STATe?  Query beeper state.
   SYSTem:ERRor?         Query the DMM's error queue.
   SYSTem:VERsion?       Query the DMM for SCPI version.
   DATA:POINts?          Query the number of readings in the DMM.
   *RST                  Reset the DMM.
   *TST?                 Self-test the DMM.
   *IDN?                 Get DMM ID.
 

* The DMM's status subsystem was discussed in the last chapter. It includes the 488.2 Status Byte and Standard Event register, plus the SCPI questionable data register.

The Status Byte implements four status bits, as listed below. Note that the lowest bit is BIT 0, and that each bit is accompanied by its decimal weight:

  • BIT 3 (8) -- Questionable Data: Indicates a bit set in the Questionable Data register.
  • BIT 4 (16) -- Message Available: Indicates data available in the output queue.
  • BIT 5 (32) -- Standard Event: Indicates a bit set in the Standard Event register.
  • BIT 6 (64) -- Request Service: Indicates that the DMM has requested service.

The Status Byte is read during a controller serial poll. If the DMM has asserted SRQ, this clears the SRQ and BIT 6. It can also be read with the STB? query. In this case BIT 6 will remain set until it is cleared with a *CLS command.

The Status Byte enable register can be set with the *SRE command and read with the *SRE? query; a set bit will cause an SRQ. The enable register can only be cleared by sending *SRE 0 or by power-cycling, and even with power-cycling, the DMM must have been configured to clear that enable register with the *PSC 1 command before power-down. If *PSC 0 has been sent instead, the enable settings will be retained.

* The Standard Event register implements six status bits:

  • BIT 0 (1) -- Operation Complete: Indicates that all commands prior to and including a *OPC command have been executed.
  • BIT 2 (4) -- Query Error: Indicates that the DMM tried to read an empty output buffer; that a new command line has been sent before a previous query has been sent; or that both the input and output buffers are full.
  • BIT 3 (8) -- Device Error: Indicates that a self-test, calibration, or reading overload error occurred.
  • BIT 4 (16) -- Execution Error: Indicates that a command execution error has occurred.
  • BIT 5 (32) -- Command Error: Indicates a syntax error in a command string sent to the DMM.
  • BIT 7 (128) -- Power On: Indicates that power has been turn on and the event register has not yet been read or cleared.

The Standard Event register can be read with the *ESR? query. Note that this register cannot be written to. The Standard Event enable register is written to with the *ESE command and read with the *ESE? query, and bits set will cause an SRQ, as long as BIT 5 in the Status Byte Enable register is set.

Sending an *ESR? clears the Standard Event register. It is also cleared by the *CLS command. Similarly to the Status Byte enable register, the Standard Event enable register can only be cleared with *ESE 0 or by power-cycling (as long as *PSC 1 has been sent before power-down).

The Operation Complete flag in this register is particularly handy. Using this flag, the controller can initiate a long DMM operation, and then go do something else until the operation completes. When the DMM is done, it will assert an SRQ and interrupt the controller. The controller has to go through the following sequence of steps to implement this scheme:


   100 CLEAR @Dmm                      ! Clear DMM interface.
   110 OUTPUT @Dmm;"*CLS"              ! Clear DMM status registers.
   120 OUTPUT @Dmm;"*ESE 1"            ! Enable OPC event.
   130 OUTPUT @Dmm;"*SRE 32"           ! Enable SRQ on OPC event.
   140 OUTPUT @Dmm;"*OPC?"             ! Send dummy *OPC? to ensure synch.
   150 ENTER @Dmm;Dummy                ! Read back dummy value.
   160 ON INTR 7 GOSUB Handler         ! Set jump to handler routine on SRQ.
   170 ENABLE INTR 7;1                 ! Enable SRQ interrupt for controller.
   180 OUTPUT @DMM;"<command>; *OPC?"  ! Send command, followed by *OPC?.
 

The controller will go on and do other things; when the operation is complete, the DMM will assert an SRQ and cause a jump to the interrupt handler.

* The Questionable Data register implements five status bits:

  • BIT 0 (1) -- Voltage Overload: Indicates overrange on DC volts, AC volts, frequency, period, diode, or ratio function.
  • BIT 1 (2) -- Current Overload: Indicates overrange on DC or AC current function.
  • BIT 9 (512) -- Ohms Overload: Indicates overrange on 2-wire or 4-wire ohms test.
  • BIT 11 (2048) -- Limit Test Fail LO: Indicates that reading has gone below the lower limit in the limit test.
  • BIT 12 (4096) -- Limit Test Fail HI: Indicates that reading has gone above the upper limit in the limit test.

You can read the Questionable Data register with the STATus:QUEStionable: EVENT? query. This action clears the register. *CLS also clears this register.

The Questionable Data enable register is set with the STATus:QUEStionable: ENABle command. It can be read with the STATus:QUESTionable:ENABle? query. Bits set will cause an SRQ, as long as BIT 5 in the Status Byte Enable register is set. This enable register is always cleared by power-up. It can also be cleared by the STATus:PREset command or by setting it to 0 with STATus:QUEStionable: ENABle 0.

* The calibration commands allow you to perform a calibration of the DMM, determine how many times the DMM has been calibrated, set and query calibration codes, and set and query calibration information. The calibration commands include:


   CALibration?                Perform a calibration.
   CALibration:COUNt?          Get number of calibrations.
   CALibration:SECure:CODE     Set calibration security code.
   CALibration:SECure:STATe    Unsecure or secure for calibration.
   CALibration:SECure:STATe?   Query security state.
   CALibration:STRing          Store calibration data.
   CALibration:STRing?         Read calibration data.
   CALibration:VALue           Set value of calibration reference.
   CALibration:VALue?          Read value of calibration reference.
 

* Finally, to complete the command set, there are three RS-232-only (non-SCPI) commands that perform functions that are inherent to HPIB but not to RS-232:


   SYSTem:LOCal                Put DMM into local state.
   SYSTem:REMote               Put DMM into remote operation.
   SYSTem:RWLock               Put DMM into local lockout.
 

Note that you will not get RS-232 communications to work properly unless you send a SYSTem:REMote command after reset. not

* Error codes are not explained in this document, since a description of the error accompanies the error code returned by the instrument.

[6.3] A SIMPLE 34401 EXAMPLE PROGRAM

* The following HP BASIC example program demonstrates elementary programming techniques for the 34401. It uses a simple text-input menu system to allow you to read AC or DC volts or current, resistance, and frequency, perform test and status operations on the DMM, and clear the display and exit the program. A practical program would be more sophisticated, but this is, after all, an example.


   10    DIM S$[100],P$[100],M$[5],R$[5] ! String, prompt, mode, reply vars.
   20    REAL T                          ! Used for timeout tracking.
   30    INTEGER Sts                     ! Stores serial poll result.
   40    CLEAR SCREEN
   50    !
   60    ON TIMEOUT 7,3 GOSUB Timetrap   ! Set up timeout trap.
   70    ASSIGN @Dmm TO 722              ! Open path to DMM.
   80    ON ERROR GOSUB Errtrap          ! Set up error trap.
   90    !
   100   M$="DC"                         ! Define DC or AC operations.
   110   LOOP
   120     P$="COMMAND:  (M)ode="&M$& / (V)olts / (A)mps"
   130     DISP P$&" / (O)hms / (F)req / (C)ls / (S)ystem / (Q)uit";
   140     INPUT R$                      ! Get reply to prompt.
   150     IF R$="" THEN R$="Z"          ! Check for empty input.
   160     R$=UPC$(R$[1,1])              ! Get first character as uppercase.
   170   ! 
   180     SELECT R$                     ! Test character:
   190   ! 
   200     CASE "M"                      ! Mode:  Toggle mode between DC & AC.
   210       IF M$="DC" THEN
   220         M$="AC"
   230       ELSE
   240         M$="DC"
   250       END IF
   260   !   
   270     CASE "V"                      ! Volts:  Get AC or DC volts.
   280       DISP "Getting volts ... "
   290       IF M$="DC" THEN
   300         OUTPUT @Dmm;"MEAS:VOLT:DC?"
   310       ELSE
   320         OUTPUT @Dmm;"MEAS:VOLT:AC?"
   330       END IF
   340       ENTER @Dmm;S$
   350       PRINT "Voltage value:    ";S$
   360   !   
   370     CASE "A"                      ! Amps:  Get AC or DC amps.
   380       DISP "Getting amps ... "
   390       IF M$="DC" THEN
   400         OUTPUT @Dmm;"MEAS:CURR:DC?"
   410       ELSE
   420         OUTPUT @Dmm;"MEAS:CURR:AC?"
   430       END IF
   440       ENTER @Dmm;S$
   450       PRINT "Current value:    ";S$
   460   !   
   470     CASE "O"                      ! Ohms:  Get 2-wire resistance.
   480       DISP "Getting resistance ... "
   490       OUTPUT @Dmm;"MEAS:RES?"
   500       ENTER @Dmm;S$
   510       PRINT "Ohms value:       ";S$
   520   !   
   530     CASE "F"                      ! Freq:  Get frequency.
   540       DISP "Getting frequency ... "
   550       OUTPUT @Dmm;"MEAS:FREQ?"
   560       ENTER @Dmm;S$
   570       PRINT "Frequency value:  ";S$
   580   !
   590     CASE "C"                      ! Cls:  Clear display.
   600       CLEAR SCREEN
   610   !
   620     CASE "S"                      ! System:  Do system functions.
   630       GOSUB System
   640   !
   650     CASE "Q"                      ! Quit program.
   660       DISP "Done!"
   670       STOP
   680   !
   690     CASE ELSE                     ! Bogus input.
   700       INPUT "ERROR:  Bad command.  Press enter to continue.",R$
   710   !
   720     END SELECT
   730   END LOOP
   740   !
   750 System: !                           Perform system commands.
   760   LOOP
   770     INPUT "COMMAND:  (C)lear / (I)d / (T)est / (E)rror / (R)eturn",R$
   780     IF R$="" THEN R$="Z"          ! Test for empty input.
   790     R$=UPC$(R$[1,1])              ! Get first character as uppercase.
   800   !
   810     SELECT R$                     ! Test character:
   820   !
   830     CASE "C"                      ! Clear DMM.
   840       DISP "Clearing DMM ... "
   850       CLEAR @Dmm
   860       OUTPUT @Dmm;"*RST;*CLS"
   870       PRINT "Reset complete!"
   880   !  
   890     CASE "I"                      ! Get ID string.
   900       DISP "Getting ID ... "
   910       OUTPUT @Dmm;"*IDN?"
   920       ENTER @Dmm;S$
   930       PRINT "Dmm ID string: ";S$
   940   !  
   950     CASE "T"                      ! Self-test DMM.
   960       DISP "Testing ... "
   970       OUTPUT @Dmm;"*CLS;*ESE 1;*OPC?" ! Flag OPC when test over.
   980       ENTER @Dmm;S$
   990       OUTPUT @Dmm;"*TST?;*OPC"    ! Test, flag OPC.
   1000      T=TIMEDATE                  ! Get initial time.
   1010      LOOP
   1020        Sts=SPOLL(@Dmm)           ! Spoll for ESB (=OPC) bit.
   1030      EXIT IF BIT(Sts,5)=1
   1040      EXIT IF TIMEDATE-T>30       ! Keep checking for 30 seconds.
   1050      END LOOP
   1060      IF BIT(Sts,5)=1 THEN     
   1070        ENTER @Dmm;S$
   1080        PRINT "Test status: ";S$
   1090      ELSE
   1100        PRINT "Test timed out!"
   1110      END IF
   1120  !  
   1130    CASE "E"                      ! Get error status.
   1140      DISP "Getting error status ... "
   1150      OUTPUT @Dmm;"SYST:ERR?"
   1160      ENTER @Dmm;S$
   1170      PRINT "Error status: ";S$
   1180  !
   1190    CASE "R"                      ! Return to main.
   1200      RETURN
   1210  !  
   1220    CASE ELSE                     ! Bogus input.
   1230      INPUT "ERROR:  Bad command.  Press enter to continue.",R$
   1240  !  
   1250    END SELECT
   1260  !
   1270  END LOOP
   1280  RETURN
   1290  !
   1300 Timetrap: !                        Trap timeout error.
   1310  INPUT "ERROR:  Timeout -- press Enter to continue.",R$
   1320  ERROR RETURN
   1330  !
   1340 Errtrap: !                         Trap error.
   1350  PRINT ERRM$                     ! Print error string.
   1360  INPUT "ERROR:  Press Enter to continue.",R$
   1370  ERROR RETURN
   1380  !
   1390  END
 

[7.0] HPIB Tutor (7): Notes & Comments

* This last chapter covers a few interesting topics in HPIB not easily discussed elsewhere.



BACK TO INDEX

[7.1] BENCHMARKS

* There is an old saying that there are lies, damn lies, and statistics, to which a modern wit added "damn statistics" ("four out of five doctors recommend"), then "benchmarks". To this I add: "damn benchmarks".

Benchmarking is a confusing topic where one is given a very specific value whose real relationship to what he or she actually wants to know is no more than an approximation, subject to a number of conditions.

This is, as shall be explained, inevitable, so the important question is one of what constitutes "benchmarks" (honestly-stated information) and what constitutes "damn benchmarks" (meaningless hype), and how one can tell the difference.

* In the case of HPIB, there are a lot of benchmarks and damn benchmarks out there. Customers often want to get estimates for the performance (in kilobytes per second) they can expect to obtain for an HPIB application with a specific HPIB card. There are two types of benchmarks that need to be provided in response: "typical" performance figures, and "maximum" performance figures.

Typical performance figures are usually obtained by setting up the PC and a low-cost instrument (the HP 34401 "Alf" DMM is currently popular for this task) and then simulating a typical customer application.

This sounds simple enough, and it is, but the complexity comes in considering what information you're getting out of it. The performance of the system will depend on four factors:

  • The speed of the PC running the test. The simplest way of judging a PC's speed is the clock speed of the processor, but this can be highly misleading, since it doesn't take into consideration the fact that the processor may have a 16-bit or 32-bit data path width, different speeds of RAM, different amounts and speeds of cache -- and, more importantly, such overall system considerations as display graphics speed, hard disk speed, and whether DOS or Windows is running the test. (There are utilities available to give a figure of merit of overall PC performance, but their results are highly dependent on the assumptions used in their design.)
  • The assumptions used in writing the program to make the test, as well as the language used -- C or BASIC or whatever -- used to write the program. An unrealistic example program would simply send a command and read a value over and over again. A realistic example program would update a graphics display, store the data returned in a file, and do error and status checking, emulating a simple data-logging application.
  • The type of HPIB card used in the PC. As will be discussed momentarily, this is the least important consideration in this type of benchmark.
  • The speed at which the instrument can communicate. This is a very important consideration. HPIB is designed so that one device cannot talk faster than another device can listen (which is not true for, say, people), and of course one device cannot listen faster than the other talks (which is true for people and everything else, as imposed by simple logic).

    Note that many benchmark requests are for performance of HPIB with a specific instrument. However, in this document the issue is deriving general performance figures for the PC's HPIB card, and instrument performance, though important in itself, will not be considered further here.

In practice, such a typical benchmark says almost nothing about the performance of an HPIB card, since almost any HPIB card you could buy would be able to keep up with the actions of the system. The speed will be far more determined by the PC and the design of the program, since the data transactions over HPIB are a small part of the total. The typical benchmark is useful in that it provides a minimum value that the user can expect to obtain.

* The maximum performance benchmark is where things get more interesting. In this case, the benchmark is optimized for the maximum possible performance to provide an upper limit on HPIB card operation.

The four constraints outlined for the typical benchmark above apply in the maximum performance benchmark case as well, but with added subtleties:

  • PC operation speed is optimized. This means going into the PC's configuration files and eliminating anything that might hinder the benchmark's performance, and tweaking anything left that could be tweaked that could enhance it by, say, freeing up as much memory as possible. Hard disk drives will be defragmented, disk cache sizes will be increased, and compressed drives will not be used for the test (since the data compression algorithm will slow down data storage as compared to an uncompressed disk).

    PC configurations can vary enough so that even the same model of PC with the same options can give surprisingly different results.

  • The program itself will be optimized for raw speed. To this end, the program will be written strictly to obtain data from the instrument using the fastest possible instrument operation mode -- and in as large blocks of data as possible. It will do absolutely nothing else.

    This is not deceptive, since this particular benchmark is intended to determined maximum sustained performance, an important specification for many practical applications. For typical HPIB operation involving many small transfers of commands and data, this spec says very little. A Lamborghini is a fast car, but if it's caught in city traffic it can't go any faster than any other car.

    HPIB communications tend to increase greatly in speed as the block size of a single transfer operation increases in length. This is because telling an instrument to do something requires sending a few commands, providing a certain overhead for the transaction, and each individual HPIB operation invoked by the program has a certain overhead as well. If you have one very long transfer of data in a single HPIB operation, then as the transaction gets longer, the overhead time becomes more negligible in comparison.

    The assumptions of the program's design are important again, though what constitutes "realistic" and "unrealistic" in this case are a little more evasive.

    First, there is the question of whether the instrument is being instructed to perform a realistic operation, or is simply being told to return data even though it cannot realistically obtain data at that rate. This is usually not much of a worry if the person making the benchmark has a good grasp of the instrument.

    Second, and more important, are the issues of what is done with the data when it is returned, and how much is returned. The fastest benchmarks will throw away the data returned from the instrument, which is entirely unrealistic. More realistic benchmarks will store it in memory, and a better benchmark will store it to hard disk. (It is not practical in most cases to manipulate data as it is coming in if speed is desired, so data has to be stored and manipulated later.)

    The amount of data affects the benchmark as well, since simply getting back a one-second burst of data will give, in general, faster rates than getting back the data over a period of several minutes. If the data is stored to disk, the amount is important as well, because once disk cache is filled up the speed of disk access changes abruptly. If you don't get close to that limit, you won't have a realistic assessment of the impact of hard disk speed since the data is really being stored in RAM.

    Note that in some applications a customer may simply want to get a short burst of data and put it in memory, rather than store data on disk for several minutes, and the short-burst-to-memory benchmark -- usually about twice as fast as a sustained transfer to disk -- may be precisely what is desired.

  • The HPIB card's speed is important in a maximum-performance benchmark since it now becomes the bottleneck, and the card itself isn't all there is to it any more. The configuration of the HPIB connections made in the benchmark system also becomes important, since HPIB transfers slow down perceptibly when more and longer cables are added to the system, analogous to the fact that filling up pipes from a pump becomes slower when you have more and longer pipes to fill.

    For maximum performance, it is a reasonable assumption to insist on a single short cable to the instrument, since if the user wants to obtain maximum speed in practice that will be required.

    The use of short connections also allows further optimizations, since many HPIB cards can be reprogrammed to use faster bus timing that isn't realistic in other circumstances. Again, this isn't deceptive if a maximum performance figure is desired, but such optimizations are inapplicable for typical operation.

  • The speed of the instrument also becomes a major factor for maximum performance benchmarks; there are relatively few instruments that can operate above, say, 250 kilobytes per second, and most are below 100 kilobytes per second -- the PC's HPIB card is often faster and so is just waiting on the instrument.

    Some benchmarks are performed using dummy devices. I often use a second computer with an HPIB card as a dummy device, which is in practice pretty realistic, but sometimes specialized hardware is used to determine maximum HPIB card transfer rates. This is unrealistic, except for determining the absolute theoretical limit of the card's operation. The card will never come close to that rate in practical operation.

The maximum-performance benchmark actually does reveal true facts about the HPIB card, but it is made under constrained and specific circumstances, and except in providing an upper limit, only gives specific information when the test conditions are fully known.

Note that some vendors are promoting HPIB card with supposed enhanced-performance features. The catch is that such enhanced performance is only available under specialized circumstances (as above) and with instruments that also support the same enhanced-performance spec, and which are few in number these days. There is a need for a faster instrument interface than HPIB, but it will probably be derived from new high-speed serial buses and the like currently being implemented on PCs.

* In summary, when you ask for benchmark figures, you will need to know what you are asking for and what you can expect. What most users want to know is: "How fast can my application run?" Without implementing the application, nobody can say. All that can be done is give an estimate of limits and constraints.

Realistic benchmarks will provide both typical and maximum performance figures, with an outline of what the benchmark programs do and the necessary details, such as the type and configuration of PC, the programming language used, the instrument used in the test, and so on. Any reasonable benchmark will also clearly state that there is no guarantee that a specific application will obtain the same figures, since the specific performance only relates to the benchmark test itself.

In marketing copy, it is hard to point out these details, so you should assume that if you are given a performance figure without comment it is a maximum figure and obtained under optimum circumstances. Really impressive performance figures (some vendors quote a "megabyte per second", which is the theoretical limit to HPIB transfer rates) should be regarded with suspicion as "damn benchmarks" since they were probably put together using unrealistic assumptions.

In practice, actual performance is a system issue, and will be determined by the user's knowledge of all system elements -- PC configuration, program design, HPIB optimization, and instrument operation. A fast HPIB card counts for very little if the application is dumping data to a bottleneck like a tape drive. But having realistic benchmarks for any one element will tell you what is, and what is not, possible.

[7.2] PASS CONTROL & NON-CONTROLLER OPERATION

* Some HPIB programmers attempt to write programs that assume non-controller operation. They want to either temporarily pass control to another controller, or operate as a pure slave (talk-listen-but-not-control) device They find they run into difficulties.

While passing control is straightforward, it does require a good understanding of how the HPIB protocols (and the interface library that implements them) work. However, operation as a slave is much trickier and very difficult to implement in a reliable fashion.

This problem is compounded by the fact that many interface libraries implement pass-control or slave-operation features in a slipshod fashion, and often have not tested what they have implemented in any methodical way. For these reasons, it is strongly recommended that passing control not be done unless there is no other way to do the required task, and that slave operation be avoided if at all possible.

Nonetheless, if you are forced to deal with these matters, hear are some clues and hints. Since HP BASIC for stand-alone workstations has the most robust HPIB implmentation I know of, the discussion is purely based on HP BASIC commands. You will need to find analogous commands on your target system, though it is likely the implementation will not be anywhere near as good.

The following discussion necessarily repeats information provided in a more terse fashion in earlier chapters for the sake of coherence.

* If you have multiple controllers on the same HPIB, one will be the system controller and all the others will be non-system controllers. On traditional HP BASIC workstations, this is set with a DIP switch.

The first visible distinction between the two is this: when you power up the controllers, the system controller will come up by default operating as a controller -- that is, you will be able to communicate with instruments -- while the non-system controllers will be operating by default as slaves -- that is, they will not be able to address any devices on the HPIB.

This means that if you perform:


   OUTPUT 705;"*IDN?"
 

-- on the system controller, it will work fine (assuming that there is a device with address 705 out there on the HPIB), but if you do it with a non-system controller, you'll get an error message:


   ERROR 173  Active/system controller req'd
 

Some users set up a non-system controller, get this error message, and think it's a bug. No, it's doing what it's supposed to be doing.

Now suppose you put these two controllers on the same HPIB and wish to pass control between them. The first issue is one which is often forgotten by HPIB users: that a controller has an HPIB address, just like an instrument (the default controller address for an RMB workstation is 21), and you can't have two devices on the bus with the exact same address.

Fortunately, you can set a controller to another HPIB address by writing to HPIB status register 3:


   CONTROL 7,3;1   ! Set interface 7 to HPIB address 1.
 

I assume the HPIB is at interface select code 7, a convention that I will stick with in the rest of the discussion. I usually prefer to set the non-system controller to address 1 and leave the system controller to address 21.

Given this knowledge, it is perfectly easy to pass control from the system controller to the non-system controller with:


   PASS CONTROL 701    ! Sends TCT (Take ConTrol) byte.
 

The non-system controller can then pass it back with:


   PASS CONTROL 721
 

* Seems pretty simple, right? Well, it is simple, but not quite that simple. There's a few other details to consider. that

The first detail can be phrased as a question: how does an RMB program know if it's running on a system controller or nonsystem controller, or if it is the current active controller? Without this knowledge, the ability to pass control will lead quickly to mutual confusion within the programs on the two systems.

This is pretty straightforward, with that information provided by status register 3. Bit 7 says if the controller is a system controller (1) or non-system controller (0) and bit 6 says if the controller is the active controller (1) or inactive controller (0):


   STATUS 7,2;Sts
   IF BIT(Sts,7)=1 THEN
     PRINT "System controller."
   ELSE
     PRINT "Non-system controller."
   END IF
   IF BIT(Sts,6)=1 THEN
     PRINT "Active controller."
   ELSE
     PRINT "Inactive controller."
   END IF
 

Note that the five lowest bits of status register 3 also give the HPIB address of the controller:


   PRINT "HPIB Address =";BINAND(Sts,31)  ! Print lowest five bits.
 

Anyway, this status is essential for avoiding confusion in controller-noncontroller operation.

* The second detail concerns the actual protocol for passing control. To be sure, if one controller passes control to a second controller, the second controller becomes active controller without any further trouble, but usually the inactive controller is the one driving the process, since it wants to do something and the active controller is in the way.

So the inactive controller can assert an SRQ -- service request -- using the REQUEST statement to ask the active controller to pass control:


   REQUEST 7,64
 

Note that only the interface select code is specified. Naturally, since all this does is assert the SRQ line and make a serial poll response byte (here given as 64) available. A value of 64 sets bit 6, which indicates a service request. Setting any other bits is optional.

The active controller will then perform serial polls to see who asserted the SRQ. If it's the inactive controller, it then passes control:


   STATUS 7,7;Sts                
   IF BIT(Sts,10)=1 THEN    ! SRQ bit is bit 10 of HPIB status 7.
     Sts=SPOLL(701)         ! Serial poll inactive controller.
     IF BIT(Sts,6)=1 THEN   ! If SRQ bit set, then pass control.
       PASS CONTROL 701
     END IF
   END IF
 

This code sample assumes operation on the system controller. Note that this sample actually checks the SRQ bit in status register 7 to see if an SRQ has happened. In reality, it may be easier to do it using an interrupt:


   ON INTR 7 GOSUB Srqtrap    ! Set up jump.
   ENABLE INTR 7,2            ! Specify SRQ interrupt.
   ...
 Srqtrap: !
   Sts=SPOLL(701)
   IF BIT(Sts,6)=1 THEN
     PASS CONTROL 701
   END IF
   RETURN
 

* The third detail is that the system controller can, unlike all the other controllers on the same HPIB, get control back any time it wants it, by executing the command ABORT, which asserts IFC (interface clear) and restores all the interfaces to their default state.

* The distinction between the concepts of system controller and active controller should be clearly described by the discussion so far, but since this is a confusing issue let me summarize it.

There can be multiple controllers on a single HPIB connection. Any of them can be active controller if control is passed to them. There is, however, only one system controller. It comes up as active controller on boot-up (the non-system controllers are inactive on boot-up), and it can take control back from any other controller by executing ABORT.

The system controller is not necessarily the active controller. The active controller can jump from controller to controller as control is passed over the bus. But it is always the system controller, and it is the only system controller.

* This explains about all there is to know about passing control in itself, with the exception of one final detail: why do it?

The only good reason that I know for passing control is that instruments often have the capability to dump a plot to a plotter or printer on the same HPIB. Some of the older instruments will demand to be made system controller for this operation. The program sends it a command to print, passes control to it, then wait for it to pass control back.

However, it is a common misconception that this is the only way to perform this task. The logic is that the instrument is talking to the printer or plotter, and of course it has to be a controller to do that, right?

No, not really. A controller can set up one device as a talker and another as a listener, and then the two can talk to each other without controller intervention. Assuming an instrument at address 713 and a printer at address 705, most instruments that have the capability to dump directly to a printer could be instructed to do so with something like this:


   OUTPUT 713;"PRINT?"
   SEND 7;UNT UNL TALK 713 LISTEN 705 DATA ""
 

The SEND command sends HPIB command bytes, setting up the talker-listener transaction (the DATA "" at the end releases the ATN line, allowing the transaction to proceed).

Of course, if the instrument understands the 488.2 OPC? (operation complete) query, the program can also instruct it to assert an SRQ when it is done with the print operation. However, that is a little beyond the scope of this discussion.

* So passing control can be done easily, but in general it's not all that useful. What is not so easy to do is try to write an RMB program that operates completely in noncontroller mode -- that is, just like an instrument on the HPIB, its operations directed by the controller.

Using an HPIB controller is easy. It tells the other devices what to do whenever it pleases, and they have to respond accordingly. For this reason, being an HPIB slave is hard. It has to respond whenever required, with the information the controller expects to get back.

This normally means that you have to set up an interrupt in the noncontroller so it can respond when needed. The most useful interrupt for this purpose is the "talker-listener address change" (TLAC) flag associated with the interface, which is asserted any time the slave is addressed. An interrupt on TLAC can be set up as follows:


   ON INTR 7 GOSUB Tlacintr
   ENABLE INTR 7;256
 

When the slave gets the TLAC interrupt, it can then check to see if it is addresses to talk or listen and respond accordingly:


 Tlacintr: !
   STATUS 7,6;Sts
   IF BIT(Sts,10)=1 THEN       ! Addressed to listen (LADS).
     ENTER 7;S$                ! Get a command (I/O is from interface).
     ELSE
     IF BIT(Sts,9)=1 THEN      ! Addressed to talk (TADS)
       SELECT S$
       CASE "*IDN?"
	 OUTPUT 7;Addrstr$     
         ...
       END SELECT
     END IF
   END IF
 

Note that status register 6 contains the listen-addressed (LADS) bit (bit 10) and the talk-addressed (TADS) bit (bit 9), and that the ENTERs and OUTPUTs have to be from the interface (remember, only a controller has addressing privileges).

This is a pretty rough outline of what needs to be done, however. The slave must actually be able to respond precisely to whatever the controller asks of it using the list of CASE statments above. The protocol for doing this has to be agreed-on by the controller and slave.

This is not too hard if the controller just sends a command and the slave makes a response. The slave's operation would look something like this:


   get TLAC interrupt
   slave is listen addressed
   get and check command
   go back to wait on TLAC interrupt

   get TLAC interrupt
   slave is talk addressed
   provide proper output for command
   go back and wait on TLAC interrupt
 

The slave has to do a lot of error checking, however. If anything goes wrong, it needs to issue an error and then go back and wait for the controller to issue a new command it understands.

Where this gets really tricky is when you want to transfer, say, a file of indeterminate length between the controller and slave. Once the slave has been given the command to send a file and is then addressed to talk, it then must sit in a loop and send the file line by line and assume the controller is reading it, since the slave remains in talk mode until otherwise instructed. On the last line, the slave needs to assert EOI with the last byte to tell the controller that the transmission is over. Similar comments apply to transferring a file from the controller to the slave.

This may sound straightforward, but in practice it can be a real nuisance to get to work. RS-232, which is a peer-to-peer system, for once works better than HPIB.

In summary, once more: you don't want to try to do things like this if you have any choice in the matter. Under RMB it is tricky. Under other applications and interface libraries, it may be completely impossible.


doc/linux-gpib.sgml000066400000000000000000006375671507046215500146220ustar00rootroot00000000000000 ]>
linux-gpib &version Linux-GPIB &version Documentation Frank Mori Hess
fmhess@users.sourceforge.net
Dave Penkler
dpenkler@gmail.com
2003-2006, 2008 Frank Mori Hess
Copying Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Alternatively, you may redistribute and/or modify this document under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Introduction The linux-gpib package is a set of software that supports programmatic access to IEEE-488 General Purpose Interface Bus compliant devices and instruments via a number of supported boards. Boards are adapters or interface cards that permit a computer to be connected to a GPIB bus. Typical instruments are test and measurement instruments such as signal generators, volt meters, oscilloscopes and spectrum analysers. There are also GPIB capable devices such as printers, plotters and digitizing tablets. The linux-gpib package is comprised of 2 parts: user part and kernel part. The user part contains The administration program gpib_config. A sample configuration file gpib.conf. Automatic udev configuration scripts for usb adapter boards. User library and header files. Bindings for various languages such as guile, perl, python and tcl. Example programmes and documentation. The kernel part contains the drivers for the different supported boards. See Supported Hardware. The kernel part is provided for installations that do not have built-in kernel support for the drivers. An IEEE-488 compliant board can drive a GPIB bus with up to 15 devices attached. Each device on the bus, as well as the board connected to it, must be assigned a unique primary address ranging from 0 to 30. GPIB addresses of devices or instruments are assigned by setting DIP switches or via the front panel. The GPIB address of boards are assigned via software configuration (see Configuration). Some boards also support secondary addressing. This feature is very rarely needed. The software supports the use of multiple boards in one system. Some boards can also function as devices. Each board is assigned an identifier called a minor by which it is referenced in the sotfware functions. Devices are referenced programmatically by a device descriptor which is obtained with the ibdev() function by specifying the minor of the board of the bus to which they are connected. Board descriptors and device descriptors can also be obtained with the ibfind() function by specifying their name as defined in the configuration file. The minor can also be used directly as a board descriptor. Board descriptors are only needed in advanced applications requiring fine control over the bus such as emulating a device or managing the bus state. When using a device descriptor for I/O the library automatically handles the low level functions such as configuring the device to talk or listen on the bus. Here is simple programme to read the identification string of a device. The descriptor is obtained with ibfind() by the name voltmeter defined in the configuration file. Error handling has been omitted for clarity. #include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdint.h> #include <gpib/gpib_user.h> #include <gpib/ib.h> int main() { int ud; /* descriptor for the device */ char *id = "*IDN?\n"; /* string to request id of device */ uint8_t buf[256]; /* buffer for response */ ud = ibfind("voltmeter"); /* obtain descriptor by name */ ibwrt(ud, id, strlen(id)); /* send request-id string */ ibrd(ud, buf, 256); /* read response */ buf[ibcnt] = 0; /* null terminate the response */ printf("Device id: %s\n", buf); return 0; } Here is the same programme using ibdev() to access a device with a primary GPIB address of 7 attached to the bus connected to a board configured with minor 0. This provides more control over the parameters or defaults in the configuration file if present. #include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdint.h> #include <gpib/gpib_user.h> #include <gpib/ib.h> int main() { int minor = 0; /* minor of board */ int pad = 7; /* primary GPIB address of device */ int sad = 0; /* no secondary address */ int timeout = T300ms; /* set timeout to 300 millseconds */ int eoi = 1; /* send EOI with last byte */ int eos = 0; /* no end of string character */ int ud; /* descriptor for the device */ char *id = "*IDN?\n"; /* string to request id of device */ uint8_t buf[256]; /* buffer for response */ ud = ibdev(minor, pad, sad, /* obtain device descriptor */ timeout, eoi, eos); ibwrt(ud, id, strlen(id)); /* send request-id string */ ibrd(ud, buf, 256); /* read response */ buf[ibcnt] = 0; /* null terminate the response */ printf("Device id: %s\n", buf); return 0; }
Configuration Configuration of the GPIB library is accomplished through the configuration file gpib.conf, and the administration program gpib_config. gpib.conf 5 gpib.conf GPIB library configuration file Description The library, and the administration tool gpib_config read their configuration information from the file gpib.conf. By default, the file is located in the sysconfdir directory configured when linux-gpib was compiled. The sysconfdir is typically set to /etc or /usr/local/etc. A template gpib.conf file can be found in the util/templates/ subdirectory of the linux-gpib package. The default config file may be overridden by setting the IB_CONFIG environment variable to a custom file path. The configuration file must contain one 'interface' entry for each of the board minors that are going to be used unless all the 'required' options are specified in the command-line invocation of the administration tool gpib_config to configure that minor. The file must contain an 'interface' entry with the 'name' option set if you wish to open the board desciptor with ibfind() instead of directly using the minor as the board descriptor. If there is no entry for the minor in the configuration file, the required command-line options are 'board_type' and 'pad'. Additionally the '--system-controller' option must be scpecified if the board is to be system-controller, which is the normal case. For example: gpib_config --minor 8 --board-type ni_usb_b --pad 0 --system-controller The configuration file can contain zero or more 'device' entries. 'device' entries are only required if you wish to open device descriptors with ibfind() instead of using ibdev(). Each 'device' entry must have at least the 'minor', 'pad' and 'name' options specified. The 'minor' of a 'device' entry must have a corresponding 'interface' entry. Several example entries, and a table summarizing the possible options follow. /* This comment style is permitted */ // This is an alternate comment style interface { minor = 0 board_type = "ni_pci" pad = 0 master = yes } interface { minor = 1 board_type = "ines_pci" name = "joe" pad = 5 sad = 0 timeout = T10s pci_bus = 0 pci_slot = 0xd master = no } interface { minor = 2 board_type = "pcII" pad = 3 sad = 0x62 eos = 0x0d set-reos = yes set-bin = no set-xeos = no set-eot = yes base = 0x300 irq = 5 dma = 0 master = no } device { minor = 0 name = "counter" // name that can be used with ibfind pad = 24 } device { minor = 0 name = "voltmeter" pad = 7 sad = 110 eos = 0xa set-reos = yes set-bin = no set-xeos = yes set-eot = no timeout = T1s } configuration options option name description used by interface or device entries required or optional base Specifies the base ioport or io memory address for a board that lacks plug-and-play capability. interface optional board_type Specifies the type of interface board. See the last two columns of Table 2. for a list of possible board types, and the kernel driver module that supports them. There is no default. interface required dma Specifies the dma channel for a board that lacks plug-and-play capability. interface optional eos Sets the end-of-string byte for board or device descriptors obtained with ibfind(). By default eos = 0. See also the set-reos, set-bin, and set-xeos options. interface or device optional irq Specifies the interrupt level for a board that lacks plug-and-play capability. interface optional master Set to 'yes' if you want the interface board to be the system controller of the bus. There can only be one system controller on a bus. By default master = no. interface required minor 'minor' specifies the minor number of the device file this interface board will use. A 'minor' of 0 corresponds to /dev/gpib0, 1 is /dev/gpib1, etc. The minor number is also equal to the 'board index' which can be used as a board descriptor, and is passed as the first argument of ibdev() interface required name The 'name' specifies the name which can be used with ibfind() to get a descriptor for the board or device associated with this entry. interface or device interface optional device required pad Specifies the primary GPIB address (valid addresses are 0 to 30). For interfaces, this is the primary address that the board will be assigned when it is first brought online. For devices, this is address that will be used by device descriptors obtained with ibfind(). No default. interface or device required pci_bus Useful for distinguishing between multiple PCI cards. If you have more than one PCI card that with the same 'board_type', you can use the 'pci_bus' and 'pci_slot' options to specify the particular card you are interested in. interface optional pci_slot Can be used in conjunction with 'pci_bus' to specify a particular pci card. interface optional sad Specifies the secondary GPIB address. Valid values are 0, or 0x60 to 0x7f hexadecimal (96 to 127 decimal). A value of 0 means secondary addressing is disabled (the default). Secondary addresses from 0 to 31 are specified by the library's convention of adding an offset of 0x60. interface or device optional set-bin Enables 8-bit comparisons when matching the end-of-string byte, instead of only comparing the 7 least significant bits. Only affects descriptors returned by ibfind(), and has same effect as setting the BIN bit in a ibeos() call. Default is set-bin = 0. interface or device optional set-eot Enables assertion of the EOI line at the end of writes, for descriptors returned by ibfind(). See ibeot(). Default set-eoi = yes. interface or device optional set-reos Enables the termination of reads on reception of the end-of-string byte for descriptors returned by ibfind(). Same as setting the REOS bit in a ibeos() call. Default is set-reos = no. interface or device optional set-xeos Enables the assertion of EOI on transmission of the end-of-string byte for descriptors returned by ibfind(). Same as setting the XEOS bit in a ibeos() call. Default is set-xeos = no. interface or device optional sysfs_device_path A string which may be used to select a particular piece of hardware by its sysfs device path. interface optional timeout Sets the io timeout for a board or device descriptor opened through ibfind(). The possible settings are the same as the constants used by ibtmo(). Default is timeout = T3s , which is 3 seconds. interface or device optional
gpib_config 8 gpib_config GPIB administration program gpib_config --minor number gpib_config --board-type board_type --device-file file_path --dma number --file file_path --help --iobase number --ifc --no-ifc --init-data file_path --irq number --minor number --offline --pad number --pci-bus number --pci-slot number --sad number --serial-number serial_number --sre --no-sre --sysfs-device-path sysfs_device_path --system-controller --no-system-controller --version Description gpib_config must be run after the kernel driver module for a GPIB interface board is loaded. It performs configuration of driver settings that cannot be performed by libgpib at runtime. This includes configuration which requires root privilege (for example, setting the base address or irq of a board), and configuration which should only be performed once and not automatically redone every time a program using libgpib is run (for example, setting the board's GPIB address). The board to be configured by gpib_config is selected by the option. By default, the board settings are read from the gpib.conf configuration file. However, individual settings can be overiden by use of command-line options (see below). Options Set board type to board_type. Specify character device file path for the board. This can be used as an alternative to the --minor option. Specify isa dma channel number for boards without plug-and-play cabability. Specify file path for configuration file. The values in the configuration file will be used as defaults for unspecified options for the minor being configured. If this option is not specified, then the value of the IB_CONFIG environment variable will be used if it is set. Otherwise, the default configuration file is "sysconfdir/gpib.conf" where sysconfdir is specified when the library is configured before compilation (it is usually /etc or /usr/local/etc). Note: The configuration file read by the library is not affected by this option. It will either use the value of the IB_CONFIG environment variable, if it is set, or the default configuration file. The configuration file read by the library is used to resolve the 'name' in ibfind() calls. Print help on options and exit. Upload binary initialization data (firmware) from file_path to board. Perform (or not) interface clear after bringing board online. Default is . Set io base address to number for boards without plug-and-play cabability. Specify irq line number for boards without plug-and-play cabability. Configure gpib device file with minor number number (default is 0). Unconfigure an already configured board, don't bring board online. Specify primary gpib address. number should be in the range 0 through 30. Specify pci bus number to select a specific pci board. If used, you must also specify the pci slot with . Specify pci slot number to select a specific pci board. If used, you must also specify the pci bus with . Specify secondary gpib address. number should be 0 (disabled) or in the range 96 through 127 (0x60 through 0x7f hexadecimal). Assert (or not) remote enable line after bringing board online. Default is . Select a specific board to attach by its sysfs device path. The sysfs device path is the absolute path to the device's directory under /sys/devices, with the leading "/sys" stripped off. The device path is available in udev scripts as the DEVPATH variable. Configure board as system controller (or not). Prints the current linux-gpib version and exits.
Supported Hardware
Supported Hardware Matrix Linux-GPIB Supported Hardware Matrix make model kernel driver module board_type (for gpib.conf) Agilent (HP) 82341C hp_82341.ko hp_82341 Agilent (HP) 82341D hp_82341.ko hp_82341 Agilent (HP) 82350A agilent_82350b.ko agilent_82350b Agilent 82350B agilent_82350b.ko agilent_82350b Agilent 82351A agilent_82350b.ko agilent_82350b Agilent 82357A agilent_82357a.ko agilent_82357a Agilent 82357B agilent_82357a.ko agilent_82357a Beiming Technologies F82357 agilent_82357a.ko agilent_82357a Beiming Technologies S82357 agilent_82357a.ko agilent_82357a Capital Equipment Corporation PC-488 pc2_gpib.ko pcII Capital Equipment Corporation PCI-488 cec_gpib.ko cec_pci Capital Equipment Corporation CEC-488 tnt4882.ko ni_pci CONTEC GP-IB(PC) pc2_gpib.ko pcIIa Frank Mori Hess fmh_gpib_core fmh_gpib.ko fmh_gpib, fmh_gpib_unaccel Hameg HO80 pc2_gpib.ko pcII Hameg HO80-2 ines_gpib.ko ines_isa Hewlett Packard HP82335 hp82335.ko hp82335 Hewlett Packard HP27209 hp82335.ko hp82335 Ines GPIB-HS-NT ines_gpib.ko ines_isa Ines GPIB for Compact PCI ines_gpib.ko ines_pci, ines_pci_unaccel Ines GPIB for PCI ines_gpib.ko ines_pci, ines_pci_unaccel Ines GPIB for PCMCIA ines_gpib.ko ines_pcmcia, ines_pcmcia_unaccel Ines GPIB PC/104 ines_gpib.ko ines_isa Iotech GP488B pc2_gpib.ko pcIIa Keithley KPCI-488 cec_gpib.ko cec_pci Keithley KUSB-488 ni_usb_gpib.ko ni_usb_b Keithley KUSB-488A ni_usb_gpib.ko ni_usb_b Keithley MBC-488 pc2_gpib.ko pcII Keysight (Agilent) 82350B PCI agilent_82350b.ko agilent_82350b Keysight (Agilent) 82351A PCIe agilent_82350b.ko agilent_82350b Keysight (Agilent) 82357B USB agilent_82357a.ko agilent_82357a Measurement Computing (Computer Boards) CPCI-GPIB cb7210.ko cbi_pci, cbi_pci_unaccel Measurement Computing (Computer Boards) ISA-GPIB cb7210.ko cbi_isa, cbi_isa_unaccel Measurement Computing (Computer Boards) ISA-GPIB/LC cb7210.ko cbi_isa_unaccel Measurement Computing (Computer Boards) ISA-GPIB-PC2A pc2_gpib.ko pcIIa (nec7210 chip), pcIIa_cb7210 (cb7210 chip) Measurement Computing (Computer Boards) PCI-GPIB/1M cb7210.ko cbi_pci, cbi_pci_unaccel Measurement Computing (Computer Boards) PCI-GPIB/300K cb7210.ko cbi_pci_unaccel Measurement Computing (Computer Boards) PCMCIA-GPIB cb7210.ko cbi_pcmcia, cbi_pcmcia_unaccel Measurement Computing (Computer Boards) USB-488 ni_usb_gpib.ko ni_usb_b National Instruments AT-GPIB (with NAT4882 chip) tnt4882.ko ni_nat4882_isa, ni_nat4882_isa_accel National Instruments AT-GPIB (with NEC7210 chip) tnt4882.ko ni_nec_isa, ni_nec_isa_accel National Instruments AT-GPIB/TNT tnt4882.ko ni_isa, ni_isa_accel National Instruments GPIB-USB-B ni_usb_gpib.ko ni_usb_b National Instruments GPIB-USB-HS ni_usb_gpib.ko ni_usb_b National Instruments GPIB-USB-HS+ ni_usb_gpib.ko ni_usb_b National Instruments PCI-GPIB tnt4882.ko ni_pci National Instruments PCIe-GPIB tnt4882.ko ni_pci National Instruments PCI-GPIB+ tnt4882.ko ni_pci National Instruments PCM-GPIB tnt4882.ko ni_pci National Instruments PXI-GPIB tnt4882.ko ni_pci National Instruments PCII pc2_gpib.ko pcII National Instruments PCIIa pc2_gpib.ko pcIIa National Instruments PCII/IIa pc2_gpib.ko pcII or pcII_IIa (depending on board switch) National Instruments PCMCIA-GPIB tnt4882.ko ni_pcmcia, ni_pcmcia_accel lpvo self-made adapter lpvo self-made lpvo_usb_gpib.ko lpvo_usb_gpib GPIO bitbang GPIO gpib_bitbang.ko gpib_bitbang Quancom PCIGPIB-1 ines_gpib.ko (Ines iGPIB 72010 chip) or cb7210.ko (Measurement Computing cb7210 chip) ines_pci or ines_pci_unaccel (Ines iGPIB 72010 chip), cbi_pci_unaccel (Measurement Computing cb7210 chip) xyphro UsbGpib xyphro_ugc.ko xyphro_ugc
Board-Specific Notes
Agilent (HP) 82341 After power-up, the Agilent 82341 boards require a firmware upload before they can be used. This can be accomplished using the "--init-data" option of gpib_config. The firmware data for the boards can be found at this repository. Note the C and D versions use different firmware data. If you specify a non-zero base address in gpib.conf, the driver will assume you are trying to configure a 82341C. Otherwise, the driver will use the kernel's ISAPNP support to attempt to configure an 82341D. The 82341 does not support detection of an end-of-string character in hardware, it only automatically detects the when the EOI line is asserted. Thus if you use the REOS flag for a read, the board's fifos will not be used for the transfer. This will greatly reduce the maximum transfer rate for your board (which may or may not be noticeable depending on the device you are talking to).
Agilent 82350A/B and 82351A The Agilent 82350A/B and 82351A boards do not support detection of an end-of-string character during reads in hardware, they can only detect assertion of the EOI line. Thus if you use the REOS flag for a read, the boards' fifos will not be used for the transfer. This will greatly reduce the maximum transfer rate for your board (which may or may not be noticeable depending on the device you are talking to). After power-up, the 82350A boards require a firmware upload before they can be used. This can be accomplished using the "--init-data" option of gpib_config. The firmware data for the 82350A can be found at this repository. The 82350B and 82351A do not require a firmware upload.
Agilent 82357A/B The Agilent 82357A and 82357B require a firmware upload (before gpib_config is run) to become functional after being plugged in. The linux-gpib tarball contains udev rules for automatically running the fxload program to upload the firmware (and to run gpib_config after the firmware is uploaded). However, the actual firmware data itself must be obtained seperately. It can be found at this repository. The 82357A/B have a few limitation due to their firmware code: They cannot be run as a device, but must be the system controller. They cannot be assigned a secondary address. They cannot do 7 bit compares when looking for an end-of-string character (they always compare all 8 bits).
Beiming F/S82357 Linux-gpib support requires a minimum firmware version of 1.10 for the F82357 and version 1.20 for the S82357. These devices have on-board firmware and do not require a firmware upload before becoming functional afer plug-in. The on-board firmware can be re-flashed; contact the manufacturer for firmware and re-flash procedure. Limitations: These devices can only be used as system controllers. They can only do 8-bit end-of-string (EOS) compares.
fmh_gpib_core fmh_gpib_core is a GPIB chip written in VHDL suitable for programming into a FPGA. The code for the chip may be found at https://github.com/fmhess/fmh_gpib_core. It supports a cb7210.2 style register interface with some extensions. More specifically, the driver is for the hardware layout specified in src/example/fmh_gpib_top.vhd file in the fmh_gpib_core repository. The driver obtains its hardware information (base addresses, interrupt, dma, etc.) from the device tree. It expects to find two i/o memory resources, an interrupt, and a dma channel. One i/o memory resource is called "gpib_control_status" which contains the 8 bit cb7210.2 registers. The other i/o memory resource is called "dma_fifos" and contains 16 bit registers for the fifos and transfer counter. The dma channel the chip is wired to is specified with the standard "dmas" and "dma-names" fields, with a dma-name of "rxtx". So, the device tree entry for a chip connected to channel 2 of dma controller "dmac" might look something like: fmh_gpib_0: fmh_gpib@0x00049800 { compatible = "fmhess,fmh_gpib_core"; reg = < 0x00049600 0x00000080 0x00049800 0x00000008 >; reg-names = "gpib_control_status", "dma_fifos"; interrupt-parent = < &intc >; interrupts = < 0 57 4 >; dmas = < &dmac 2 >; dma-names = "rxtx"; }; //end fmh_gpib@0x00049800 (fmh_gpib_0)
Self-made usb-gpib adapter This usb-gpib adapter can be assembled following the project from the Laboratory of Photovoltaics and Optoelectronics at the Faculty of Electrical Engineering, University of Ljubljana. It is available at http://lpvo.fe.uni-lj.si/gpib . The adapter allows the control of GPIB devices with some limitations: it can only be the system controller; multicontroller and device operations are not supported (as yet). The linux-gpib driver 'lpvo_usb_gpib', written at the Department of Physics of University of Florence (Italy), is currently under development. It offers basic capabilities like ibrd(), ibwrt(), WaitSRQ() and others. Requests for unsupported features are flagged by a diagnostic message to syslog.
GPIO bitbang adapter This is a simple GPIO bitbang driver that currently only works on Raspberry Pi platforms. It has the following limitations: It cannot be run as a device, but must be the system controller. If the SN7516x driver chips are not used the fan out is limited to a maximum of 4 devices. Parallel poll is not supported. Setting T1 delay (ibconfig(board, IbcTIMING, T1_delay)) is not implemented. The high interrupt latency on the RPi platforms with Linux does not permit to ensure even a 2 microsecond T1 delay. Three pin maps between gpio and gpib are currently supported: "elektronomikon", "gpib4pi-1.1" and "yoga". The pin_maps are configured via the pin_map module parameter. By default support for the elekronomikon pin_map with SN75160/161 driver IC's is enabled. i.e. the default module parameter settings are pin_map=elektonomikon and sn7516x_used=1. To disable support for the SN75160/161 IC's when they are not installed the module parameter sn7516x_used must be set to zero: modprobe gpib_bitbang sn7516x_used=0 For schematics, boards and information on driver IC's see elektronomikon This is the default pinmap. The activity led on the adapter is enabled. gpib4pi-1.1 To set the pin_map for the Lightside instruments gpib4pi-1.1 board modprobe gpib_bitbang pin_map="gpib4pi-1.1" The activity led on the adapter is enabled. yoga To set the pin_map for the yoga board modprobe gpib_bitbang pin_map="yoga" For the yoga board the sn7516x_used option is ignored. The status led on the adapter is enabled as the activity led.
xyphro compact usb to GPIB adapter This driver is experimental. The standard adapter as shipped uses the normal linux usbtmc driver. Special firmware is required for this device to work with the linux-gpib driver. The project page has information on the hardware and the link for the firmware binary for the linux-gpib firmware. In order to flash the linux-gpib firmware, dowload the LinuxGpib.bin file (in the SW/binaries directory). With the adapter plugged in to a usb port press the reset button for about 5 secs. The device will then enumerate as a usb mass storage device. If you don't have an automounter enabled mount the device (in this case /dev/sda, see the output of dmesg for the appropriate dev): # mkdir -p /mnt/usbgpib # mount /dev/sda /mnt/usbgpib Then execute the following commmand (possibly replacing usbgpib with the automounted directory): # dd if=LinuxGpib.bin of=/mnt/usbgpib/FLASH.BIN bs=512 conv=notrunc \ oflag=direct,sync You can always reflash the standard usbtmc firmware if required. After disconnecting and reconnecting the adapter on the usb side you can verify whether the operation of flashing the LinuxGpib firmware was successful by checking the output of: $ lsusb -d 03eb: -v To see whether bInterfaceClass = 255 Vendor Specific Class In which case you are all set to use the adapter with linux-gpib.
National Instruments GPIB-USB-B The USB-B requires a firmware upload (before gpib_config is run) to become functional after being plugged in. The linux-gpib tarball contains udev rules for automatically running the fxload program to upload the firmware (and to run gpib_config after the firmware is uploaded). However, the actual firmware must be obtained separately. It can be found at this repository.
National Instruments GPIB-USB-HS and GPIP-USB-HS+ Unlike the USB-B, the USB-HS does not require a firmware upload to become functional after being plugged in. Most GPIB-USB-HS+ also do not require firmware upload, however some exceptions have been identified. If your GPIB-USB-HS+ initially comes up with a USB product id of 0x761e it will require a one-time firmware upload which permanently changes the product id to the usual 0x7618 for a GPIB-USB-HS+. Currently this can be done by plugging the adapter into a Windows computer which has the NI driver software installed. Alternatively, you may use the hsplus_load utility to initialize the adapter under Linux. The linux-gpib tarball contains udev rules which will automatically run gpib_config after the device is plugged in. Beware of inexpensive NI GPIB-USB-HS clones. While they work on Windows most will not and cannot be made to work with linux-gpib. See this post on bug ticket #82.
GPIB utility programme ibterm 1 Linux-GPIB User Manual ibterm Interactive GPIB terminal ibterm -d primary_address -m minor -s secondary_address -i eoi -e eos -r reos -b bin -x xeos -t timeout -p prompt -f history_file -N -X -h Description An interactive terminal program for sending commands to a device over an IEEE-488 general purpose instrument bus and printing the responses. Options address Sets the device's primary address (pad). The address must be between and . number Specify the minor number of the device file this interface board will use. A number of corresponds to /dev/gpib0, is /dev/gpib1, etc. Defaults to . address Sets the device's secondary address (sad). The address must be (disabled) or between and (0x60 and 0x7e hexadecimal). Defaults to . 0|1 Assert EIO with last byte sent. Defaults to (true). code ASCII code of end-of-string (eos) character. The code must be between and . Defaults to (no code). 0|1 Terminate read on eos character (reos) flag. Defaults to (false). 0|1 Binary eos character match mode (bin) flag. Defaults to (false). 0|1 Assert EOI when transmitting eos (xeos) flag. Defaults to (false). timeout Sets the IO timeout for the device. The timeout must be a value from the below table. The default value is , corresponding to 300 milliseconds. timeout Length Never timeout 10 microseconds 30 microseconds 100 microseconds 300 microseconds 1 millisecond 3 milliseconds 10 milliseconds 30 milliseconds 100 milliseconds 300 milliseconds 1 second 3 seconds 10 seconds 30 seconds 100 seconds 300 seconds 1000 seconds string Sets the prompt. Defaults to ibterm> string Send Untalk/Unlisten after each read and write file Command history file. Defaults to .ibterm_hist_<primary_address> No automatic read on device, enter return at prompt to read. Force hexadecimal output. Print help and exit. Notes To quit the program enter the EOF character ( Ctrl D ) at the prompt. For interactivity, timeout should not be greater than i.e. 10 secs. A device read can always be triggered by hitting enter at the prompt. Interrupting the program while reading from the device may cause hangs. Implementation details The program is implemented as follows: loop: Print prompt to stdout Read a line of text from stdin Write the text (if any) to the device at pad If is not set, or no text was entered: Attempt to read response from the device If no response is received before timeout: go to loop else: print the response on stdout Go back to loop. See also See the readline3 man page for editing input and searching history.
Linux-GPIB Reference Reference for libgpib functions, macros, and constants.
Global Variables ibcnt 3 ibcnt hold number of bytes transferred, or errno #include <gpib/ib.h> volatile int ibcnt; volatile long ibcntl; Description ibcnt and ibcntl are set after IO operations to the the the number of bytes sent or received. They are also set to the value of errno after EDVR or EFSO errors. If you wish to avoid using a global variable, you may instead use ThreadIbcnt() or ThreadIbcntl() which return thread-specific values. iberr 3 iberr holds error code #include <gpib/ib.h> volatile int iberr; Description iberr is set whenever a function from the 'traditional' or 'multidevice' API fails with an error. The meaning of each possible value of iberr is summarized in the following table: iberr error codes constant value meaning EDVR 0 A system call has failed. ibcnt/ibcntl will be set to the value of errno. ECIC 1 Your interface board needs to be controller-in-charge, but is not. ENOL 2 You have attempted to write data or command bytes, but there are no listeners currently addressed. EADR 3 The interface board has failed to address itself properly before starting an io operation. EARG 4 One or more arguments to the function call were invalid. ESAC 5 The interface board needs to be system controller, but is not. EABO 6 A read or write of data bytes has been aborted, possibly due to a timeout or reception of a device clear command. ENEB 7 The GPIB interface board does not exist, its driver is not loaded, or it is not configured properly. EDMA 8 Not used (DMA error), included for compatibility purposes. EOIP 10 Function call can not proceed due to an asynchronous IO operation (ibrda(), ibwrta(), or ibcmda()) in progress. ECAP 11 Incapable of executing function call, due the GPIB board lacking the capability, or the capability being disabled in software. EFSO 12 File system error. ibcnt/ibcntl will be set to the value of errno. EBUS 14 An attempt to write command bytes to the bus has timed out. ESTB 15 One or more serial poll status bytes have been lost. This can occur due to too many status bytes accumulating (through automatic serial polling) without being read. ESRQ 16 The serial poll request service line is stuck on. This can occur if a physical device on the bus requests service, but its GPIB address has not been opened (via ibdev() for example) by any process. Thus the automatic serial polling routines are unaware of the device's existence and will never serial poll it. ECNF 17 There is a syntax or value error in the configuration file. This error can be returned by ibfind() and ibdev(). ETAB 20 This error can be returned by ibevent(), FindLstn(), or FindRQS(). See their descriptions for more information.
If you wish to avoid using a global variable, you may instead use ThreadIberr() which returns a thread-specific value.
ibsta 3 ibsta holds status #include <gpib/ib.h> volatile int ibsta; Description ibsta is set whenever a function from the 'traditional' or 'multidevice' API is called. Each of the bits in ibsta has a different meaning, summarized in the following table: ibsta Bits bit value (hexadecimal) meaning used for board/device DCAS 0x1 DCAS is set when a board receives the device clear command (that is, the SDC or DCL command byte). It is cleared on the next 'traditional' or 'multidevice' function call following ibwait() (with DCAS set in the wait mask), or following a read or write (ibrd(), ibwrt(), Receive(), etc.). The DCAS and DTAS bits will only be set if the event queue is disabled. The event queue may be disabled with ibconfig(). board DTAS 0x2 DTAS is set when a board has received a device trigger command (that is, the GET command byte). It is cleared on the next 'traditional' or 'multidevice' function call following ibwait() (with DTAS in the wait mask). The DCAS and DTAS bits will only be set if the event queue is disabled. The event queue may be disabled with ibconfig(). board LACS 0x4 Board is currently addressed as a listener (IEEE listener state machine is in LACS or LADS). board TACS 0x8 Board is currently addressed as talker (IEEE talker state machine is in TACS or TADS). board ATN 0x10 The ATN line is asserted. board CIC 0x20 Board is controller-in-charge, so it is able to set the ATN line. board REM 0x40 Board is in 'remote' state. board LOK 0x80 Board is in 'lockout' state. board CMPL 0x100 I/O operation is complete. Useful for determining when an asynchronous I/O operation (ibrda(), ibwrta(), etc) has completed. board or device EVENT 0x200 One or more clear, trigger, or interface clear events have been received, and are available in the event queue (see ibevent()). The EVENT bit will only be set if the event queue is enabled. The event queue may be enabled with ibconfig(). board SPOLL 0x400 If this bit is enabled (see ibconfig()), it is set when the board is serial polled. The SPOLL bit is cleared when the board requests service (see ibrsv()) or you call ibwait() on the board with SPOLL in the wait mask. board RQS 0x800 RQS indicates that the device has requested service, and one or more status bytes are available for reading with ibrsp(). RQS will only be set if you have automatic serial polling enabled (see ibconfig()). device SRQI 0x1000 SRQI indicates that a device connected to the board is asserting the SRQ line. It is only set if the board is the controller-in-charge. If automatic serial polling is enabled (see ibconfig()), SRQI will generally be cleared, since when a device requests service it will be automatically polled and then unassert SRQ. board END 0x2000 END is set if the last io operation ended with the EOI line asserted, and may be set on reception of the end-of-string character. The IbcEndBitIsNormal option of ibconfig() can be used to configure whether or not END should be set on reception of the eos character. board or device TIMO 0x4000 TIMO indicates that the last io operation or ibwait() timed out. board or device ERR 0x8000 ERR is set if the last 'traditional' or 'multidevice' function call failed. The global variable iberr will be set indicate the cause of the error. board or device
If you wish to avoid using a global variable, you may instead use ThreadIbsta() which returns a thread-specific value.
Traditional API Functions Reference section for traditional API functions. ibask 3 ibask query configuration (board or device) #include <gpib/ib.h> int ibask int ud int option int *result Description Queries various configuration settings associated with the board or device descriptor ud. The option argument specifies the particular setting you wish to query. The result of the query is written to the location specified by result. To change the descriptor's configuration, see ibconfig(). ibask options option value (hexadecimal) result of query used for board/device IbaPAD 0x1 GPIB primary address board or device IbaSAD 0x2 GPIB secondary address (0 for none, 0x60 to 0x7f for secondary addresses 0 to 31) board or device IbaTMO 0x3 Timeout setting for io operations (a number from 0 to 17). See ibmto(). board or device IbaEOT 0x4 Nonzero if EOI is asserted with last byte on writes. See ibeot(). IbaPPC 0x5 Parallel poll configuration. See ibppc(). board IbaREADDR 0x6 Useless, included for compatibility only. device IbaAUTOPOLL 0x7 Nonzero if automatic serial polling is enabled. board IbaCICPROT 0x8 Useless, included for compatibility only. board IbaSC 0xa Nonzero if board is system controller. See ibrsc(). board IbaSRE 0xb Nonzero if board automatically asserts the REN line when it becomes the system controller. See ibrsc(). board IbaEOSrd 0xc Nonzero if termination of reads on reception of the end-of-string character is enabled. See ibeos(), in particular the REOS bit. board or device IbaEOSwrt 0xd Nonzero if EOI is asserted whenever end-of-string character is sent. See ibeos(), in particular the XEOS bit. board or device IbaEOScmp 0xe Nonzero if all 8 bits are used to match end-of-string character. Zero if only least significant 7 bits are used. See ibeos(), in particular the BIN bit. board or device IbaEOSchar 0xf The end-of-string byte. board or device IbaPP2 0x10 Nonzero if in local parallel poll configure mode. Zero if in remote parallel poll configure mode. board IbaTIMING 0x11 Number indicating T1 delay. 1 for 2 microseconds, 2 for 500 nanoseconds, 3 for 350 nanoseconds. The values are declared in the header files as the constants T1_DELAY_2000ns, T1_DELAY_500ns, and T1_DELAY_350ns. board IbaReadAdjust 0x13 Nonzero if byte pairs are automatically swapped during reads. board or device IbaWriteAdjust 0x14 Nonzero if byte pairs are automatically swapped during writes. board or device IbaEventQueue 0x15 Nonzero if event queue is enabled. board IbaSPollBit 0x16 Nonzero if the use of the SPOLL bit in ibsta is enabled. board IbaSendLLO 0x17 Nonzero if devices connected to this board are automatically put into local lockout mode when brought online with ibfind() or ibdev(). board IbaSPollTime 0x18 Timeout for serial polls. The value of the result is between 0 and 17, and has the same meaning as in ibtmo(). device IbaPPollTime 0x19 Timeout for parallel polls. The value of the result is between 0 and 17, and has the same meaning as in ibtmo(). board IbaEndBitIsNormal 0x1a Nonzero if END bit of ibsta is set on reception of end-of-string character or EOI. Zero if END bit is only set on EOI. board or device IbaUnAddr 0x1b Nonzero if UNT (untalk) and UNL (unlisten) commands are automatically sent after a completed ibrd* or ibwrt* operation using this descriptor. device IbaHSCableLength 0x1f Useless, included only for compatibility. board IbaIst 0x20 Individual status bit, a.k.a. 'ist'. board IbaRsv 0x21 The current status byte this board will use to respond to serial polls. board IbaBNA 0x200 For a device: the board index (minor number) of interface board through which the device is being accessed. For a board: the board index of the board itself. board or device Iba7BitEOS 0x1000 Nonzero if board supports 7 bit EOS comparisons. See ibeos(), in particular the BIN bit. This is a Linux-GPIB extension. board
Return value The value of ibsta is returned.
ibbna 3 ibbna change access board (device) #include <gpib/ib.h> int ibbna int ud const char *name Description ibbna() changes the GPIB interface board used to access the device specified by ud. Subsequent device level calls using the descriptor ud will assume the device is connected to the interface board specified by name. If you wish to specify a device's new access board by board index instead of name, you can use the IbcBNA option of ibconfig(). The name of a board can be specified in the configuration file gpib.conf. On success, iberr is set to the board index of the device's old access board. Return value The value of ibsta is returned. ibcac 3 ibcac assert ATN (board) #include <gpib/ib.h> int ibcac int ud int synchronous Description ibcac() causes the board specified by the board descriptor ud to become active controller by asserting the ATN line. The board must be controller-in-change in order to assert ATN. If synchronous is nonzero, then the board will wait for a data byte on the bus to complete its transfer before asserting ATN. If the synchronous attempt times out, or synchronous is zero, then ATN will be asserted immediately. It is generally not necessary to call ibcac(). It is provided for advanced users who want direct, low-level access to the GPIB bus. Return value The value of ibsta is returned. ibclr 3 ibclr clear device (device) #include <gpib/ib.h> int ibclr int ud Description ibclr() sends the clear command to the device specified by ud. Return value The value of ibsta is returned. ibcmd 3 ibcmd write command bytes (board) #include <gpib/ib.h> int ibcmd int ud const void *commands long num_bytes Description ibcmd() writes the command bytes contained in the array commands to the bus. The number of bytes written from the array is specified by num_bytes. The ud argument is a board descriptor, and the board must be controller-in-charge. Most of the possible command bytes are declared as constants in the header files. In particular, the constants GTL, SDC, PPConfig, GET, TCT, LLO, DCL, PPU, SPE, SPD, UNL, UNT,and PPD are available. Additionally, the inline functions MTA(), MLA(), MSA(), and PPE_byte() are available for producing 'my talk address', 'my listen address', 'my secondary address', and 'parallel poll enable' command bytes respectively. It is generally not necessary to call ibcmd(). It is provided for advanced users who want direct, low-level access to the GPIB bus. Return value The value of ibsta is returned. ibcmda 3 ibcmda write command bytes asynchronously (board) #include <gpib/ib.h> int ibcmda int ud const void *commands long num_bytes Description ibcmda() is similar to ibcmd() except it operates asynchronously. ibcmda() does not wait for the sending of the command bytes to complete, but rather returns immediately. While an asynchronous operation is in progress, most library functions will fail with an EOIP error. In order to successfully complete an asynchronous operation, you must call ibwait() with CMPL set in the wait mask, until the CMPL bit is set ibsta. Asynchronous operations may also be aborted with an ibstop() or ibonl() call. After the asynchronous I/O has completed and the results resynchronized with the current thread, the Linux-GPIB extensions AsyncIbsta, AsyncIberr, AsyncIbcnt, AsyncIbcntl may be useful to more cleanly separate the results of the asynchronous I/O from the results of the ibwait or similar call used to resynchronize. Return value The value of ibsta is returned. ibconfig 3 ibconfig change configuration (board or device) #include <gpib/ib.h> int ibconfig int ud int option int setting Description Changes various configuration settings associated with the board or device descriptor ud. The option argument specifies the particular setting you wish to modify. The setting argument specifies the option's new configuration. To query the descriptor's configuration, see ibask(). ibconfig options option value (hexadecimal) effect used for board/device IbcPAD 0x1 Sets GPIB primary address. Same as ibpad() board or device IbcSAD 0x2 Sets GPIB secondary address. Same as ibsad() board or device IbcTMO 0x3 Sets timeout for io operations. Same as ibmto(). board or device IbcEOT 0x4 If setting is nonzero, EOI is asserted with last byte on writes. Same as ibeot(). IbcPPC 0x5 Sets parallel poll configuration. Same as ibppc(). board IbcREADDR 0x6 Not implemented, included for compatibility only. Device ibrd* and ibwrt* calls always re-address. To avoid re-addressing use an initial device read or write followed by board read or writes to the controlling minor, ensuring no other intervening device access occurs. device IbcAUTOPOLL 0x7 If setting is nonzero then automatic serial polling is enabled. board IbcCICPROT 0x8 Useless, included for compatibility only. board IbcSC 0xa If setting is nonzero, board becomes system controller. Same as ibrsc(). board IbcSRE 0xb If setting is nonzero then board asserts REN when it becomes sytem controller otherwise REN is not asserted. It is nonzero by default. See ibrsc(). board IbcEOSrd 0xc If setting is nonzero then reads are terminated on reception of the end-of-string character. See ibeos(), in particular the REOS bit. board or device IbcEOSwrt 0xd If setting is nonzero then EOI is asserted whenever the end-of-string character is sent. See ibeos(), in particular the XEOS bit. board or device IbcEOScmp 0xe If setting is nonzero then all 8 bits are used to match the end-of-string character. Otherwise only the least significant 7 bits are used. See ibeos(), in particular the BIN bit. board or device IbcEOSchar 0xf Sets the end-of-string byte. See ibeos(). board or device IbcPP2 0x10 If setting is nonzero then the board is put into local parallel poll configure mode (IEEE 488.1 PP2 subset), and will not change its parallel poll configuration in response to receiving 'parallel poll enable' command bytes from the controller-in-charge. Instead, the parallel poll configuration is set locally by doing a board-level call of ibppc(). A zero value puts the board in remote parallel poll configure mode (IEEE 488.1 PP1 subset). IEEE 488.2 requires devices to support the remote PP1 subset and not the local PP2 subset. Some older hardware does not support local parallel poll configure mode. board IbcTIMING 0x11 Sets the T1 delay. Use setting of 1 for 2 microseconds, 2 for 500 nanoseconds, or 3 for 350 nanoseconds. These values are declared in the header files as the constants T1_DELAY_2000ns, T1_DELAY_500ns, and T1_DELAY_350ns. A 2 microsecond T1 delay is safest, but will limit maximum transfer speeds to a few hundred kilobytes per second. board IbcReadAdjust 0x13 If setting is nonzero then byte pairs are automatically swapped during reads. Presently, this feature is unimplemented. board or device IbcWriteAdjust 0x14 If setting is nonzero then byte pairs are automatically swapped during writes. Presently, this feature is unimplemented. board or device IbcEventQueue 0x15 If setting is nonzero then the event queue is enabled. The event queue is disabled by default. board IbcSPollBit 0x16 If the setting is nonzero then the use of the SPOLL bit in ibsta is enabled. board IbcSendLLO 0x17 If the setting is nonzero then devices connected to this board are automatically put into local lockout mode when brought online with ibfind() or ibdev(). board IbcSPollTime 0x18 Sets timeout for serial polls. The setting must be between 0 and 17, which correspond to the same time periods as in ibtmo(). device IbcPPollTime 0x19 Sets timeout for parallel polls. The setting must be between 0 and 17, which correspond to the same time periods as in ibtmo(). board IbcEndBitIsNormal 0x1a If setting is nonzero then the END bit of ibsta is set on reception of the end-of-string character or EOI (default). Otherwise END bit is only set on EOI. board or device IbcUnAddr 0x1b If setting is nonzero then UNT (untalk) and UNL (unlisten) commands are automatically sent after a completed ibrd* or ibwrt* operation using this descriptor. device IbcHSCableLength 0x1f Configures the total cable length in meters for your system, by sending the command bytes CFE and CFGn. This is required to enable high speed noninterlocked handshaking (a.k.a. HS488) and set associated handshake timings. Valid setting values are 0 through 15. A value of zero disables noninterlocked handshaking, otherwise the value is the total number of meters of cable. board IbcIst 0x20 Sets the individual status bit, a.k.a. 'ist'. Same as ibist(). board IbcRsv 0x21 Sets the current status byte this board will use to respond to serial polls. Same as ibrsv(). board IbcBNA 0x200 Changes the GPIB interface board used to access a device. The setting specifies the board index of the new access board. This configuration option is similar to ibbna() except the new board is specified by its board index instead of a name. device
Return value The value of ibsta is returned.
ibdev 3 ibdev open a device (device) #include <gpib/ib.h> int ibdev int board_index int pad int sad int timeout int send_eoi int eos Description ibdev() is used to obtain a device descriptor, which can then be used by other functions in the library. The argument board_index specifies which GPIB interface board the device is connected to. The pad and sad arguments specify the GPIB address of the device to be opened (see ibpad() and ibsad()). The timeout for io operations is specified by timeout (see ibtmo()). If send_eoi is nonzero, then the EOI line will be asserted with the last byte sent during writes (see ibeot()). Finally, the eos argument specifies the end-of-string character and whether or not its reception should terminate reads (see ibeos()). To suppress error messages printed to stderr by ibdev() set the environment variable IB_NO_ERROR before calling the routine. Return value If sucessful, returns a (non-negative) device descriptor. On failure, -1 is returned. ibeos 3 ibeos set end-of-string mode (board or device) #include <gpib/ib.h> int ibeos int ud int eosmode Description ibeos() is used to set the end-of-string character and mode. The least significant 8 bits of eosmode specify the eos character. You may also bitwise-or one or more of the following bits to set the eos mode: End-of-String Mode Bits constant value (hexadecimal) meaning REOS 0x400 Enable termination of reads when eos character is received. XEOS 0x800 Assert the EOI line whenever the eos character is sent during writes. BIN 0x1000 Match eos character using all 8 bits (instead of only looking at the 7 least significant bits).
Return value The value of ibsta is returned.
ibeot 3 ibeot assert EOI with last data byte (board or device) #include <gpib/ib.h> int ibeot int ud int send_eoi Description If send_eoi is non-zero, then the EOI line will be asserted with the last byte sent by calls to ibwrt() and related functions. Return value The value of ibsta is returned. ibevent 3 ibevent get events from event queue (board) #include <gpib/ib.h> int ibevent int ud short *event Description ibevent() is used to obtain the oldest event stored in the event queue of the board specified by the board descriptor ud. The EVENT bit of ibsta indicates that the event queue contains 1 or more events. An event may be a clear command, a trigger command, or reception of an interface clear. The type of event is stored in the location specified by event and may be set to any of the following values: events constant value description EventNone 0 The board's event queue is empty EventDevTrg 1 The board has received a trigger command from the controller-in-charge. EventDevClr 2 The board has received a clear command from the controller-in-charge. EventIFC 3 The board has received an interface clear from the system controller. Note, some models of GPIB interface board lack the ability to report interface clear events.
The event queue is disabled by default. It may be enabled by a call to ibconfig(). Each interface board has a single event queue which is shared across all processes and threads. So, only one process can retrieve any given event from the queue. Also, the queue is of finite size so events may be lost (ibevent() will return an error) if it is neglected too long.
Return value The value of ibsta is returned.
ibfind 3 ibfind open a board or device (board or device) #include <gpib/ib.h> int ibfind const char *name Description ibfind() returns a board or device descriptor based on the information found in the configuration file. To suppress error messages printed to stderr by ibfind() set the evironment variable IB_NO_ERROR before calling the routine. It is not required to use ibfind(), since device descriptors can be obtained with ibdev() and the 'board index' (minor number in the configuration file) can be used directly as a board descriptor. Return value If sucessful, returns a (non-negative) board or device descriptor. On failure, -1 is returned. ibgts 3 ibgts release ATN (board) #include <gpib/ib.h> int ibgts int ud int shadow_handshake Description ibgts() is the complement of ibcac(), and causes the board specified by the board descriptor ud to go to standby by releasing the ATN line. The board must be controller-in-change to change the state of the ATN line. If shadow_handshake is nonzero, then the board will handshake any data bytes it receives until it encounters an EOI or end-of-string character, or the ATN line is asserted again. The received data is discarded. It is generally not necessary to call ibgts(). It is provided for advanced users who want direct, low-level access to the GPIB bus. Return value The value of ibsta is returned. ibist 3 ibist set individual status bit (board) #include <gpib/ib.h> int ibist int ud int ist Description If ist is nonzero, then the individual status bit of the board specified by the board descriptor ud is set. If ist is zero then the individual status bit is cleared. The individual status bit is sent by the board in response to parallel polls. On success, iberr is set to the previous ist value. Return value The value of ibsta is returned. iblines 3 iblines monitor bus lines (board) #include <gpib/ib.h> int iblines int ud short *line_status Description iblines() is used to obtain the status of the control and handshaking bus lines of the bus. The board used to monitor the bus is specified by the ud argument, and the status of the various bus lines are written to the location specified by line_status. Some older chips are not capable of reporting the status of the bus lines, so each line has two corresponding bits in line_status. One bit indicates if the board can monitor the line, and the other bit indicates the line's state. The meaning of the line_status bits are as follows: line status bits constant value description ValidDAV 0x1 The BusDAV bit is valid. ValidNDAC 0x2 The BusNDAC bit is valid. ValidNRFD 0x4 The BusNRFD bit is valid. ValidIFC 0x8 The BusIFC bit is valid. ValidREN 0x10 The BusREN bit is valid. ValidSRQ 0x20 The BusSRQ bit is valid. ValidATN 0x40 The BusATN bit is valid. ValidEOI 0x80 The BusEOI bit is valid. BusDAV 0x100 Set/cleared if the DAV line is asserted/unasserted. BusNDAC 0x200 Set/cleared if the NDAC line is asserted/unasserted. BusNRFD 0x400 Set/cleared if the NRFD line is asserted/unasserted. BusIFC 0x800 Set/cleared if the IFC line is asserted/unasserted. BusREN 0x1000 Set/cleared if the REN line is asserted/unasserted. BusSRQ 0x2000 Set/cleared if the SRQ line is asserted/unasserted. BusATN 0x4000 Set/cleared if the ATN line is asserted/unasserted. BusEOI 0x8000 Set/cleared if the EOI line is asserted/unasserted.
Return value The value of ibsta is returned.
ibln 3 ibln check if listener is present (board or device) #include <gpib/ib.h> int ibln int ud int pad int sad short *found_listener Description ibln() checks for the presence of a device, by attempting to address it as a listener. ud specifies the GPIB interface board which should check for listeners. If ud is a device descriptor, then the device's access board is used. The GPIB address to check is specified by the pad and sad arguments. pad specifies the primary address, 0 through 30 are valid values. sad gives the secondary address, and may be a value from 0x60 through 0x7f (96 through 127), or one of the constants NO_SAD or ALL_SAD. NO_SAD indicates that no secondary addressing is to be used, and ALL_SAD indicates that all secondary addresses should be checked. If the board finds a listener at the specified GPIB address(es), then the variable specified by the pointer found_listener is set to a nonzero value. If no listener is found, the variable is set to zero. The board must be controller-in-charge to perform this function. Also, it must have the capability to monitor the NDAC bus line (see iblines()). This function has the additional effect of addressing the board as talker for the duration of the Find Listeners protocol, which is beyond what IEEE 488.2 specifies. This is done because some boards cannot reliably read the state of the NDAC bus line unless they are the talker. Being the talker causes the board's gpib transceiver to configure NDAC as an input, so its state can be reliably read from the bus through the transceiver. Return value The value of ibsta is returned. ibloc 3 ibloc go to local mode (board or device) #include <gpib/ib.h> int ibloc int ud Description Causes the board or device specified by the descriptor ud to go to local mode. If ud is a board descriptor, and the board is in local lockout, then the function will fail. Note, if the system controller is asserting the REN line, then devices on the bus will return to remote mode the next time they are addressed by the controller in charge. Return value The value of ibsta is returned. ibonl 3 ibonl close or reinitialize descriptor (board or device) #include <gpib/ib.h> int ibonl int ud int online Description If the parameter online is zero, then ibonl() frees the resources associated with the board or device descriptor ud. The descriptor cannot be used again after the ibonl() call. The parameter ud cannot be a board index (aka minor). If the parameter online is nonzero, then all the settings associated with the descriptor (GPIB address, end-of-string mode, timeout, etc.) are reset to their 'default' values. The 'default' values are the settings the descriptor had when it was first obtained with ibdev() or ibfind(). The parameter ud can be a board index (aka minor). The 'default' values are the standard default values as modified by the corresponding gpib.conf interface definition. Return value The value of ibsta is returned. ibpad 3 ibpad set primary GPIB address (board or device) #include <gpib/ib.h> int ibpad int ud int pad Description ibpad() sets the GPIB primary address to pad for the device or board specified by the descriptor ud. If ud is a device descriptor, then the setting is local to the descriptor (it does not affect the behaviour of calls using other descriptors, even if they refer to the same physical device). If ud is a board descriptor, then the board's primary address is changed immediately, which is a global change affecting anything (even other processes) using the board. Valid GPIB primary addresses are in the range from 0 to 30. Return value The value of ibsta is returned. ibpct 3 ibpct pass control (board) #include <gpib/ib.h> int ibpct int ud Description ibpct() passes control to the device specified by the device descriptor ud. The device becomes the new controller-in-charge. Return value The value of ibsta is returned. ibppc 3 ibppc parallel poll configure (board or device) #include <gpib/ib.h> int ibppc int ud int configuration Description Configures the parallel poll response of the device or board specified by ud. The configuration should either be set to the 'PPD' constant to disable parallel poll responses, or set to the return value of the PPE_byte() inline function to enable and configure the parallel poll response. If ud is a device descriptor then the device will be remotely configured by the controller. If ud is a board descriptor then the board will be locally configured. Note, in order to do a local parallel poll configuration IbcPP2 must be set using ibconfig(). IEEE 488.2 prohibits local parallel poll configuration (IEEE 488.1 PP2 subset), requiring support for remote parallel poll configuration (IEEE 488.1 PP1 subset) instead. After configuring the parallel poll response of devices on a bus, you may use ibrpp() to parallel poll the devices. Return value The value of ibsta is returned. ibrd 3 ibrd read data bytes (board or device) #include <gpib/ib.h> int ibrd int ud void *buffer long num_bytes Description ibrd() is used to read data bytes from a device or board. The argument ud can be either a device or board descriptor. Up to num_bytes bytes are read into the user-supplied array buffer. The read may be terminated by a timeout occuring(see ibtmo()), the talker asserting the EOI line, the board receiving the end-of-string character (see ibeos()), receiving a device clear command, or receiving an interface clear. If ud is a device descriptor, then the library automatically handles addressing the device as talker and the interface board as listener before performing the read. If ud is a board descriptor, no addressing is performed and the board must be addressed as a listener by the controller-in-charge. After the ibrd() call, ibcnt and ibcntl are set to the number of bytes read. Return value The value of ibsta is returned. ibrda 3 ibrda read data bytes asynchronously (board or device) #include <gpib/ib.h> int ibrda int ud void *buffer long num_bytes Description ibrda() is similar to ibrd() except it operates asynchronously. ibrda() does not wait for the reception of the data bytes to complete, but rather returns immediately. While an asynchronous operation is in progress, most library functions will fail with an EOIP error. In order to successfully complete an asynchronous operation and resynchronize its results with the current thread, you must call ibwait() with CMPL set in the wait mask, until the CMPL bit is set ibsta. Asynchronous operations may also be completed by a call to ibstop() or ibonl() call. Note, ibwait() will only complete the asynchronous operation if you explicitly set the CMPL bit in the wait mask parameter of ibwait(). After the asynchronous I/O has completed and the results resynchronized with the current thread, the Linux-GPIB extensions AsyncIbsta, AsyncIberr, AsyncIbcnt, AsyncIbcntl may be useful to more cleanly separate the results of the asynchronous I/O from the results of the ibwait or similar call used to resynchronize. Return value The value of ibsta is returned. ibrdf 3 ibrdf read data bytes to file (board or device) #include <gpib/ib.h> int ibrdf int ud const char *file_path Description ibrdf() is similar to ibrd() except that the data bytes read are stored in a file instead of an array in memory. file_path specifies the save file. If the file already exists, the data will be appended onto the end of the file. Return value The value of ibsta is returned. ibrpp 3 ibrpp perform a parallel poll (board or device) #include <gpib/ib.h> int ibrpp int ud char *ppoll_result Description ibrpp() causes the interface board to perform a parallel poll, and stores the resulting parallel poll byte in the location specified by ppoll_result. Bits 0 to 7 of the parallel poll byte correspond to the dio lines 1 to 8, with a 1 indicating the corresponding dio line is asserted. The devices on the bus you wish to poll should be configured beforehand with ibppc(). The board which performs the parallel poll must be controller-in-charge, and is specified by the descriptor ud. If ud is a device descriptor instead of a board descriptor, the device's access board performs the parallel poll. Return value The value of ibsta is returned. ibrsc 3 ibrsc request system control (board) #include <gpib/ib.h> int ibrsc int ud int request_control Description If request_control is nonzero, then the board specified by the board descriptor ud is made system controller. If request_control is zero, then the board releases system control. The system controller has the ability to assert the REN and IFC lines, and is typically also the controller-in-charge. Automatic assertion of REN is controlled with ibconfig(). If the IbcSRE configuration option has been set for the board descriptor ud then REN will automatically be asserted when the board becomes system controller. The configuration option IbcSRE is set by default. A GPIB bus may not have more than one system controller. Return value The value of ibsta is returned. ibrsp 3 ibrsp read status byte / serial poll (device) #include <gpib/ib.h> int ibrsp int ud char *result Description ibrsp() obtains the status byte from the device specified by ud. The status byte is stored in the location specified by result. If automatic serial polling is enabled on the board controlling the device, the status byte is automatically read and queued whenever the device requests service. If the status byte queue is not empty ibrsp() obtains the status byte information from the queue. If the queue is empty the status byte is obtained by serial polling the device. Automatic serial polling is controlled with ibconfig(). The contents of the status byte returned in result are device specific. Refer to the device manufacturer's documentation for details. For devices conforming to the IEEE488.1 or 2 specification the bits defined in the table below are available if enabled in the device's Status Byte Enable register. Standard IEEE.488 GPIB status byte bits constant value description IbStbRQS 0x40 The request service bit is set when device asserts RQS. It is cleared by serial polling the device. Supported by devices conforming to IEEE 488.1 or IEEE 488.2. IbStbESB 0x20 The event-status bit is set when there are one or more bits set in the device's Standard Event Status Register. It is cleared by reading the Standard Event Status Register. For devices conforming to IEEE 488.2 only. IbStbMAV 0x10 The message available bit indicates whether or not the device's data output queue is empty. Whenever the device has data available, this bit will be set. It is cleared when the output queue is empty. The queue is emptied by reading data from the device with ibrd() for example. For devices conforming to IEEE 488.2 only.
Return value The value of ibsta is returned.
ibrsv 3 ibrsv request service (board) #include <gpib/ib.h> int ibrsv int ud int status_byte Description The serial poll response byte of the board specified by the board descriptor ud is set to status_byte. If MSS (bit 6 in status_byte) is set, then the IEEE 488.2 local message "reqt" will be set true, causing the board to request service by asserting the SRQ line. If the MSS bit is clear, then the "reqf" message will be set true, causing the board to stop requesting service. Boards will also automatically stop requesting service when they are serial polled by the controller. This function follows the implementation technique described in IEEE 488.2 section 11.3.3.4.3. It is prone to generating spurious requests for service, which are permitted by 488.2 but less than ideal. In order to avoid spurious requests, use ibrsv2() instead. Return value The value of ibsta is returned. ibrsv2 3 ibrsv2 request service (board) #include <gpib/ib.h> int ibrsv2 int ud int status_byte int new_reason_for_request Description The serial poll response byte of the board specified by the board descriptor ud is set to status_byte. A service request may be generated, cleared, or left unaffected depending on the values of MSS (bit 6 in status_byte) and new_reason_for_request. There are three valid possibilities for MSS and new_reason_for_request. If MSS is 1 and new_reason_for_request is nonzero, then the IEEE 488.2 local message "reqt" will be set true. reqt sets local message "rsv" true which in turn causes the board to request service by asserting the SRQ line. If the MSS bit is 0 and new_reason_for_request is also 0, then the "reqf" message will be set true, causing rsv to clear and the board to stop requesting service. Finally, if MSS is 1 and new_reason_for_request is 0, then ibrsv2 will have no effect on the service request state (it will only update the status byte). The fourth possibility of MSS is 0 (which implies no service request) and new_reason_for_request is nonzero (which implies there is a service request) is contradictory and will be rejected with an EARG error. Boards will also automatically stop requesting service when they are serial polled by the controller. This function follows the preferred implementation technique described in IEEE 488.2 section 11.3.3.4.1. It can be used to avoid the spurious requests for service that ibrsv() is prone to. However, not all drivers/hardware implement support for this function. In such a case, this function may result in a ECAP error, and you will have to fall back on using the simpler ibrsv(). If you are implementing a 488.2 device, this function should be called every time either the status byte changes, or the service request enable register changes. The value for new_reason_for_request may be calculated from: new_reason_for_request = (status_byte & service_request_enable) & ~(old_status_byte & old_service_request_enable); Return value The value of ibsta is returned. ibsad 3 ibsad set secondary GPIB address (board or device) #include <gpib/ib.h> int ibsad int ud int sad Description ibsad() sets the GPIB secondary address of the device or board specified by the descriptor ud. If ud is a device descriptor, then the setting is local to the descriptor (it does not affect the behaviour of calls using other descriptors, even if they refer to the same physical device). If ud is a board descriptor, then the board's secondary address is changed immediately, which is a global change affecting anything (even other processes) using the board. This library follows NI's unfortunate convention of adding 0x60 hexadecimal (96 decimal) to secondary addresses. That is, if you wish to set the secondary address to 3, you should set sad to 0x63. Setting sad to 0 disables the use of secondary addressing. Valid GPIB secondary addresses are in the range from 0 to 31 (which correspond to sad values of 0x60 to 0x7f). Return value The value of ibsta is returned. ibsic 3 ibsic perform interface clear (board) #include <gpib/ib.h> int ibsic int ud Description ibsic() resets the GPIB bus by asserting the 'interface clear' (IFC) bus line for a duration of at least 100 microseconds. The board specified by ud must be the system controller in order to assert IFC. The interface clear causes all devices to untalk and unlisten, puts them into serial poll disabled state (don't worry, you will still be able to conduct serial polls), and the board becomes controller-in-charge. Return value The value of ibsta is returned. ibspb 3 ibspb obtain length of serial poll bytes queue (device) #include <gpib/ib.h> int ibspb int ud short *result Description ibspb() obtains the number of serial poll bytes queued for the device specified by ud. The number of queued serial poll bytes is stored in the location specified by result. If automatic serial polling is enabled on the board controlling the device, the status byte is automatically read and queued whenever the device requests service. Automatic serial polling is controlled with ibconfig(). The queued status bytes are read with ibrsp(). Return value The value of ibsta is returned. ibsre 3 ibsre set remote enable (board) #include <gpib/ib.h> int ibsre int ud int enable Description If enable is nonzero, then the board specified by the board descriptor ud asserts the REN line. If enable is zero, the REN line is unasserted. The board must be the system controller. Return value The value of ibsta is returned. ibstop 3 ibstop abort asynchronous i/o operation (board or device) #include <gpib/ib.h> int ibstop int ud Description ibstop() aborts an asynchronous i/o operation (for example, one started with ibcmda(), ibrda(), or ibwrta()). The return value of ibstop() is counter-intuitive. On successfully aborting an asynchronous operation, the ERR bit is set in ibsta, and iberr is set to EABO. If the ERR bit is not set in ibsta, then there was no asynchronous i/o operation in progress. If the function failed, the ERR bit will be set and iberr will be set to some value other than EABO. Return value The value of ibsta is returned. ibtmo 3 ibtmo adjust io timeout (board or device) #include <gpib/ib.h> int ibtmo int ud int timeout Description ibtmo() sets the timeout for IO operations and ibwait calls performed using the board or device descriptor ud. The actual amount of time before a timeout occurs may be greater than the period specified, but never less. timeout is specified by using one of the following constants: Timeout constants constant value timeout TNONE 0 Never timeout. T10us 1 10 microseconds T30us 2 30 microseconds T100us 3 100 microseconds T300us 4 300 microseconds T1ms 5 1 millisecond T3ms 6 3 milliseconds T10ms 7 10 milliseconds T30ms 8 30 milliseconds T100ms 9 100 milliseconds T300ms 10 300 milliseconds T1s 11 1 second T3s 12 3 seconds T10s 13 10 seconds T30s 14 30 seconds T100s 15 100 seconds T300s 16 300 seconds T1000s 17 1000 seconds
Return value The value of ibsta is returned.
ibtrg 3 ibtrg trigger device (device) #include <gpib/ib.h> int ibtrg int ud Description ibtrg() sends a GET (group execute trigger) command byte to the device specified by the device descriptor ud. Return value The value of ibsta is returned. ibvers 3 ibvers Obtain the current linux gpib version. #include <gpib/ib.h> void ibvers char ** version Description ibvers() will return the current version string in version. ibwait 3 ibwait wait for event (board or device) #include <gpib/ib.h> int ibwait int ud int status_mask Description ibwait() will sleep until one of the conditions specified in status_mask is true. The meaning of the bits in status_mask are the same as the bits of the ibsta status variable. If status_mask is zero, then ibwait() will return immediately. This is useful if you simply wish to get an updated ibsta. When calling ibwait() on a device, only the following condition bits in the status_mask are valid: TIMO, END, CMPL, and RQS. For the RQS bit to be set in the returned ibsta automatic serial polling must be enabled for the board controlling the device, see ibconfig(). The RQS condition is cleared by serial polling the device, see ibrsp(). If you wish to resynchronize and obtain the results from an asynchronous I/O operation, you must wait on CMPL by setting its bit in the status_mask parameter. Then if ibwait returns with CMPL set, it will have updated iberr, ibcnt, and the ERR bit of ibsta with the most recent asynchronous I/O results. If TIMO is set in the status_mask parameter, then ibwait will timeout after the time period set by ibtmo and set TIMO in ibsta. Return value The value of ibsta is returned. ibwrt 3 ibwrt write data bytes (board or device) #include <gpib/ib.h> int ibwrt int ud const void *data long num_bytes Description ibwrt() is used to write data bytes to a device or board. The argument ud can be either a device or board descriptor. num_bytes specifies how many bytes are written from the user-supplied array data. EOI may be asserted with the last byte sent or when the end-of-string character is sent (see ibeos() and ibeot()). The write operation may be interrupted by a timeout (see ibtmo()), the board receiving a device clear command, or receiving an interface clear. If ud is a device descriptor, then the library automatically handles addressing the device as listener and the interface board as talker, before sending the data bytes onto the bus. If ud is a board descriptor, the board simply writes the data onto the bus. The controller-in-charge must address the board as talker. After the ibwrt() call, ibcnt and ibcntl are set to the number of bytes written. Return value The value of ibsta is returned. ibwrta 3 ibwrta write data bytes asynchronously (board or device) #include <gpib/ib.h> int ibwrta int ud const void *buffer long num_bytes Description ibwrta() is similar to ibwrt() except it operates asynchronously. ibwrta() does not wait for the sending of the data bytes to complete, but rather returns immediately. While an asynchronous operation is in progress, most library functions will fail with an EOIP error. In order to successfully complete an asynchronous operation, you must call ibwait() with CMPL set in the wait mask, until the CMPL bit is set ibsta. Asynchronous operations may also be aborted with an ibstop() or ibonl() call. After the asynchronous I/O has completed and the results resynchronized with the current thread, the Linux-GPIB extensions AsyncIbsta, AsyncIberr, AsyncIbcnt, AsyncIbcntl may be useful to more cleanly separate the results of the asynchronous I/O from the results of the ibwait or similar call used to resynchronize. Return value The value of ibsta is returned. ibwrtf 3 ibwrtf write data bytes from file (board or device) #include <gpib/ib.h> int ibwrtf int ud const char *file_path Description ibwrtf() is similar to ibwrt() except that the data to be written is taken from a file instead of an array in memory. file_path specifies the file, which is written byte for byte onto the bus. Return value The value of ibsta is returned.
"Multidevice" API Functions The "Multidevice" API functions provide similar functionality to the "Traditional" API functions. However, some of the "multidevice" functions can be performed on multiple devices simultaneously. For example, SendList() can be used to write a message to multiple devices. Such functions take an array of Addr4882_t as an argument. The end of the array is specified by setting the last element to the constant NOADDR. AllSPoll 3 AllSPoll serial poll multiple devices #include <gpib/ib.h> void AllSPoll int board_desc Addr4882_t *addressList short *resultList void AllSpoll int board_desc const Addr4882_t *addressList short *resultList Description AllSPoll() causes the interface board specified by board_desc to serial poll all the GPIB addresses specified in the addressList array. The results of the serial polls are stored into resultList. If you only wish to serial poll a single device, ReadStatusByte() or ibrsp() may be more convenient. This function may also be invoked with the alternate capitalization 'AllSpoll' for compatibility with NI's library. DevClear 3 DevClear clear a device #include <gpib/ib.h> void DevClear int board_desc Addr4882_t address Description DevClear() causes the interface board specified by board_desc to send the clear command to the GPIB address specified by address. If you wish to clear multiple devices simultaneously, use DevClearList() DevClearList 3 DevClearList clear multiple devices #include <gpib/ib.h> void DevClearList int board_desc const Addr4882_t addressList[] Description DevClear() causes the interface board specified by board_desc to send the clear command simultaneously to all the GPIB addresses specified by the addressList array. If addressList is empty or NULL, then the clear command is sent to all devices on the bus. If you only wish to clear a single device, DevClear() or ibclr() may be slightly more convenient. EnableLocal 3 EnableLocal put devices into local mode. #include <gpib/ib.h> void EnableLocal int board_desc const Addr4882_t addressList[] Description EnableLocal() addresses all of the devices in the addressList array as listeners then sends the GTL (go to local) command byte, causing them to enter local mode. This requires that the board is the controller-in-charge. Note that while the REN (remote enable) bus line is asserted, the devices will return to remote mode the next time they are addressed. If addressList is empty or NULL, then the REN line is unasserted and all devices enter local mode. The board must be system controller to change the state of the REN line. EnableRemote 3 EnableRemote put devices into remote mode. #include <gpib/ib.h> void EnableRemote int board_desc const Addr4882_t addressList[] Description EnableRemote() asserts the REN (remote enable) line, and addresses all of the devices in the addressList array as listeners (causing them to enter remote mode). The board must be system controller. FindLstn 3 FindLstn find devices #include <gpib/ib.h> void FindLstn int board_desc const Addr4882_t padList[] Addr4882_t resultList[] int maxNumResults Description FindLstn() will check the primary addresses in the padList array for devices. The GPIB addresses of all devices found will be stored in the resultList array, and ibcnt will be set to the number of devices found. The maxNumResults parameter limits the maximum number of results that will be returned, and is usually set to the number of elements in the resultList array. If more than maxNumResults devices are found, an ETAB error is returned in iberr. The padList should consist of primary addresses only, with no secondary addresses (all possible secondary addresses will be checked as necessary). Your GPIB board must have the capability to monitor the NDAC bus line in order to use this function (see iblines). This function has the additional effect of addressing the board as talker for the duration of the Find Listeners protocol, which is beyond what IEEE 488.2 specifies. This is done because some boards cannot reliably read the state of the NDAC bus line unless they are the talker. Being the talker causes the board's gpib transceiver to configure NDAC as an input, so its state can be reliably read from the bus through the transceiver. FindRQS 3 FindRQS find device requesting service and read its status byte #include <gpib/ib.h> void FindRQS int board_desc const Addr4882_t addressList[] short *status Description FindRQS will serial poll the GPIB addresses specified in the addressList array until it finds a device requesting service. The status byte of the device requesting service is stored in the location specified by status. The addressList array index of the device requesting service is returned in ibcnt. If no device requesting service is found, an ETAB error is returned in iberr. PassControl 3 PassControl make device controller-in-charge #include <gpib/ib.h> void PassControl int board_desc const Addr4882_t address Description PassControl() causes the board specified by board_desc to pass control to the device specified by address. On success, the device becomes the new controller-in-charge. PPoll 3 PPoll parallel poll devices #include <gpib/ib.h> void PPoll int board_desc short *result Description PPoll() is similar to the 'traditional' API function ibrpp(). It causes the interface board to perform a parallel poll, and stores the parallel poll byte in the location specified by result. Bits 0 to 7 of the parallel poll byte correspond to the dio lines 1 to 8, with a 1 indicating the corresponding dio line is asserted. The devices on the bus you wish to poll should be configured beforehand with PPollConfig(). The board must be controller-in-charge to perform a parallel poll. PPollConfig 3 PPollConfig configure a device's parallel poll response #include <gpib/ib.h> void PPollConfig int board_desc Addr4882_t address int dio_line int line_sense Description PPollConfig() configures the device specified by address to respond to parallel polls. The dio_line (valid values are 1 through 8) specifies which dio line the device being configured should use to send back its parallel poll response. The line_sense argument specifies the polarity of the response. If line_sense is nonzero, then the specified dio line will be asserted to indicate that the 'individual status bit' (or 'ist') is 1. If sense is zero, then the specified dio line will be asserted when ist is zero. PPollUnconfig 3 PPollUnconfig disable devices' parallel poll response #include <gpib/ib.h> void PPollUnconfig int board_desc const Addr4882_t addressList[] Description PPollUnconfig() configures the devices specified by addressList to ignore parallel polls. RcvRespMsg 3 RcvRespMsg read data #include <gpib/ib.h> void RcvRespMsg int board_desc void *buffer long count int termination Description RcvRespMsg() reads data from the bus. A device must have already been addressed as talker (and the board as listener) before calling this function. Addressing may be accomplished with the ReceiveSetup() function. Up to count bytes are read into the array specified by buffer. The termination argument specifies the 8-bit end-of-string character (which must be a value from 0 to 255) whose reception will terminate a read. termination can also be set to the 'STOPend' constant, in which case no end-of-string character will be used. Assertion of the EOI line will always end a read. You may find it simpler to use the slightly higher level function Receive(), since it does not require addressing and reading of data to be performed separately. ReadStatusByte 3 ReadStatusByte serial poll a device #include <gpib/ib.h> void ReadStatusByte int board_desc Addr4882_t address short *result Description ReadStatusByte() causes the board specified by the board descriptor board_desc to serial poll the GPIB address specified by address. The status byte is stored at the location specified by the result pointer. If you wish to serial poll multiple devices, it may be slightly more efficient to use AllSPoll(). Serial polls may also be conducted with the 'traditional API' function ibrsp(). Receive 3 Receive perform receive addressing and read data #include <gpib/ib.h> void Receive int board_desc Addr4882_t address void *buffer long count int termination Description Receive() performs the necessary addressing, then reads data from the device specified by address. It is equivalent to a ReceiveSetup() call followed by a RcvRespMsg() call. ReceiveSetup 3 ReceiveSetup perform receive addressing #include <gpib/ib.h> void ReceiveSetup int board_desc Addr4882_t address Description ReceiveSetup() addresses the device specified by address as talker, and addresses the interface board as listener. A subsequent RcvRespMsg() call will read data from the device. You may find it simpler to use the slightly higher level function Receive(), since it does not require addressing and reading of data to be performed separately. ResetSys 3 ResetSys reset system #include <gpib/ib.h> void ResetSys int board_desc const Addr4882_t addressList[] Description ResetSys() has the following effects: The remote enable bus line is asserted. An interface clear is performed (the interface clear bus line is asserted for at least 100 microseconds). The device clear command is sent to all the devices on the bus. The *RST message is sent to every device specified in the addressList. Send 3 Send perform send addressing and write data #include <gpib/ib.h> void Send int board_desc Addr4882_t address const void *data long count int eot_mode Description Send() addresses the device specified by address as listener, then writes data onto the bus. It is equivalent to a SendList() except it only uses a single GPIB address to specify the listener instead of allowing an array of listeners. SendCmds 3 SendCmds write command bytes onto bus #include <gpib/ib.h> void SendCmds int board_desc const void *cmds long count Description SendCmds() writes count command byte onto the the GPIB bus from the array cmds. It is generally not necessary to call SendCmds(). It is provided for advanced users who want direct, low-level access to the GPIB bus. SendDataBytes 3 SendDataBytes write data #include <gpib/ib.h> void SendDataBytes int board_desc const void *data long count int eot_mode Description SendDataBytes() writes data to the bus. One or more devices must have already been addressed as listener (and the board as talker) before calling this function. Addressing may be accomplished with the SendSetup() function. count bytes are written from the array specified by data. The eot_mode argument specifies how the message should be terminated, and may be any of the following values: eot modes constant value description NULLend 0 Do not assert EOI or add a newline at the end of the write. DABend 1 Assert EOI with the last byte of the write. NLend 2 Append a newline, and assert EOI with the newline at the end of the write.
You may find it simpler to use the slightly higher level functions Send() or SendList(), since they does not require addressing and writing of data to be performed separately.
SendIFC 3 SendIFC perform interface clear #include <gpib/ib.h> void SendIFC int board_desc Description SendIFC() resets the GPIB bus by asserting the 'interface clear' (IFC) bus line for a duration of at least 100 microseconds. The board specified by board_desc must be the system controller in order to assert IFC. The interface clear causes all devices to untalk and unlisten, puts them into serial poll disabled state (don't worry, you will still be able to conduct serial polls), and the board becomes controller-in-charge. SendList 3 SendList write data to multiple devices #include <gpib/ib.h> void SendList int board_desc const Addr4882_t addressList[] const void *data long count int eot_mode Description SendList() addresses the devices in addressList as listeners, then writes the contents of the array data to them. It is equivalent to a SendSetup() call followed by a SendDataBytes() call. SendLLO 3 SendLLO put devices into local lockout mode #include <gpib/ib.h> void SendLLO int board_desc Description SendLLO() asserts the 'remote enable' bus line, then sends the LLO command byte. Any devices currently addressed as listener will be put into RWLS (remote with lockout state), and all other devices will enter LWLS (local with lockout state). Local lockout means the remote/local mode of devices cannot be changed though the devices' front-panel controls. Unasserting the REN line should bring the devices out of lockout state. The SetRWLS() performs a similar function, except it lets you specify which devices you wish to address as listener before sending the LLO command. SendSetup 3 SendSetup perform send addressing #include <gpib/ib.h> void SendSetup int board_desc const Addr4882_t addressList[] Description SendSetup() addresses the devices in addressList as listeners, and addresses the interface board as talker. A subsequent SendDataBytes() call will write data to the devices. You may find it simpler to use the slightly higher level functions Send() or SendList(), since they does not require addressing and writing of data to be performed separately. SetRWLS 3 SetRWLS put devices into remote with lockout state #include <gpib/ib.h> void SetRWLS int board_desc const Addr4882_t addressList[] Description SetRWLS() asserts the 'remote enable' bus line, addresses the devices in the addressList array as listeners, then sends the LLO command byte. The devices addressed as listener will be put into RWLS (remote with lockout state), and all other devices will enter LWLS (local with lockout state). Local lockout means the remote/local mode of devices cannot be changed though the devices' front-panel controls. Unasserting the REN line should bring the devices out of the lockout state. TestSRQ 3 TestSRQ query state of SRQ bus line #include <gpib/ib.h> void TestSRQ int board_desc short *result Description TestSRQ() checks the state of the SRQ bus line and writes its state to the location specified by result. A '1' indicates the SRQ line is asserted, and a '0' indicates the line is not asserted. Some boards lack the capability to report the status of the SRQ line. In such a case, an ECAP error is returned in iberr. TestSys 3 TestSys perform self-test queries on devices #include <gpib/ib.h> void TestSys int board_desc const Addr4882_t addressList[] short results[] Description TestSys() sends the '*TST?' message to all the devices in the addressList array, then reads their responses into the results array. This will cause devices that conform to the IEEE 488.2 standard to perform a self-test and respond with a zero on success. A non-zero response indicates an error during the self-test. The number of devices which responded with nonzero values from their self-tests is returned in ibcnt, ibcntl. If a device fails to respond to the *TST? query, an error will be flagged in ibsta (this is different than NI's documented behaviour which is broken). Trigger 3 Trigger trigger a device #include <gpib/ib.h> void Trigger int board_desc Addr4882_t address Description Trigger() is equivalent to a TriggerList() call with a single address. TriggerList 3 Trigger trigger multiple devices #include <gpib/ib.h> void TriggerList int board_desc Addr4882_t addressList[] Description TriggerList() sends a GET (group execute trigger) command byte to all the devices specified in the addressList array. If no addresses are specified in addressList then the GET command byte is sent without performing any addressing. WaitSRQ 3 WaitSRQ sleep until the SRQ bus line is asserted #include <gpib/ib.h> void WaitSRQ int board_desc short *result Description WaitSRQ() sleeps until either the SRQ bus line is asserted, or a timeout (see ibtmo()) occurs. A '1' will be written to the location specified by result if SRQ was asserted, and a '0' will be written if the function timed out.
Utility Functions AsyncIbcnt 3 AsyncIbcnt ibcnt, ibcntl values for last asynchronous I/O operation #include <gpib/ib.h> int AsyncIbcnt void long AsyncIbcntl void Description AsyncIbcnt() and AsyncIbcntl() return thread-local counts related to the global variables ibcnt, ibcntl. Their values correspond to the result of the last asynchronous I/O operation resynchronized to the current thread by an ibwait or ibstop call. These functions only reflect the result of the asynchronous I/O operation itself and not, for example, the ibwait which resynchronized the asynchronous result to the current thread. Thus the result from AsyncIbcnt() is easier to interpret than ThreadIbcnt(), since it is unambiguous whether the value is associated with the asynchronous I/O result, or with the function call used to resynchronize (ibwait or ibstop). These functions are Linux-GPIB extensions. Return value A value related to ibcnt or ibcntl corresponding to the last asynchronous I/O operation resynchronized to the current thread is returned. AsyncIberr 3 AsyncIberr iberr value for last asynchronous I/O operation #include <gpib/ib.h> int AsyncIberr void Description AsyncIberr() returns a thread-local error number related to the global variable iberr. Its value corresponds to the result of the last asynchronous I/O operation resynchronized to the current thread by an ibwait or ibstop call. This function only reflects the result of the asynchronous I/O operation itself and not, for example, the ibwait which resynchronized the asynchronous result to the current thread. Thus the result from AsyncIberr() is easier to interpret than ThreadIberr(), since it is unambiguous whether the value is associated with the asynchronous I/O result, or with the function call used to resynchronize (ibwait or ibstop). This function is a Linux-GPIB extension. Return value A value related to iberr corresponding to the last asynchronous I/O operation resynchronized to the current thread is returned. AsyncIbsta 3 AsyncIbsta ibsta value for last asynchronous I/O operation #include <gpib/ib.h> int AsyncIbsta void Description AsyncIbsta() returns a thread-local status value related to the global variable ibsta. Its value corresponds to the result of the last asynchronous I/O operation resynchronized to the current thread by an ibwait or ibstop call. This function only reflects the result of the asynchronous I/O operation itself and not, for example, the ibwait which resynchronized the asynchronous result to the current thread. Thus the result from AsyncIbsta() is easier to interpret than ThreadIbsta(), since it is unambiguous whether the value is associated with the asynchronous I/O result, or with the function call used to resynchronize (ibwait or ibstop). Only the status bits END | ERR | TIMO | CMPL are valid in the returned status byte. The rest of the bits should be ignored and will be set to zero. This function is a Linux-GPIB extension. Return value A value related to ibsta corresponding to the last asynchronous I/O operation resynchronized to the current thread. CFGn 3 CFGn generate 'configure n meters' command byte #include <gpib/ib.h> uint8_t CFGn unsigned int num_meters Description CFGn() returns a 'configure n meters' command byte corresponding to the num_meters argument. num_meters (valid values are 1 through 15) specifies how many meters of cable are in your system. This is necessary in before high speed non-interlocked handshaking (a.k.a. HS488) can be used on the bus. The CFGn command byte must be preceded by a CFE command byte to take effect. Return value The appropriate CFGn command byte is returned. GetPAD 3 GetPAD extract primary address from an Addr4882_t value #include <gpib/ib.h> static __inline__ unsigned int GetPAD Addr4882_t address Description GetPAD() extracts the primary address packed into the Addr4882_t value address. Return value The primary GPIB address (from 0 through 30) stored in address. GetSAD 3 GetSAD extract secondary address from an Addr4882_t value #include <gpib/ib.h> static __inline__ unsigned int GetSAD Addr4882_t address Description GetSAD() extracts the secondary address packed into the Addr4882_t value address. Return value The secondary GPIB address (from 0x60 through 0x7f, or 0 for none) stored in address. MakeAddr 3 MakeAddr pack primary and secondary address into an Addr4882_t value #include <gpib/ib.h> static __inline__ Addr4882_t MakeAddr unsigned int pad unsigned int sad Description MakeAddr() generates an Addr4882_t value that corresponds to the specified primary address pad and secondary address sad. It does so by putting pad into the least significant byte and left shifting sad up to the next byte. Examples Addr4882_t addressList[ 5 ]; addressList[ 0 ] = 5 /* primary address 5, no secondary address */ addressList[ 1 ] = MakeAddr(3, 0); /* primary address 3, no secondary address */ addressList[ 2 ] = MakeAddr(7, 0x70); /* primary address 3, secondary address 16 */ addressList[ 3 ] = MakeAddr(20, MSA(9)); /* primary address 20, secondary address 9 */ addressList[ 4 ] = NOADDR; Return value An Addr4882_t value corresponding to the specified primary and secondary GPIB address. MLA 3 MLA generate 'my listen address' command byte #include <gpib/ib.h> uint8_t MLA unsigned int address Description MLA() returns a 'my listen address' command byte corresponding to the address argument. The address may be between 0 and 30. Return value The appropriate MLA command byte is returned. MSA 3 MSA generate 'my secondary address' command byte #include <gpib/ib.h> uint8_t MSA unsigned int address Description MSA() returns a 'my secondary address' command byte corresponding to the address argument. The address may be between 0 and 31. This macro is also useful for mangling secondary addresses from the 'real' values between 0 and 31 to the range 0x60 to 0x7f used by most of the library's functions. Return value The appropriate MSA command byte is returned. MTA 3 MTA generate 'my talk address' command byte #include <gpib/ib.h> uint8_t MTA unsigned int address Description MTA() returns a 'my talk address' command byte corresponding to the address argument. The address may be between 0 and 30. Return value The appropriate MTA command byte is returned. PPE_byte 3 PPE_byte generate 'parallel poll enable' command byte #include <gpib/ib.h> uint8_t PPE_byte unsigned int dio_line int sense Description PPE_byte() returns a 'parallel poll enable' command byte corresponding to the dio_line and sense arguments. The dio_line (valid values are 1 through 8) specifies which dio line the device being configured should use to send back its parallel poll response. The sense argument specifies the polarity of the response. If sense is nonzero, then the specified dio line will be asserted to indicate that the 'individual status bit' (or 'ist') is 1. If sense is zero, then the specified dio line will be asserted when ist is zero. Return value The appropriate PPE command byte is returned. ThreadIbcnt 3 ThreadIbcnt thread-specific ibcnt, ibcntl values #include <gpib/ib.h> int ThreadIbcnt void long ThreadIbcntl void Description ThreadIbcnt() and ThreadIbcntl() return thread-local versions of the global variables ibcnt, ibcntl. Return value The value of ibcnt or ibcntl corresponding to the last 'traditional' or 'multidevice' function called in the current thread is returned. ThreadIberr 3 ThreadIberr thread-specific iberr value #include <gpib/ib.h> int ThreadIberr void Description ThreadIberr() returns a thread-local version of the global variable iberr. Return value The value of iberr corresponding to the last 'traditional' or 'multidevice' function called by the current thread is returned. ThreadIbsta 3 ThreadIbsta thread-specific ibsta value #include <gpib/ib.h> int ThreadIbsta void Description ThreadIbsta() returns a thread-local version of the global variable ibsta. Return value The value of ibsta corresponding to the last 'traditional' or 'multidevice' function called by the current thread is returned.
GPIB protocol Outline of the GPIB protocol elements
GPIB command bytes The meaning and values of the possible GPIB command bytes are as follows: GPIB command bytes byte value (hexadecimal) name description 0x1 GTL Go to local 0x4 SDC Selected device clear 0x5 PPConfig (also 'PPC' on non-powerpc architectures) Parallel poll configure 0x8 GET Group execute trigger 0x9 TCT Take control 0x11 LLO Local lockout 0x14 DCL Device clear 0x15 PPU Parallel poll unconfigure 0x18 SPE Serial poll enable 0x19 SPD Serial poll disable 0x1f CFE Configure enable 0x20 to 0x3e MLA0 to MLA30 My (primary) listen address 0 to 30 0x3f UNL Unlisten 0x40 to 0x5e MTA0 to MTA30 My (primary) talk address 0 to 30 0x5f UNT Untalk 0x60 to 0x6f MSA0 to MSA15, also PPE, also CFG1 to CFG15 When following a primary talk or primary listen address, this is "my secondary address" MSA0 (0x60) to MSA15 (0x6f). When following a PPC "parallel poll configure", this is PPE "parallel poll enable". When following a CFE "configure enable", this is CFG1 (0x61) to CFG15 (0x6f) "configure n meters". For parallel poll enable, the least significant 3 bits of the command byte specify which DIO line the device should use to send its parallel poll response. The fourth least significant bit (0x8) indicates the 'sense' or polarity the device should use when responding. 0x70 to 0x7f MSA16 to MSA31, also PPD When following a talk or listen address, this is 'my secondary address' 16 to 31. When following a parallel poll configure, this is 'parallel poll disable'.
GPIB bus lines Physically, the GPIB bus consists of 8 data lines, 3 handshaking lines, and 5 control lines (and 8 ground lines). Brief descriptions of how they are used follow: GPIB bus lines bus line description pin number DIO1 through DIO8 Data input/output bits. These 8 lines are used to read and write the 8 bits of a data or command byte that is being sent over the bus. DIO1 to DIO4 use pins 1 to 4, DIO5 to DIO8 use pins 13 to 16 EOI End-or-identify. This line is asserted with the last byte of data during a write, to indicate the end of the message. It can also be asserted along with the ATN line to conduct a parallel poll. 5 DAV Data valid. This is a handshaking line, used to signal that the value being sent with DIO1-DIO8 is valid. During transfers the DIO1-DIO8 lines are set, then the DAV line is asserted after a delay called the 'T1 delay'. The T1 delay lets the data lines settle to stable values before they are read. 6 NRFD Not ready for data. NRFD is a handshaking line asserted by listeners to indicate they are not ready to receive a new data byte. 7 NDAC Not data accepted. NDAC is a handshaking line asserted by listeners to indicate they have not yet read the byte contained on the DIO lines. 8 IFC Interface clear. The system controller can assert this line (it should be asserted for at least 100 microseconds) to reset the bus and make itself controller-in-charge. 9 SRQ Service request. Devices on the bus can assert this line to request service from the controller-in-charge. The controller can then poll the devices until it finds the device requesting service, and perform whatever action is necessary. 10 ATN Attention. ATN is asserted to indicate that the DIO lines contain a command byte (as opposed to a data byte). Also, it is asserted with EOI when conducting parallel polls. 11 REN Remote enable. Asserted by the system controller, it enables devices to enter remote mode. When REN is asserted, a device will enter remote mode when it is addressed by the controller. When REN is false, all devices will immediately return to local mode. 17
&license
doc/obsolete-linux-gpib.txt000066400000000000000000001446121507046215500162710ustar00rootroot00000000000000 Linux-GPIB User's Guide Copyright cfl 1994 Claus Schroeter (clausi@chemie.fu-berlin.de) Version 1.1 (4/8/96) The Linux-GPIB Package is a Driver and User-Interface Package for usual GPIB cards. This Document describes the basic steps for installation and usage of the package. Contents 1 Introduction 5 1.1 Short Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.2.1 Additional Documentation . . . . . . . . . . . . . . . . . . . . . . . 7 1.3 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3.2 Additional Software . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2 Installing the Software 9 2.1 Preparing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 Compile-Time Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 Compiling the Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.4 Configuring Driver/library Characteristics . . . . . . . . . . . . . . . . . . . 10 2.4.1 Configuring the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.4.2 Configuring the Library . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4.3 Using ibconf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3 The Driver Module 15 3.1 Special Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.2 Testing the Configuration with ibchk . . . . . . . . . . . . . . . . . . . . . 15 3.3 Testing the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 Using the VFS Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.5 Multiprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1 2 CONTENTS 4 Using the GPIB Library 19 4.1 What is goin' on behind the scenes? . . . . . . . . . . . . . . . . . . . . . . 19 4.2 How The Library is organized . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.2.1 Compatibility with NI-488.2TMLibrary . . . . . . . . . . . . . . . . . 22 4.2.2 Device Management . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2.3 Error Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2.4 Device Status and Error Codes . . . . . . . . . . . . . . . . . . . . . 27 4.3 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.4 Using Remote GPIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.4.2 Programming With rGPIB . . . . . . . . . . . . . . . . . . . . . . . 30 4.4.3 Configuring the Library for rGPIB . . . . . . . . . . . . . . . . . . . 31 5 The Application Suite 35 5.1 What is ibsh? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 5.2 Using ibsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 5.2.1 Module Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 5.3 Writing Modules for ibsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.3.1 Some modules included . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.4 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 A Library Reference 41 A.1 Management Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 A.2 Device Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 A.3 Bus Level Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 CONTENTS 3 Copyrights 8 The Package and this document is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published by the Free Software Foundation; This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 4 CONTENTS Introduction 1.1 Short Overview Let's understand this package as the begin of a larger project to make linux more useable to people dealing with automation, process control and engineering in laboratory and industrial environment. Realize that there is much work todo (with this and other projects dealing with this stuff). The IEEE488 or GPIB Standard, first developed by HP (1965) (called HPIB) provides a wide spreaded construction kit that makes measurement, data aquisition and control as simple as possible. Til now this bus-system wasn't availiable for linux users because the Hardware wasn't supported yet. I want to fill this gap step by step. My second Idea is to make it as simple as possible for the (perhaps unexperienced) user to write applications. This can be done step by step too. Under DOS a wide Variety of nice (colorful) Software exists to simplify the GPIB Handling. That makes a lot of people afraid to going to Linux. I want to fill this gap too. The first step i did was to implement a interface to TCL/TK, a powerful Toolkit Language by John Ousterhout, to the GPIB library. With this simple a-few-hundred-lines C interface users could write very poverful Programs with comfortable graphical User Interfaces under X11 within some Minutes (depending on the knowledge of tcl/tk). At this time a lot of extensions exists for Tcl/Tk so that it were possible to provide GPIB functions over a network or write client/server Measurement systems. There are no limits to the phantasies what to do with this tool. As i mentioned this should be the first step. So i made a driver for the mostly used Card (AT-GPIB from NI) and i hope the support for other cards follows soon. 5 6 Chapter 1. Introduction 1.2 Features The Package consists of four Parts: n^ The driver Module This piece of code does all the dirty work, write magic numbers in magic places and gives the results back. The Driver has been designed as loadable Module and is full Runtime configurable. You can change the functionality, base-address etc at runtime without rebuilding the kernel. To Install the driver, minor changes to the Kernel are required. Normally once the module has been build you could use it for many purposes without recompiling. The driver-module can be used either with the gpib-library or as normal character driver using the VFS interface. ng The GPIB Library. This Library provides higher level calls to C-Programs, that makes the work easier. Tere are simple to understand functions that provide Device-Management, configuration and read/write commands to the GPIB the bus. The function names of the most Library functions are similar to the National Instruments NI488.2TMLibrary. Porting of your programs should be simple. The library does the whole driver runtime configuration that could be specified in a special configuration file. A simple Errorlogging Mechanism is provided so that every Operation on the driver could be backtraced on /dev/console or whereever. rGPIB a client-server model extension is included in the library with this feature the bus can be virtually extended over the network. o"" The TCL/TK extension I think this is the most popular thing of this Package. With the TCL/tk Interface you can test your hardware, play around and write simple applications with graphical user interfaces within some minutes. ibsh the TCL/Tk interpreter is included in the package, ibsh can be dynamically extended with loadable TCL-Modules. Some useful widgets are also included as dials, meters, rasters and so on. A Software Diagnostic Program that checks your Setup for installation errors is also provided. 1.3. Requirements 7 1.2.1 Additional Documentation For finding routines and driver conventions quick and easy a handy Quick-Reference-Guide is included in the documentation (refcard.ps). 1.3 Requirements 1.3.1 Hardware The following GPIB Hardware is supported by this Package: ffl National Instruments AT-GPIB Boards There are three types supported - one with NEC7210 TLC and TURBO488 chip, one with NAT4882/TURBO488 chips and the newest one with TNT4882 ASIC. ffl National Instruments PCII Boards ffl National Instruments PCIIa Boards ffl IBM GPIB Adapter (PCIIa compatible) ffl Hewlett Packard HP82355 and 27209 boards. 1.3.2 Additional Software You will need Linux-1.1.61 or higher to work with this Package. To install the driver to your kernel you will need the modutils package (insmod/rmmod). This should be in /sbin if You have the slackware distribution installed. If you want (and i bet you will) the TCL/tk Interface you need a working tcl/tk library (my version was tcl7.3 and tk3.6 but i think you can use newer versions as well). You also can get a shared binary version from sunsite or tsx-11. The installation should be very simple. It's recommended to have the Tcl/Tk sources availiable if you want to write own Widgets for Tk or if you Want to add other TCL/Tk extensions to ibsh. For the unpatient installer I added the necessary files to ../tcldev so everything should compile smootly. The original National Instruments sample files could be helpful for beginners to understand how to write GPIB Programs. Additionally I added some sample programs in ./examples. 8 Chapter 1. Introduction Installing the Software 2.1 Preparing There are some things you must do before you can slip into any Linux GPIB stuff. u"" cd to the directory where You want to install the Linux-GPIB sources (say /usr/local/src). u* Unpack the gpib-linux!version?.base.tgz and optionally the other package files gpib-linux!version?.ibsh.tgz (the ibsh sources) and gpib-linux!version?.tcl.tgz (additional tcl stuff ) to this directory. (Oh what stupid, if you read this you will have done this yet :-) ) y" Now install the additional Software (mentioned above) first. On newer distributions as Slackware-2.0 you will not need to install the modutils Package. Check out if insmod,rmmod,lsmod exists in /sbin. If You haven't the tcl package installed, It's recommended to make a Directory (or symbolic link) tcldev in your Source Directory where the whole Tcl Stuff lives, the configuration expects at least two directories inside ../tcldev. See applications/ibsh/Makefile for details. If you install the Tcl Sources compile them and make install to put the binaries to the right places. Edit ibsh/Makefile for your requirements. z' Read all README files ! There is important information about how to configure special cards etc. z^ Configure your board-jumpers to the desired base-address,IRQ, and DMA You should take care that the base and/or DMA setting does not conflict with other hardware settings. z. Turn off your system and install your board in your computer. Take care that at least one GPIB device is connected to your bus before you start building the package. 9 10 Chapter 2. Installing the Software 2.2 Compile-Time Options There are some Options that could be set for the driver. You can decide if you want continous Debugging or if the driver should run in DMA transfer mode. Compile time options are set with the configuration script provided with the package. First time you're building the package the configuration will be done automatically. Later you can reconfigure your driver with make config 2.3 Compiling the Sources Change to the toplevel Directory (say /usr/local/src/atgpib-linux!version?). Now type make and answer the Questions from the Configuration and select the desired options in the option menu. If the setup has been done the setup-script now will compile the package. If everything has been finished the script will attempt to load and check the configuration with the ibchk utility. If everything is OK you could now test your driver. If you think it works fine you may type make install to install Linux-GPIB on your system. You will get an object file gpib!id?.o (id is the id number given in driver/Makefile ) If the driver has sucessfully been build try to load it (directly via insmod gpib!id?.o or by typing make load) If no error message occurs you have loaded the driver succesfully into the kernel. Look at the File /usr/adm/messages, you should see some messages related to GPIB. 2.4 Configuring Driver/library Characteristics 2.4.1 Configuring the Driver Everything the driver Module needs to know from the User is the Base Address, the IRQ Level and DMA channel, it's Major Number and optionally the Debug Level. The Base, IRQ and DMA settings depends on your board jumper settings. Refer to your Hardware installation Guide for details. The Major Number is used to decide wich driver inode file is suitable to which module. This Number has to be unique for your System. To find out which Majors are used by other Drivers check out /proc/devices 2.4. Configuring Driver/library Characteristics 11 The Debug Level determines wich actions of the Module should be logged by syslogd to /usr/adm/messages. The Driver Module is Configurable with three Methods: ffl Via the compile-time options. ffl At Loading time you could specify options: /sbin/insmod gpib0.o [[option=value] ....] option could be one of ibbase specifies the Hardware address of the GPIB board (default is 0x2c0) ibdma specifies the DMA Channel for the board ( default is 5) ibirq specifies the IRQ Level for the board (default is 11) ibmajor specifies the Major Number for the module (default is 31) Realize that this Number must match your driver inode's Major Number dbgMask sets your debugging level if you selected DEBUG Mode in the configuration. If you want to use the module with debugging enabled you should set the default debug level to NONE (Configuration). ffl With Library routines and the library configuration script. 2.4.1.1 Specifying Debug Levels If you enabled the Debugging Option in your Configuration Script you could backtrace every action that your driver is doing. One of the consequences of this Method is your /usr/adm/messages logging file will get very large. To prevent a messy logfile you could select what actions should be logged. The Meaning of the 8 debug-level bits are in Table 2.4.1.1. Example: Load the Module with /sbin/insmod gpib0.o dbgMask=0x06 and start the ibchk program. Your Kernel Logfile (/usr/adm/messages) will show up messages like shown in Example 2.4.1.1. Now you can backtrace any function that is called during program operation. If you're using the GPIB library, the debugging level can also be set from /etc/gpib.conf debug = !level? option in the config section. 12 Chapter 2. Installing the Software Example 2.4.1 Driver Logging Nov 20 13:37:56 clausi kernel: AT-GPIB Driver -- Major=31 Base=0x2c0 Irq=11 DMA=5 enabled Nov 20 13:37:56 clausi kernel: -- DebugMask = 0x106 Nov 20 13:37:56 clausi kernel: -- Kernel Release 1.1.51 Nov 20 13:37:56 clausi kernel: gpib - ibinstall:in Nov 20 13:37:56 clausi kernel: gpib - ibinstall:out Nov 20 13:38:16 clausi kernel: gpib - ibopen:in . 2.4.2 Configuring the Library The GPIB Library can be configured via the /etc/gpib.conf file. A simple utility program ibconf comes with the Package that allows quick and easy installation see 2.4.3 how to use it. 8 8 Realize that the driver does not know anything about this configuration if the Library is not used. If you want to use the driver without the library you must pay attention that your base address, IRQ and DMA has been set at compiling- or loading-time. You're able to define mnemonics for your devices like "dvm" or "scope". The default configuration file is /etc/gpib.conf but you can override this by setting the IB CONFIG environment variable to the desired path. Look at the default config file to understand the mechanism. You can also set the base address and the IRQ level of the card. Edit the configuration for your requirements. You can set the board characteristics as base adress and irq within the config file for several 0 All actions will be logged 1 Log every Function Entry 2 Log every Function Exits 3 Branches (as DMA start etc) 4 Data given to functions 5 Interrupts and Timeouts 6 Register i/o 7 Reserved Table 2.1: Debugging level Bits 2.4. Configuring Driver/library Characteristics 13 boards. The syntax is as follows: Example 2.4.2 The Config-File Syntax config - options "" device - options "" . . . config - options "" device - options "" . . . You can have MAX BOARDS GPIB-cards in your PC1. Each config section begins the definition for devices connected to this board. The first config will refer to /dev/gpib0, the second to /dev/gpib1 and so on. Device Names consists of Letters and numbers and must begin with a letter. Example: You have two gpib-boards in your computer one at 2c0h (default) and one at 3c0 with interrupt 10 and 11. A scope has been connected to the first board with GPIB adress 7 and a DVM has been connected to the second board. Your config file will look like Example 2.4.3 A sample Config File config - base=0x2c0 irq=11 "" device - name=scope pad=7 "" config - base=0x3c0 irq=10 "" device - name=dvm pad=3 "" * The 'name' and the 'pad' option are required. The EOS modes can be specified for each device seperately. This will be useful for situations where different devices with different fixed-eos handling are used on the same bus. The configuration provides an initialization string per device this string will be send to the device if ibfind() is called. There are some other useful options look at ./util/template/gpib.conf.dist for ex1The default of maximal 4 GPIB boards should be sufficient 14 Chapter 2. Installing the Software amples. You can have one master device per GPIB-bus (Usually the GPIB-Adapter) To perform low level board commands to the whole bus this device must be configured as controller. You can configure this special device with one devicefg entry while setting the master flag on this configuration. Note that only one device on the bus can be the controller at the same time. 2.4.3 Using ibconf If TCL/Tk is installed on your system you can use the GPIB configuration utility to simplify the configuration process. The utility program comes with the Linux-GPIB Package in ./applications/ibconf. With ibconf it is possible to configure the GPIB Library software characteristics in a comfortable way without editing the /etc/gpib.conf file directly. Main Menu Status Bar Button Bar Devices Figure 2.1: The ibconf program With ibconf you can change old entrys or add new device entrys to the configuration. The Board characteristics can also be changed. Figure ?? shows the layout of ibconf main dialog, on the left side you'll see a listbox with the configured device entrys a button bar on the right side provides the basic editing functions as adding new, deleting or configuring old devices. The Board characteristics configuration dialog can be reached within the 'Boards' pulldown-menu. The Driver Module 3.1 Special Configurations The users of GPIB will mostly be satisfied if strings can be transfered over the bus. This strings are usually not very large (a few bytes). One exeption are devices with large data buffers (as scopes or scanners etc). Reading or writing this buffers will consume some more time as single byte transfer does. Use DMA Transfer Mode will speed up this. The problem with DMA Transfer under Linux is the continous Memory block that you need for this transfer, it has to be aligned to a page boundary and must be in the lower 16M of System Memory. For drivers compiled into the kernel this is not a big problem as this requirements could be satisfied at boot time. A Module runs after the kernel has been loaded into the memory so there is no guarantee that memory pages you can get from kernel are located below 16M. If you have more than 16Mb or if you use the module with kernels !1.3.xx the dynamic DMA memory allocation mechanism often fails because the memory gets more and more fragmented. If you see error messages like 'Can't get memory Pages' in /usr/adm/messages this is a sign for this problem. In this case you should set the dma-bufzize option in /etc/gpib.conf (or using ibconf). The value has to be a multiple of 1024. With this option set a static buffer is allocated only once at board initialization, so the problem of memory fragmentation should disappear. 3.2 Testing the Configuration with ibchk For a simple error check run util/ibchk. ibchk will test your Configuration against the Hardware preset board characteristics and reports useful error messages if something is going wrong. Ibchk looks if the device file has been created with the correct major number or if a gpib board is present at the desired base adress, it looks for reused interrupts or dma channels and reports any errors with suggestions to fix them. Since ibchk doesn't know anything about your GPIB Bus Configuration, your device setups can't be tested 15 16 Chapter 3. The Driver Module MSB LSB 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r r r S S S S S r r r P P P P P Table 3.1: Minor Number Bits (P=Sad,S=Sad,r=reserved) with ibchk. Ibchk is not a program that should be used as programming example as it looks very deep into the driver specialities to do its job. 3.3 Testing the Library This is your task because I don't know anything about your devices connected to your gpib. I added a sample lib/ibtest.c you can change it for your devices. If you build ibsh you can do this via tcl. Look at ibsh/demos/ibtest.tcl for example. 8 Note: Realize that the GPIB driver used with the GPIB library serves not as a usual character driver since all operations are done via ioctl calls. A User Program need to be linked to the GPIB Library if you want to use the config file Mechanism. 3.4 Using the VFS Interface The driver module provides a simple Mechanism to send or receive bytes to or from the bus via normal read/write operations. In this case where simple i/o is sufficient the driver can be used as normal character driver. To use the full functionality of the driver it is recommended to use the GPIB-Library for your application programs. In VFS-mode the driver automatically initializes the Bus for transfer and implicitely set up the device addresses decoding the MINOR number of the device special file. If you want to use the VFS mode you have to create one device special for each device connected to the bus using the mknod command. It would be useful to create an own subdirectory within /dev, for example /dev/GPIB. Example 3.4 shows how to create the inode files for three imaginary devices one called "tektronix604" with PAD=7, one called "counter" with PAD=2 and one called "dvm" with PAD=5. To access this devices you can simply use shell commands as shown in the Example or you can use the read() or write() C-Library calls. 3.5. Multiprocessing 17 Example 3.4.1 Creating device specials for VFS Mode mknod /dev/GPIB/tektronix604 c 31 7 mknod /dev/GPIB/counter c 31 2 mknod /dev/GPIB/dvm c 31 5 echo "D1Ready" ?/dev/GPIB/dvm Currently the VFS Mode is under construction so features as setting EOS modes and issueing commands to the bus via VFS are not possible. 3.5 Multiprocessing While sending or recieving commands, the bus system runs through different states to distinguish between the different phases of the transfer. A running transfer can't be interrupted until the bus reaches it's initial state because the usual TLC's cannot save the bus state on a exeptional condition. So it's the software's task to pay attention in which state the bus transfer can be interrupted to give other processes a chance to make their transfers. The linux-GPIB driver is capable to share the bus between different processes on a percommand mechanism. That means that each request is queued but one command can be transferred at the same time and other processes must wait for its completion. For the linux-GPIB programmer that means that he has to keep the transfers as short as possible if he want to have the Multiprocessing feeling. 18 Chapter 3. The Driver Module Using the GPIB Library 4.1 What is goin' on behind the scenes? From User's Side of View GPIB is a simple thing: You have some devices as Scopes, Digital Multimeters, Counters and so on. Each of this device has a Plug on the rear side of it's case and is labeled to understand ieee488 commands. You buy one of this expensive Cables and plug it from device to computer - and ready to go (You think). Yes from Hardware side (outside the devices) this seems to be simple but to write Programs using GPIB you have to know more about what is going on between the computer and the devices. I think we should not explain all the Lines of the cables in detail but it's not wrong to know a little about what's going on behind this plugs. As mentioned in each device's Manual (i bet) you can select a GPIB-Adress for each device. This 'device adress' has to be unique for the bus. With this adress the bus-controller can find the device on the bus. The GPIB bus can connenct many devices that could communicate independently over the bus. A device that has the controller capability could take control over the bus and send commands to the devices. Only one device can be the controller at the same time. The dataflow direction is controlled by the Talker and the Listener States of the Devices. More than one device could be in listener or in talker state. If the Controller want to write out some bytes to a device it sets the device in listener state and itself to talker state, then the desired bytes are written over the bus (See Figure 4.1). For read operations the controller will become the listener and the device will be adressed as talker, then the bytes will be read (See Figure 4.2). Similar to SCSI, each device (that means the interface of the device) can be in different states during the transmission Process. Some states are controlled by some Lines on the Bus (ATN,REN,IFC,SRQ,RQS) and some states could be reached with commands on the 19 20 Chapter 4. Using the GPIB Library GPIB-Bus Device 1 addressed as Listener Controller, addressed as Talker Figure 4.1: States During Write Operation Data-Bus (D0:::D7). IFC (Interface Clear) resets all device-controllers to its initial State (Similar to a Chip Reset), this message will be send on initialization process of the system-controller. ATN (Attention) and REN (Remote Enable) are used to signal a bus action to the devicecontrollers, this line is driven by the system-controller whenever you apply a command on the bus. SRQ (Service Request) and RQS (Request Service) are used from device-controller to signal a special state to the system-controller, this message usualy will be send if the device has done the requested operation. The so called multiline Messages (that means commands over the Data Lines while ATN is active) are grouped in unadressed Commands (Comands for all Devices on the Bus) and adressed Commands (for one or more specified Device). Unadressed Commands are DCL (Device Clear), LLO (Local Lockout), PPU (parallel Unconfigure), SPD (Serial Poll Disable) and SPE (Serial Poll Enable). Adressed commands are GET (Group Execute Trigger), GTL (go to Local), PPC (Parallel Poll Configure), SDC (Selected Device Clear) and TCT (take Control). The Adresses itself will be send as special Multiline Messages. All devices on the bus can be adressed as Talker and as Listener. Each Transfer on the bus in adressed mode (usual with computer controlled GPIB) needs to set the Talker and Listener Adresses properly depending on which Direction the Transfer will be made. As soon as ATN is inactive every Byte on the bus is interpreted as valid Data. The additional Messages UNL (Unlisten) and 4.1. What is goin' on behind the scenes? 21 GPIB-Bus Device 1 addressed Controller, addressed as Talker as Listener Figure 4.2: States During Read Operation UNT (Untalk) reset the desired Listener or Talker to its normal state. Imagine you want to send a simple string "ABC" to your device, how is it done by the controller ? The controller will activate ATN and send the Listener Adress of the desired device(s) then it sends its own Talker Adress. Now ATN will be deactivated and the data Bytes "ABC" will go over the bus. To finish the transmission the EOI Line will be activated. Now the controller can send the next string to the device or send UNL and UNT to unlisten the device. As i concealed the controller has to setup the command Phase with IFC and REN first. Lets show this Transfer on a nice Diagram: The following Diagram shows how multiline Messages are coded on the eight Data Lines (a X means any Bit 0 or 1). You will not need this for Programming with the GPIB Library but it will be helpful for advanced GPIB-Programmers or for finding bugs in the driver sourcecode. 22 Chapter 4. Using the GPIB Library ATN command EOI 1 0 ATN starts the 'Command Phase' 1 UNL 0 Send Unlisten 1 LAD1 0 Adress first Device as Listener 1 LAD2 0 Adress second Device as Listener ... 1 LADn 0 Adress Device n as Listener 1 TAD 0 Adress One Device as Talker 0 DAB1 0 Deactivate ATN, send first Data Byte 0 DAB2 0 Send 2nd Data Byte ... 0 DABn 1 Send last Data Byte together with EOI 0 EOS Send EOS Message Table 4.1: Bus Commands during Transfer 4.2 How The Library is organized 4.2.1 Compatibility with NI-488.2 TMLibrary The essential GPIB-Bus Handling functions should be compatible to NI-488.2TMLibrary calls. Porting of User Programs from DOS to Linuxshould be simple. A short overview shows which functions are present in both librarys. 4.2. How The Library is organized 23 Message Mnemonic ATN DIO-Lines Bit 7654 3210 Attention ATN 1 XXXX XXXX Data Byte DAB 0 DDDD DDDD Device Clear DCL 1 X001 0100 End of String EOS 0 EEEE EEEE Group Execute Trigger GET 1 X000 1000 Go To Local GTL 1 X000 0001 Local Lock out LLO 1 X001 0001 Talker Adress TAD 1 X10T TTTT Listener Adress LAD 1 X01L LLLL Par. Poll Configure PPC 1 X000 0101 Par. Poll Enable PPE 1 X110 SPPP Par. Poll Disable PPD 1 X111 DDDD Par. Poll Unconfigure PPU 1 X001 0101 Selected Dev. Clear SDC 1 X000 0100 Ser. Poll Disable SPD 1 X001 1001 Ser. Poll Enable SPE 1 X001 1000 Take Control TCT 1 X000 1001 Unlisten UNL 1 X011 1111 Untalk UNT 1 X101 1111 Table 4.2: Multiline Messages 24 Chapter 4. Using the GPIB Library Function NI-488.2 Library LinuxGPIB Library ibbna ffl ibcac ffl ffl ibclr ffl ffl ibcmd ffl ffl ibcmda ffl ibconfig not identical ffl ibdev ffl ibdma ffl ibeos ffl ffl ibeot ffl ffl ibevent ffl ibfind ffl ffl ibFindDevIndex ffl ibgts ffl ffl ibist ffl iblines ffl ffl ibln ffl ibloc ffl ibonl ffl ffl ibpad ffl ffl ibParseConfigFile ffl ibPutErrlog ffl ibPutErrMsg ffl ibpct ffl ibppc ffl ibrd ffl ffl ibrda ffl ibrdf ffl 4.2. How The Library is organized 25 Function NI-488.2 Library LinuxGPIB Library ibrpp ffl ffl ibrsc ffl ibrsp ffl ffl ibrsv ffl ffl ibsad ffl ffl ibsic ffl ffl ibsre ffl ffl ibsrq ffl ibstop ffl ibtmo ffl ffl ibtrap ffl ibtrg ffl ffl ibwait ffl ffl ibwrt ffl ffl ibwrta ffl ibwrtf ffl Due to the fact that You're using a Unix compatible operating system with all its advantages and due to the different architecture of the driver there are some incompatibilites in the functionality of the Driver/Library that should be mentioned1. 7 NI-488TMuses decl.h as header file to its applications. Linux-GPIB uses ib.h 7 NI-488TMautomatically performs IFC, REN, and LLO to the bus when the first device function is called. Linux-GPIB performs this commands only for the first call to ibfind() and only for the first process using the bus (If you don't want any of this commands at init time you can configure this in /etc/gpib.conf ). 7 NI-488TMcan be configured so thet the board will request to be the Controller-InCharge whenever a device function is called. Linux-GPIB always assumes the board is currently Controller-In-Charge. 7 if(ibfind,"gpib0") ! 0) f...g will work for NI-488 (since MS-DOS has 16 bit integers), but will not work with Linux-GPIB. You should use if(ibfind,"gpib0") & ERR ) f...g instead. 1Thanks to Glenn! 26 Chapter 4. Using the GPIB Library 4.2.2 Device Management Each device connected to the bus must have a unique GPIB-Adress set. This can be done via the Front Panel Buttons or rear panel DIP-Switch depending on the Device. Refer to the 'Selecting GPIB Adress' Section of Your Device's User Manual. The Configuration File for the GPIB Library assigns your Devices with the Interface board. You must give each Device an unique name wich identifies the Device and set The Primary Adress for this Device. If you make a call to ibfind first time the following actions will be done by ibfind automagically: ffl ibfind looks if the IB CONFIG Environment is set and parses the configuration file. If is not set it parses the default config file (/etc/gpib.conf). ffl Each device found in the config file will be added to the device descriptor table. ffl The Error Logging File will be opened (see Error Logging) ffl The device driver (e.g. /dev/gpib0) will be opened and the configuration of the driver will be made ( set irq,dma and base-adress). ffl The driver will be set in Active State via ibonl. 4.2.3 Error Logging Every time a library call results to an error, a Message is logged to the Errorloging file specified in the errlog variable. If no errlog variable has been specified in the config file Error Logging will be done to stderr. If you work with X11 you could use xconsole to Log your Errors set the errlog variable to /dev/console for this. Each Message has the following format: routine : [time](device) ! state ? error !explanation? If the error occurs while no device is active device is empty. state is a combination of states as described below. A verbose explanation of the error follows the message. With this feature a error can be easyly backtraced. For example means that ibwrt failed while performing the ioctl to the device (in ibBoardFunc) the reason of the error is a not responding device (no listener). 4.2. How The Library is organized 27 Example 4.2.1 Error Messages dvwrt :[Sun Sep 11 15:41:02 1994](-)! ERR CMPL CIC TACS? ENOL !No Listener? ibBoardFunc :[Sun Sep 11 15:41:02 1994](-)! ERR CMPL CIC TACS? ENOL !No Listener? 4.2.4 Device Status and Error Codes As the Driver and the Library should be NI-488.2TMcompatible, two global variables exists for driver state and error reporting. An additional variable carries information about the number of bytes transferred on a I/O operation. int ibsta; int iberr; int ibcnt; 4.2.4.1 Status Word The Meaning of the Status Bits shows the following table: State Description ERR Function Terminated on error TIMO Time Limit on I/O or wait function exceeded END EOI Terminated ibrd SRQI SRQ is asserted CMPL I/O is complete CIC Controller in Charge ATN Attention is asserted TACS Board is adressed as TALKER LACS Board is adressed as LISTENER For detailed Information on these codes See Ni-488.2TMSoftware Reference Manual for MSDOS (Part Number 320282-01) 28 Chapter 4. Using the GPIB Library 4.2.4.2 Error Codes Error Code Description EDVR system error ECIC not CIC ENOL no listeners EADR CIC and not addressed before I/O EARG bad argument to function call ESAC not SAC EABO I/O operation was aborted ENEB non-existent board (GPIB interface offline) EDMA DMA hardware error detected EBTO DMA hardware uP bus timeout EOIP new I/O attempted with old I/O in progress ECAP no capability for intended opeation EFSO file system operation error EOWN shareable board exclusively owned EBUS bus error ESTB lost serial poll bytes ESRQ SRQ stuck on ECFG \Lambda Config file not found EPAR \Lambda Parse Error in Config ETAB \Lambda Table Overflow ENSD \Lambda Device not found in Configuration \Lambda = Linux GPIB Library only If iberr is EDVR ibcnt is set to errno and further Explanation is written to Error Logging file. For detailed Information on these codes See Ni-488.2TMSoftware Reference Manual for MSDOS (Part Number 320282-01) 4.3 Getting Started The simplest task using a GPIB device is sending or receiving strings over the bus for example to setup device characteristics or receiving measurements from the device. For easy understanding let us imagine a virtual Digital Voltmeter (DVM) that understands commands to set the Voltage Range and returns a measurement result on readout. Program 4.3.1 shows how such task could be solved using Device-Level Functions. 4.3. Getting Started 29 Example 4.3.1 A Simple C-Program #include !stdio.h? #include !ib.h? main()- int dvm; /* The Unit descriptor of the device */ char cmd[80]; /* A buffer for the string */ /* get device from configuration */ if( (dvm=ibfind("dvm")) & ERR )- printf("Can't find DVM!"n"); exit(1); "" /* Clear the Device */ if( ibclr(dvm) & ERR )- printf("Clear Error!"n"); exit(1); "" /* Now Setup a few things */ strcpy(cmd,"D0 R1 S0"); if( ibwrt(dvm,cmd,strlen(cmd)) & ERR )- printf("Write Error!"n"); exit(1); "" /* now Read back the result */ if( ibrd(dvm,cmd,79) & ERR )- printf("Read Error!"n"); exit(1); "" /* print out result */ printf(""n Result=%s",cmd); "" 30 Chapter 4. Using the GPIB Library 4.4 Using Remote GPIB 4.4.1 Introduction The basic idea of Remote-GPIB (rGPIB) was to design a Virtual Extension to the Bus using a usual Network Protocol. With rGPIB it should be possible to write or read from devices that are connected to another machine's GPIB. The user of both the client and the server should not need to get familiar with programming all the network stuff. The rGPIB feature could be used for testing application on a foreign machine without having a GPIB-board in the local machine or for building up simple test systems for sensoric environments without any need of expensive hard and software. Additionally more than one client can request one machine's GPIB to share the devices on the bus over the network. Programming with rGPIB should be very simple as the networking code uses the lower transport levels of the GPIB-Library directly. In other words the changes to existing programs are minimal. The ibsh interpreter can be used as well for distributed GPIB applications with minimal changes to the TCL/TK code First i will explain some basic concepts about rGPIB: The requests are given over the network to the target host, the other host takes the requests and passes it to the GPIB the responses are routed back to the client machine. Figure 4.3 shows how the concept has been implemented. The GPIB Library contains the client-stubs to send the requests via RPC to the server. The server uses the GPIB library to send the requests to the GPIB. 4.4.1.1 Security Unfortunately the DES Encryption software is not availiable outside the US so that other algorithms must be used for the authentication protocol. For the first guess i use a normal AUTH UNIX RPC authentication what is easily possible to break through but for the normal use this should be sufficient. 4.4.2 Programming With rGPIB Programming with rGPIB should be as easy as programming a application without the networking support. The only exeption is that a new device naming scheme has been introduced to achieve the desired functionality. Device names now can contain the network name of the target machine for Example: Now a network unit descriptor is returned by ibfind(). Now the GPIB-Library routes requests to this descriptor automatically to the desired host's rGPIB server and the results 4.4. Using Remote GPIB 31 Example 4.4.1 Programming rGPIB int dev; dev = ibfind("beaver.chemie.fu-berlin.de:scope"); back to the client application. So from the Programmers point of view there is basically no difference between applications using the rGPIB and normal applications. 4.4.3 Configuring the Library for rGPIB Some new Configuration-Options are added to the Library configuration mechanism to provide a minimal security to the server. Hosts providing their GPIB over the network can be configured so that only certain hosts can send requests to the server. For this the busmaster entry contains a new option network that specifies a group of hosts or single hosts that are allowed to access the GPIB. Example 4.4.2 The configuration for network access device - name = gpib0 /* name of the bus should be compilant * to the usual conventions gpib0,gpib1... */ pad=0 sad=0 /* * This line denotes the device as busmaster * realize that only one device per board can be the busmaster */ master /* This Line specifies which clients can access the GPIB-Server * entrys are separated by colons, wildcards can be specified * to match more than one host * ( don't forget the last colon ) */ network *.chemie.fu-berlin.de:clausi: "" 32 Chapter 4. Using the GPIB Library Example 4.4.2 shows how the access mechanism can be configured. Wildcards (*) can be used to specify a whole group of hosts. The host entrys must be colon separated and the line must end with a colon. A single * means that access control is disabled. The client side should be configured to have a verbose host and domainname, check out hostname and domainname for this. 4.4.3.1 Important Notes Since the rGPIB feature uses RPC to comunicate with the server you need the RPC portmapper running on both the client and the server machine. Look at your /etc/rc.d/rc.inet2 uncomment de desired lines if necessary and reboot your system. Now rpcinfo -p localhost should show the portmapper running. The client and server stubs and the XDR files are generated automatically by the TIRPC rpc source generator that is included as binary in ./lib/utils the original sources can be obtained on sunsite (system/Network/sunacm/Netkit-B-0.05.tar.gz) 4.4. Using Remote GPIB 33 GPIB-Library GPIB-Library Server Stubs Server Stubs GPIB-LibraryClient Stubs Application host1 host2 host3 Figure 4.3: The distributed GPIB model 34 Chapter 4. Using the GPIB Library The Application Suite 5.1 What is ibsh? Usually writing nice applications with a graphical user interface (GUI) is a really hard job since a lot of X-Toolkit,Motif or plain X11 routines has to be learned before. Thanks to J.Ousterhout's TCL/Tk Language this is not necessary anymore since comfortable, nice and colorful applications can be written within a very short time in TCL/Tk. Depending on the complexity of the application, the code can be more and more integrated into the TCL/Tk interpreter that minimizes the redundancy of code. The Tk widget set is very powerful and the functionality grows with the number of availiable extensions. ibsh has been designed as a basic-TCL/Tk interpreter with the capability to load Modules (DLLs) dynamically at runtime1, this saves memory and speeds up the development of new modules. Each Module availiable with this package can be staticaly linked to ibsh alternatively. 2 The user could write Modules to handle special data types, calibrate data, support own hardware or whatever. The implementation of new modules should be very simple as only few changes to existing tcl-extensions are needed. The referencing of undefined symbols in the dll-modules is done automatically if the missing symbols are located in either libm.a,libc.a or libX11.a, if additional libraries are needed there is a simple control mechanism for explicit linking of desired libraries. ibsh comes along with several useful packages as basic data visualization extension kit as meters, dials, barcharts, turndials and a powerful plotting extension, a raster widget can be used as pixel display and if a soundcard or pcsnd driver is installed a sound extension can be used to signal exceptional conditions or whatever. With the basic functionality (without the Add-On Packages) of TCL/Tk a wide variety of applications can be made. The AddOn Packages make ibsh more scaleable, new modules can be tested without recompiling 1The GPIB extension is included by default of course. 2Yes I know there is a dynamic loading extension called tcldl but I think its usage is a little bit confusing expecially for beginners. So I designed my own dll extension. 35 36 Chapter 5. The Application Suite the whole package. Alternatively if needed, modules can be linked statically with ibsh at compilation time. 5.2 Using ibsh Due to the fact that ibsh is implemented on the top on the standard TCL/Tk interpreter you need not to learn a complete new language (assuming you're familiar with TCL/Tk). The GPIB commands are implemented as special command set: each gpib related command begins with gpib. A special extension is the capability to load modules at runtime so one need not to recompile ibsh if more extensions are desired. If ibsh has been installed correctly (with make install), dynamic loadable Modules will reside in /usr/local/lib/ibsh/modules, this can be changed editing the toplevel Makefile for ibsh. If no path has been specified on a module-loading command this path will be taken as default. 5.2.1 Module Loading Example 5.2.1 Examples for dynamic module loading with ibsh #!/usr/local/lib/ibsh -f # ## now load modules dll load Turndial dll load Meters .... # # turndial .t pack .t #end Example 5.2.1 shows how the two widget librarys 'Turndial' and 'Meters' can be loaded. While dll modules are loaded the loader looks for undefined symbols in the module and links some standard librarys automatically until all symbols have been resolved. To have access to this mechanism for each module an associative array exists with the same name 5.3. Writing Modules for ibsh 37 as the module that can be set to the library path and the library names. Example 5.2.2 Accessing the link mechanism #!/usr/local/lib/ibsh -f # ## now load modules set Mymodule(dll.libpath) ~:/usr/local/bin:/usr/mymodule/libs:. set Mymodule(dll.libs) "mylib1.a mylib2.a" dll load Mymodule Example 5.2.2 shows how new module specific librarys can be set to the desired path. Realize that using this feature will override the default settings, under some circumstances it could be neccessary to bind the standard librarys libm.a and libX11.a explicitely. 5.3 Writing Modules for ibsh To write own modules for ibsh you should get familiar with the TCL C-Interface Mechanism first. The ibsh-specific code consists of two additional routines one Module init() routine that hooks own TCL-commands into ibsh's gearbox and one Module cleanup() that destroys the command bindings. Example 5.3.1 shows the code for a really dumb sample module that can be loaded with ibsh. Realize that the name of the Module functions and the name of the dll file must be the same. 5.3.1 Some modules included I added some useful modules to the package by default and I think it will be very useful for lab-related application programs. The following list should give some more information about some extension modules: Graph.dll Contains XY-graph plots and barcharts and hypertext widgets, I think this will be the most used module for experimentalists. Meters.dll A Meter Widget and stripcharts. Useful where data should be observed on a short view. 38 Chapter 5. The Application Suite Example 5.3.1 A simple ibsh module /* * * Module.c * * Sample Module for ibsh * * (c) 1995 C. Schroeter (clausi@chemie.fu-berlin.de) * * */ #include !stdio.h? #include !stdlib.h? #include !string.h? #include !tcl.h? int Module.init ( Tcl.Interp *interp )- extern int MyModuleCmd .ANSI.ARGS.(( ClientData clientData, Tcl.Interp *interp, int argc, char *argv[] )); Tcl.CreateCommand(interp,"mycmd",MyModuleCmd, (ClientData) NULL, (Tcl.CmdDeleteProc *) NULL ); return TCL.OK; "" int Module.cleanup ( Tcl.Interp *interp )- Tcl.DeleteCommand(interp,"mycmd"); "" int MyModuleCmd ( ClientData clientData, Tcl.Interp *interp, int argc, char *argv[] ) - printf("MyModuleCmd invoked !"n"); return TCL.OK; "" 5.4. Configuration 39 Turndial.dll A circular dial widget (volume knob), nice and handy. Useful where screen space is a factor. Raster.dll A pixel-oriented raster display. Could be useful displaying pictures (this won't be necessary in Tk4.0) Sound.dll A quick hack to make events audible. Under some cicumstances this can be useful (process control). It would be nice if there would be a vector-data processing module so that data could be manipulated within the application program :-). 5.4 Configuration ibsh can be configured at compiling time via the toplevel Makefile in ./applications/ibsh to search its modules in another path or to link modules statically if they're needed very often. For Details see the Makefile in ./applications/ibsh . 40 Chapter 5. The Application Suite Library Reference A.1 Management Functions ud = ibfind(char *name) Returns a Unit Descriptor that will be assigned to the device designated by name.The device name can be specified in the form host:device to get a remote unit descriptor using the rGPIB system. ibonl(int ud,int bool) Sets the board 'online' if called with bool ? 0 and closes the driver if called with 0. If device Functions are used this routine will be called implicitely with the first call to ibfind(). ibsic(int ud) Sends the IFC (interface clear) Message to the controller. Sets the Board to active state. This routine is called implicitely if is a device descriptor and set-ifc is enabled. ibsre(int ud,int bool) Send Remote Enable Message (assert the REN line). ibeos(int ud, int eos) Sets the EOS byte. This command does not overwrite the EOSbyte set in the library configuration. ibtmo(int ud,int tmo) Set the default timeout value. ibpad(int ud,int pad) Set the controller's primary address. ibsad(int ud,int sad) Set the controller's Secondary address 1. ibeot(int ud,int bool) Switch EOT Message on or off. Normally EOI is sent out with the last byte this can be disabled using ibeot() 1Not supported with HP boards 41 42 Appendix A. Library Reference A.2 Device Functions ibwrt(int ud,char *msg,int nbytes) Writes the Message to the bus. The device and the controller are addressed implicitely, that means set to the desired talker/listener states before the message will be sent. ibrd(int ud,char *buf,int nbytes) Get a string from the bus and store it into buffer. Implicit addressing is done as on ibwrt() ibclr(int ud) Sends a 'Device Clear' Message to the device. ibrpp(int ud,char *ppr) Request Parrallel Poll, the poll byte is stored in ppr. ibwait(int ud,int mask) Wait for event masked with mask. Normally one of SRQI or RQS together with TIMO. ibrsp(int ud,char *spr) Request Serial Poll. The poll byte is stored in spr. ibtrg(int ud) Send a device trigger message to the device. A.3 Bus Level Functions ibcmd(int ud,char *cmd,int nbytes) Sends a message to the bus while ATN is asserted. ibwrt(int ud,char *msg,int nbytes) Sends a message without implicit addressing. The difference between a device descriptor and a bus-level descriptor is that no implicid addressing is done. A virtual device name that has the master flag set will map to bus-level descriptors. ibrd(int ud,char *buf,int nbytes) Reads bytes from the bus without imlicit addressing. ibcac(int ud,int bool) Become Active Controller. Sends TCS or TCA Message. This will set the ATN line to true. ibgts(int ud,int bool) Go to standby. This will release the ATN line. ibrsv(int ud,int v) Request Service. Sends out serial poll status. If bit 7 is set to 1 the SRQ line is pulled true. drivers/000077500000000000000000000000001507046215500125415ustar00rootroot00000000000000drivers/Makefile.am000066400000000000000000000025441507046215500146020ustar00rootroot00000000000000# driver/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. install-data-hook: gpib.conf $(DESTDIR)/dev/gpib0: $(INSTALL) -d $(DESTDIR)/dev for i in `seq 0 15`; \ do \ mknod -m u=rw,g=rw,o= $(DESTDIR)/dev/gpib$${i} c $(IBMAJOR) $${i} || exit 1; \ chown root:gpib $(DESTDIR)/dev/gpib$${i}; \ done .PHONY : device_files_install device_files_install: $(DESTDIR)/dev/gpib0 @if [ ! -c $(DESTDIR)/dev/gpib0 ]; then \ if [ -a $(DESTDIR)/dev/gpib0 ]; then \ echo "A file or directory called /dev/gpib0 exists but it is not" \ "a character device. Delete or move it and try again."; \ exit 1; \ fi; \ fi @ls -l $(DESTDIR)/dev/gpib0 | grep -q "$(IBMAJOR)"; \ if [ $$? != 0 ]; then \ echo "$(DESTDIR)/dev/gpib0 has the wrong major number. " \ "Delete your $(DESTDIR)/dev/gpibX files and try again."; \ exit 1; \ fi #should move this to util/templates Makefile.am when it exists .PHONY : gpib.conf gpib.conf: test -e $(DESTDIR)$(sysconfdir)/gpib.conf || \ $(INSTALL_DATA) -D $(top_srcdir)/util/templates/gpib.conf $(DESTDIR)$(sysconfdir)/gpib.conf etc/000077500000000000000000000000001507046215500116365ustar00rootroot00000000000000etc/pcmcia/000077500000000000000000000000001507046215500130725ustar00rootroot00000000000000etc/pcmcia/linux-gpib-pcmcia000077500000000000000000000011051507046215500163250ustar00rootroot00000000000000#! /bin/sh if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi # Get device attributes get_info $DEVICE # Load site-specific settings start_fn () { return; } stop_fn () { return; } . $0.opts case "$ACTION" in 'start') export PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH; # you might need to change --minor to match /etc/gpib.conf setting gpib_config --minor 0 start_fn $DEVICE ;; 'stop') stop_fn $DEVICE ;; 'check') ;; 'cksum') ;; 'restart') ;; 'suspend'|'resume') ;; *) usage ;; esac exit 0 etc/pcmcia/linux-gpib-pcmcia.conf000066400000000000000000000007021507046215500172500ustar00rootroot00000000000000 device "ines_gpib_cs" class "linux-gpib-pcmcia" module "ines_gpib" card "Ines GPIB for PCMCIA" manfid 0x01b4, 0x4730 bind "ines_gpib_cs" device "cb_gpib_cs" class "linux-gpib-pcmcia" module "cb7210" card "Measurement Computing PCMCIA-GPIB" manfid 0x01c5, 0x0005 bind "cb_gpib_cs" device "ni_gpib_cs" class "linux-gpib-pcmcia" module "tnt4882" card "National Instruments PCMCIA GPIB" manfid 0x010b, 0x4882 bind "ni_gpib_cs" etc/pcmcia/linux-gpib-pcmcia.opts000066400000000000000000000000021507046215500173010ustar00rootroot00000000000000 examples/000077500000000000000000000000001507046215500127015ustar00rootroot00000000000000examples/Makefile.am000066400000000000000000000021331507046215500147340ustar00rootroot00000000000000 noinst_PROGRAMS = master_read_to_file master_write_from_file \ slave_read_to_file slave_write_from_file bin_PROGRAMS = ibtest ibterm findlisteners ibtest_SOURCES = ibtest.c ibtest_CFLAGS = $(LIBGPIB_CFLAGS) ibtest_LDADD = $(LIBGPIB_LDFLAGS) ibterm_SOURCES = ibterm.c ibterm_CFLAGS = $(LIBGPIB_CFLAGS) $(LIB_READLINE_CFLAGS) ibterm_LDADD = $(LIBGPIB_LDFLAGS) $(LIB_READLINE_LDFLAGS) findlisteners_SOURCES = findlisteners.c findlisteners_CFLAGS = $(LIBGPIB_CFLAGS) findlisteners_LDADD = $(LIBGPIB_LDFLAGS) master_read_to_file_SOURCES = master_read_to_file.c master_read_to_file_CFLAGS = $(LIBGPIB_CFLAGS) master_read_to_file_LDADD = $(LIBGPIB_LDFLAGS) master_write_from_file_SOURCES = master_write_from_file.c master_write_from_file_CFLAGS = $(LIBGPIB_CFLAGS) master_write_from_file_LDADD = $(LIBGPIB_LDFLAGS) slave_read_to_file_SOURCES = slave_read_to_file.c slave_read_to_file_CFLAGS = $(LIBGPIB_CFLAGS) slave_read_to_file_LDADD = $(LIBGPIB_LDFLAGS) slave_write_from_file_SOURCES = slave_write_from_file.c slave_write_from_file_CFLAGS = $(LIBGPIB_CFLAGS) slave_write_from_file_LDADD = $(LIBGPIB_LDFLAGS) examples/findlisteners.c000066400000000000000000000105201507046215500157140ustar00rootroot00000000000000/*************************************************************************** findlisteners.c ------------------ An example program to list the devices connected to a board. copyright : (C) 2020 by Dave Penkler email : dpenkler@gmail.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include static char* myProg; static void myError(int erc, char * mess) { int sys_errno = ThreadIbcnt(); fprintf(stderr,"%s: error: %s", myProg, mess); fprintf(stderr," - %s\n", gpib_error_string(erc)); if (erc == EDVR) fprintf(stderr," system error: %s\n",strerror(sys_errno)); exit(0); } int findListeners(int ud, int from, int to) { int ibsta, erc, pad, n = 0; short stat; int bpad; /* board primary address */ int timeout; /* old timeoout */ if (ibask(ud, IbaPAD, &bpad) & ERR) /* Get board primary address */ myError(ThreadIberr(), "ibask IbaPAD failed"); if (ibask(ud, IbaTMO, &timeout) & ERR) /* Remember old timeout */ myError(ThreadIberr(), "ibask IbaTMO failed"); if (ibtmo(ud, T30ms) & ERR) /* Set a shortish timeout for now */ myError(ThreadIberr(), "ibtmo failed"); for (pad=from; pad<=to; pad++) { if (ibln(ud, pad, NO_SAD, &stat) & ERR) { /* check for listener at pad */ ibsta = ThreadIbsta(); erc = ThreadIberr(); ibtmo(ud,timeout); /* Restore old timeout */ if ((erc == ENOL) || (ibsta & TIMO)) { /* No listeners on the bus */ return(0); } else { myError(erc, "unexpected error"); } } else if (stat) { printf("Listener at pad %2d", pad); if (pad == bpad) printf(" (board) "); else n++; printf("\n"); } } ibtmo(ud,timeout); /* Restore old timeout */ return n; } void usage(int brief) { fprintf(stderr,"Usage: %s [-h] [-d ] [[-m ] | ]\n", myProg); if (brief) exit(0); fprintf(stderr," Where the optional is the name of the board from gpib.conf\n"); fprintf(stderr," If the is not specified all pads are scanned.\n"); fprintf(stderr," Default is 0\n"); fprintf(stderr," If a is specified the is ignored.\n"); exit(0); } int main(int argc, char ** argv) { int n; char *board; int ud, device; int gotdev=0; int minor = 0; int gotmin = 0; int from = 0; int to = 30; int c; myProg = argv[0]; while ((c = getopt (argc, argv, "m:d:h")) != -1) { switch (c) { case 'm': minor = atoi(optarg); gotmin++; break; case 'd': device = atoi(optarg); gotdev++; break; case 'h': usage(0); break; default: usage(0); } } if (gotdev) { if (device < 0 || device > 30) { fprintf(stderr,"%s: invalid pad specified 0 <= pad <= 30\n",myProg); exit(1); } else { from = to = device; } } if (optind < argc) { gotmin = 0; /* ignore minor if one was specified */ board = argv[optind]; ud = ibfind(board); if (ud < 0) { fprintf(stderr, "%s: can't find board \"%s\"\n",myProg, board); exit(0); } if (ibask(ud,IbaBNA,&minor) & ERR) /* get minor of board */ myError(ThreadIberr(), "ibask ibaBNA failed"); } else { gotmin++; ud = minor; } if (gotdev) printf("%s: Scanning pad %d", myProg, device); else printf("%s: Scanning pads from %d to %d", myProg, from, to); if (gotmin) printf(" on minor %d\n", minor); else printf(" on board \"%s\" minor %d\n", board, minor); n = findListeners(ud, from, to); printf("%s: %d device%s found.\n",myProg, n, (n==1) ? "" : "s"); exit(n); /* tell invoking script, if any, how many devices were found */ } examples/ibterm.c000066400000000000000000000263501507046215500143350ustar00rootroot00000000000000/*************************************************************************** ibterm.c ------------------ Another example program which uses the linux gpib C library: An interactive terminal program for sending commands to an instrument and printing its response. copyright : (C) 2013 by Dave Penkler email : dpenkler@gmail.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #ifdef READLINE #include #include #endif #include "gpib/ib.h" #define PROMPT "ibterm>" #define DEVICE_BUFFER_SIZE 2048 #define false 0 #define true 1 /* Global variable declarations */ static char * mPrompt = PROMPT; // Prompt string static char * mProg; // Programme name static char * mHist = (char *)NULL; // History filename pointer static int mAutoRead = true; // Automatically read from device static int mHex = false; // Force hex output flag static int mUnTUnL = false; // send untalk/unlisten static int devdesc = -1; // device descriptor static int minor = 0; // gpib driver major static int pad = -1; // device primary bus address static int sad = 0; // device secondary bus address static int send_eoi = 1; // Assert eoi with last byte in ibwrt static int eos_mode = 0; // No end of string processing static int timeout = 10; // 300 milliseconds static char errmes[256]; // error message buffer static const char * help_string = "ibterm help info -\n" "\nSummary:\n" "An interactive terminal program for sending commands to a device over an \n" "IEEE488 general purpose instrument bus and printing the responses.\n" "\nOptions:\n" " -d (required, no default)\n" " -m (optional, default=0)\n" " -s (optional, default=0)\n" " -i (optional, default=1)\n" " -e (optional, default=0)\n" " -r (optional, default=0)\n" " -b (optional, default=0)\n" " -x (optional, default=0)\n" " -t (optional, default=10 i.e. 300milliseconds)\n" " -p (optional, default=\"" PROMPT "\")\n" #ifdef READLINE " -f (optional, default=\".ibterm_hist_\")\n" #endif " -u Send Untalk/Unlisten after each read and write\n" " -N No automatic read on device, enter return at prompt to read.\n" " -X forces hexadecimal output.\n" " -h prints this help info and exits.\n" "\nOperation:\n" " loop:\n" " Prompt on stdout\n" " Read a line of text from stdin\n" " Write the text (if any) to the device at pad\n" " If -N is not set, or no text was entered\n" " Attempt to read response from the device\n" " If no response is received before timeout go to loop\n" " else print the response on stdout\n" " Go back to loop.\n" "\nNotes:\n" " To quit the programme enter the EOF character (Ctrl-d) at the prompt.\n" " For interactivity, timeout should not be greater than 13 i.e. 10 secs.\n" " The timeout values are documented under the ibtmo() entry of the \n" " section Linux-GPIB Reference: http://linux-gpib.sourceforge.net/doc_html\n" " A device read can always be triggered by hitting at the prompt.\n" " Interrupting the programme while reading from the device may cause hangs.\n" #ifdef READLINE "\nAlso:\n" " See the readline(3) manpage for editing input and searching history.\n" #endif ; static const char * usage_options = " -d pad \\\n" " [-m minor] [-s sad] [-i eoi] [-e eos]" " [-r reos] [-b bin] [-x xeos] \\\n" " [-t timeout] [-p prompt]" #ifdef READLINE " [-f history_file]" #endif " [-u] [-N] [-X] [-h]\n"; #define EMES(var) fputs(var,stderr) static void abend(const char * mess) { EMES(mess); EMES(mProg); EMES(": Aborted\n"); if (devdesc >= 0) ibonl(devdesc,0); exit(1); } static void usage(int abort) { EMES("\nUsage:\n "); EMES(mProg); EMES(usage_options); if (abort) { sprintf(errmes,"Try '%s -h' for more information.\n",mProg); abend(errmes); } exit(1); } /* Print buffer contents in parallel hexadecimal and ASCII */ static const char * hexdig = "0123456789ABCDEF"; static char * template = "12345678 | | " " | "; void prhex(unsigned char * buf, int len) { int i,j,k,l,m; char *c,ob[80]; for (i=0;i>= 4,j++) *--c = hexdig[m & 0xf]; } k += 1 + 2*((i % 8) == 0); ob[k++] = hexdig[(buf[i] & 0xf0)>>4]; ob[k++] = hexdig[(buf[i] & 0xf)]; ob[l++] = (buf[i] < 32 || buf[i] > 127) ? ' ' : buf[i]; if (k == 60) { puts(ob); k = 0; } } if (k) puts(ob); } #define CHECK_FLAG(var, flag) \ if (var != 0 && var != 1) abend(#flag " flag must be 1 or 0.\n"); #define CHECK_ADDR(var) \ if (var < 0 || var > 30) abend(#var " must be between 0 and 30.\n"); #define CHECK_SADDR(var) \ if (var < 0x60 || var > 0x7f) abend("linux-gpib requires the secondary address to be offset by 96,\n that is sad must be between 96 and 127.\n"); void parse_options(int argc, char ** argv) { int eos_char = 0; // End of string character int reos_mode = 0; // Don't terminate read on eos_char int bin_mode = 0; // Match only 7 bits of eos_char int xeos_mode = 0; // Don't assert EOI when sending eos_char int c; mProg = argv[0]; while ((c = getopt (argc, argv, "d:m:s:i:e:r:b:x:t:f:p:uNXh")) != -1) switch (c) { case 'd': pad = atoi(optarg); break; case 'm': minor = atoi(optarg); break; case 's': sad = atoi(optarg); break; case 'i': send_eoi = atoi(optarg); break; case 'e': eos_char = atoi(optarg); break; case 'r': reos_mode = atoi(optarg); break; case 'b': bin_mode = atoi(optarg); break; case 'x': xeos_mode = atoi(optarg); break; case 't': timeout = atoi(optarg); break; case 'f': mHist = optarg; break; case 'p': mPrompt = optarg; break; case 'u': mUnTUnL = true; break; case 'N': mAutoRead = false; break; case 'X': mHex = true; break; case 'h': EMES(help_string); usage(0); break; default: usage(1); } if (pad == -1) { EMES("No primary device address (pad) specified!\n"); usage(1); } CHECK_ADDR(pad); if (sad) CHECK_SADDR(sad); CHECK_FLAG(send_eoi, eoi); CHECK_FLAG(reos_mode,reos); CHECK_FLAG(bin_mode, bin); CHECK_FLAG(xeos_mode,xeos); if (eos_char < 0 || eos_char > 255) { abend("eos character must be between 0 and 255,\n"); } if (!bin_mode && eos_char > 127) { EMES("Warning eos is 8 bits but compares are set to 7.\n"); } if (timeout < 1 || timeout > 15) abend(" must be between 1 and 15."); eos_mode = eos_char; if (reos_mode) eos_mode |= REOS; if (bin_mode) eos_mode |= BIN; if (xeos_mode) eos_mode |= XEOS; if (mHist == NULL) { mHist = malloc(32); sprintf(mHist,".ibterm_hist_%02d",pad); } } static void showError(char * mess) { fprintf(stderr,"ibterm error: %s\n", mess); fprintf(stderr," - %s\n", gpib_error_string(ThreadIberr())); if (iberr==EDVR) fprintf(stderr,"\t%s\n",strerror(ibcnt)); } #ifndef READLINE #define READ_BUF_SIZE 2048 char * readline(char * prompt) { char * buf, * ret; int len; fwrite(prompt,1,strlen(prompt),stdout); fflush(stdout); if (!(buf = malloc(READ_BUF_SIZE))) { abend("no memory"); } ret = fgets(buf,READ_BUF_SIZE,stdin); if (ret) { len = strlen(ret); if (ret[len-1] == '\n') ret[len-1] = 0; } else free(buf); return ret; } void read_history(char * buf) {}; void add_history(char * buf) {}; void write_history(char * buf) {}; #endif int main (int argc, char ** argv) { char * line; int i, devdatalen,datasent; unsigned char devbuf[DEVICE_BUFFER_SIZE]; int printable; parse_options(argc, argv); printf("Attempting to open /dev/gpib%i\n" "pad = %d, sad = %d, timeout = %d, send_eoi = %d, eos_mode = 0x%04x\n", minor,pad,sad,timeout,send_eoi,eos_mode); putenv("IB_NO_ERROR=1"); // we check for our own errors devdesc = ibdev(minor, pad, sad, timeout, send_eoi, eos_mode); if (devdesc < 0) { showError("open failed"); abend("ibdev error\n"); } if (mUnTUnL) { if(ERR & ibconfig(devdesc, IbcUnAddr, 1)) EMES("Could not set IbcUnAddr\n"); ibask(devdesc, IbaUnAddr, &i); printf("IbaUnAddr %d\n",i); } read_history(mHist); /* prompt user - read term - write device - read device - print term loop */ while ((line = readline(mPrompt))) { /* prompt and read from user */ /* write to device */ if (*line) { /* send to device only if we got something */ if (ibwrt(devdesc,line,strlen(line)) & ERR ) { sprintf(errmes,"Unable to write to device at pad %d\n",pad); showError(errmes); free(line); continue; } add_history (line); datasent = true; } else datasent = false; free(line); /* return buffer allocated by readline */ if (mAutoRead || !datasent) { /* read response if any from device */ if (ibrd(devdesc,devbuf,DEVICE_BUFFER_SIZE) & ERR) { if (!(ThreadIbsta() & TIMO)) { sprintf(errmes,"Failed during read from device at pad %d\n",pad); showError(errmes); } continue; } devdatalen = ThreadIbcntl(); if (!devdatalen) continue; } else continue; /* print response */ if (!mHex) { printable = true; for(i = 0; i < devdatalen; ++i) { if (!isprint(devbuf[i]) && !isspace(devbuf[i])){ printable = false; break; } } } else printable = false; if (printable) { fwrite(devbuf,1,devdatalen,stdout); /* print response as ASCII string */ /* but don't print an extra newline if it ends with LF or LF CR */ if ((devdatalen > 2 && (devbuf[devdatalen-2] != '\n') || (devbuf[devdatalen-1] != '\r')) && devbuf[devdatalen-1] != '\n') putchar('\n'); } else { prhex(devbuf,devdatalen); /* print contents with hex and ascii */ } } /* Finish up */ ibonl(devdesc, 0); /* free up gpib library resources */ write_history(mHist); puts("\nibterm: Done."); exit(0); } examples/ibtest.c000066400000000000000000000441331507046215500143440ustar00rootroot00000000000000/*************************************************************************** ibtest.c ------------------- Example program which uses gpib c library. More complex than an example program needs to be really, but useful for testing library functions. copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include "gpib/ib.h" void fprint_status( FILE* filep, char *msg ); enum Action { GPIB_COMMAND, GPIB_DEVICE_CLEAR, GPIB_EOT, GPIB_EOS, GPIB_GO_TO_LOCAL, GPIB_GO_TO_STANDBY, GPIB_IFC, GPIB_LINE_STATUS, GPIB_QUIT, GPIB_READ, GPIB_REMOTE_ENABLE, GPIB_REQUEST_SERVICE, GPIB_SERIAL_POLL, GPIB_TAKE_CONTROL, GPIB_TIMEOUT, GPIB_WAIT, GPIB_WRITE, GPIB_GROUP_EXECUTE_TRIGGER }; typedef struct { int minor; } parsed_options_t; static void parse_options( int argc, char *argv[], parsed_options_t *parsed_opts ) { int c, index; struct option options[] = { { "minor", required_argument, NULL, 'm' }, { 0 }, }; parsed_opts->minor = 0; while(1) { c = getopt_long(argc, argv, "m:", options, &index); if( c == -1 ) break; switch( c ) { case 0: break; case 'm': parsed_opts->minor = strtol( optarg, NULL, 0 ); break; default: fprintf(stderr, "ibtest: invalid option\n"); exit(1); } } } void descriptor_type( int ud, int *is_board, int *is_master ) { int master; int status; status = ibask( ud, IbaSC, &master ); if( status & ERR ) { if( ThreadIberr() != EARG ) { fprint_status( stderr, "ibask error" ); abort(); } *is_board = 0; *is_master = 0; }else { *is_board = 1; *is_master = master; } } int descriptor_is_board( int ud ) { int is_board; int is_master; descriptor_type( ud, &is_board, &is_master ); return is_board; } int descriptor_is_master( int ud ) { int is_board; int is_master; descriptor_type( ud, &is_board, &is_master ); return is_board && is_master; } /* returns a device descriptor after prompting user for primary address */ int prompt_for_device(int minor) { int ud, pad; const int sad = 0; const int send_eoi = 1; const int eos_mode = 0; const int timeout = T1s; char input[100]; while(1) { printf("enter primary gpib address for device you wish to open [0-30]: "); if(fgets(input, sizeof(input), stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } pad = strtol(input, NULL, 0); if(pad < 0 || pad > 30) printf("primary address must be between 0 and 30\n"); else break; } printf("trying to open pad = %i on /dev/gpib%i ...\n", pad, minor); ud = ibdev(minor, pad, sad, timeout, send_eoi, eos_mode); if(ud < 0) { fprint_status( stderr, "ibdev error\n"); abort(); } return ud; } /* returns a device descriptor after prompting user for primary address */ int prompt_for_board(void) { int ud = -1; char board_name[100]; do { int length; printf("enter name of interface board (or device) you wish to open: "); if(fgets( board_name, sizeof( board_name ), stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } length = strlen( board_name ); if( board_name[ length - 1 ] == '\n' ) board_name[ length - 1 ] = 0; printf( "trying to open board named '%s'\n", board_name ); ud = ibfind( board_name ); if(ud < 0) { fprintf( stderr, "failed to open board\n" ); } }while( ud < 0 ); return ud; } int prompt_for_descriptor(int minor) { char input[100]; do { printf( "Do you wish to open a (d)evice or an interface (b)oard?\n" "\t(you probably want to open a device): "); if(fgets(input, sizeof(input), stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); break; } switch( input[0] ) { case 'd': case 'D': return prompt_for_device(minor); break; case 'b': case 'B': return prompt_for_board(); break; default: break; } } while( 1 ); return -1; } /* asks user what they want to do next */ int prompt_for_action(void) { char input[100]; while(1) { printf("You can:\n" "\tw(a)it for an event\n" "\twrite (c)ommand bytes to bus (system controller only)\n" "\tsend (d)evice clear (device only)\n" "\tchange remote (e)nable line (system controller only)\n" "\t(g)o to standby (release ATN line, system controller only)\n" "\tsend (i)nterface clear (system controller only)\n" "\tta(k)e control (assert ATN line, system controller only)\n" "\tget bus (l)ine status (board only)\n" "\tgo to local (m)ode\n" "\tchange end (o)f transmission configuration\n" "\tend read on recei(p)t of EOS character\n" "\t(q)uit\n" "\t(r)ead string\n" "\tperform (s)erial poll (device only)\n" "\tchange (t)imeout on io operations\n" "\trequest ser(v)ice (board only)\n" "\t(w)rite data string\n" "\tsend group e(x)ecute trigger (device only)\n" ": " ); do { if(fgets( input, sizeof( input ), stdin ) == NULL) { if(feof(stdin)) return GPIB_QUIT; fprintf(stderr, "Error reading from standard input.\n"); return -1; } }while (input[0] == '\n'); switch( input[0] ) { case 'A': case 'a': return GPIB_WAIT; break; case 'C': case 'c': return GPIB_COMMAND; break; case 'd': case 'D': return GPIB_DEVICE_CLEAR; break; case 'E': case 'e': return GPIB_REMOTE_ENABLE; break; case 'G': case 'g': return GPIB_GO_TO_STANDBY; break; case 'L': case 'l': return GPIB_LINE_STATUS; break; case 'I': case 'i': return GPIB_IFC; break; case 'K': case 'k': return GPIB_TAKE_CONTROL; break; case 'm': case 'M': return GPIB_GO_TO_LOCAL; break; case 'o': case 'O': return GPIB_EOT; break; case 'p': case 'P': return GPIB_EOS; break; case 'q': case 'Q': return GPIB_QUIT; break; case 'r': case 'R': return GPIB_READ; break; case 's': case 'S': return GPIB_SERIAL_POLL; break; case 't': case 'T': return GPIB_TIMEOUT; break; case 'v': case 'V': return GPIB_REQUEST_SERVICE; break; case 'w': case 'W': return GPIB_WRITE; break; case 'x': case 'X': return GPIB_GROUP_EXECUTE_TRIGGER; break; default: fprintf( stderr, "invalid selection\n"); break; } } return -1; } int perform_read(int ud, int max_num_bytes) { char *buffer; int buffer_size = max_num_bytes + 1; buffer = malloc(buffer_size); int is_string; int i; long read_count = 0; if(buffer == NULL) { fprintf(stderr, "%s: failed to allocate buffer.\n", __FUNCTION__); return -1; } memset(buffer, 0, buffer_size); printf("trying to read %i bytes from device...\n", max_num_bytes); ibrd(ud, buffer, buffer_size - 1); if((ThreadIbsta() & ERR) == 0 || ThreadIberr() != EDVR) { read_count = ThreadIbcntl(); } is_string = 1; for(i = 0; i < read_count; ++i) { if(isascii(buffer[i]) == 0) { is_string = 0; break; } } if(is_string) { printf("received string: '%s'\n", buffer); }else { printf("received binary data (hex): "); for(i = 0; i < read_count; ++i) { printf("%2x ", (unsigned)buffer[i]); } printf("\n"); } free(buffer); printf("Number of bytes read: %li\n", read_count); if(ThreadIbsta() & ERR) return -1; return 0; } int prompt_for_commands(int ud) { char buffer[ 1024 ]; char *next = buffer; char *end; int i; printf("enter command bytes to send to the bus: "); if(fgets( buffer, sizeof(buffer), stdin ) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } for(i = 0; i < sizeof(buffer); ++i) { buffer[i] = strtol(next, &end, 0); if(end == next) break; next = end; } printf("writing %i command bytes to the bus\n", i); if(ibcmd(ud, buffer, i) & ERR) { return -1; } return 0; } int prompt_for_read(int ud) { char *buffer; static const int buffer_size = 1024; int max_num_bytes; static const int default_num_bytes = 1024; char *endptr; buffer = malloc(buffer_size); if(buffer == NULL) return -ENOMEM; printf("enter maximum number of bytes to read [1024]: "); if(fgets(buffer, buffer_size, stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } max_num_bytes = strtol(buffer, &endptr, 0); if(endptr == buffer) max_num_bytes = default_num_bytes; free(buffer); return perform_read(ud, max_num_bytes); } int prompt_for_write(int ud) { char buffer[ 1024 ]; printf("enter a string to send to your device: "); if(fgets( buffer, sizeof(buffer), stdin ) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } printf("sending string: %s\n", buffer); if( ibwrt(ud, buffer, strlen(buffer)) & ERR ) { return -1; } return 0; } int do_serial_poll( int ud ) { char result; int status; if( descriptor_is_board( ud ) != 0 ) { fprintf( stderr, "You have a board open (as opposed to a device).\n" "\tYou cannot perform a serial poll.\n" ); return -1; } status = ibrsp( ud, &result ); if( status & ERR ) { return -1; } printf( "serial poll result: 0x%x\n", ( (unsigned int) result ) & 0xff ); return 0; } int request_service( int ud ) { int status_byte; int status; if( descriptor_is_board( ud ) == 0 ) { fprintf( stderr, "You have a device open (as opposed to a board).\n" "\tYou cannot request service.\n" ); return -1; } printf( "enter new status byte (bit 0x40 requests service): " ); if(scanf( "%i", &status_byte ) < 1) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } status = ibrsv( ud, status_byte ); if( status & ERR ) { return -1; } return 0; } int prompt_for_timeout( int ud ) { int timeout; printf( "enter the desired timeout:\n" "\t(0) none\n" "\t(1) 10 microsec\n" "\t(2) 30 microsec\n" "\t(3) 100 microsec\n" "\t(4) 300 microsec\n" "\t(5) 1 millisec\n" "\t(6) 3 millisec\n" "\t(7) 10 millisec\n" "\t(8) 30 millisec\n" "\t(9) 100 millisec\n" "\t(10) 300 millisec\n" "\t(11) 1 sec\n" "\t(12) 3 sec\n" "\t(13) 10 sec\n" "\t(14) 30 sec\n" "\t(15) 100 sec\n" "\t(16) 300 sec\n" "\t(17) 1000 sec\n" ); if(scanf( "%i", &timeout ) < 1) { fprintf(stderr, "Error reading from standard input."); return -1; } if( ibtmo( ud, timeout ) & ERR ) { fprintf( stderr, "failed to set timeout to %i\n", timeout ); return -1; } return 0; } int prompt_for_wait( int ud ) { int wait_mask; printf( "Possible wait bits:\n" "\t0x%x timeout\n" "\t0x%x device requesting service\n" "\t0x%x board serial polled\n", TIMO, RQS, SPOLL); printf("Enter wait mask: "); if(scanf( "%i", &wait_mask ) < 1) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } ibwait( ud, wait_mask ); return 0; } void printf_line_status( const char *name, int line_status, int valid_bit, int bus_bit ) { printf( "%s ", name ); if( line_status & valid_bit ) { if( line_status & bus_bit ) printf( "on\n" ); else printf( "off\n" ); }else printf( "unknown\n" ); } int get_lines( int ud ) { short line_status; if( iblines( ud, &line_status ) & ERR ) return -1; printf_line_status( "DAV", line_status, ValidDAV, BusDAV ); printf_line_status( "NDAC", line_status, ValidNDAC, BusNDAC ); printf_line_status( "NRFD", line_status, ValidNRFD, BusNRFD ); printf_line_status( "IFC", line_status, ValidIFC, BusIFC ); printf_line_status( "REN", line_status, ValidREN, BusREN ); printf_line_status( "SRQ", line_status, ValidSRQ, BusSRQ ); printf_line_status( "ATN", line_status, ValidATN, BusATN ); printf_line_status( "EOI", line_status, ValidEOI, BusEOI ); return 0; } int device_clear(int ud) { if(ibclr(ud) & ERR) { return -1; } printf("Device clear sent.\n" ); return 0; } int group_execute_trigger(int ud) { if(ibtrg(ud) & ERR) { return -1; } printf("Group execute trigger sent.\n" ); return 0; } int interface_clear( int ud ) { if( ibsic( ud ) & ERR ) return -1; printf( "Inferface clear sent\n" ); return 0; } int go_to_local(int ud) { if(ibloc(ud) & ERR) { return -1; } printf("Go to local sent.\n" ); return 0; } int go_to_standby(int ud) { if(ibgts(ud, 0) & ERR) { return -1; } printf("ATN released.\n" ); return 0; } int prompt_for_remote_enable( int ud ) { int status; int assert; printf("Enter '1' to assert remote enable, or '0' to unassert: "); if(scanf( "%i", &assert ) < 1) { fprintf(stderr, "Error reading from standard input."); return -1; } status = ibsre( ud, assert ); if( status & ERR ) return -1; return 0; } int prompt_for_take_control(int ud) { int status; int synchronous; char *buffer; static const int buffer_size = 1024; char *endptr; buffer = malloc(buffer_size); if(buffer == NULL) return -ENOMEM; printf("Enter '1' to assert ATN synchronously, or '0' for asynchronously [1]: "); if(fgets(buffer, buffer_size, stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } synchronous = strtol(buffer, &endptr, 0); if(endptr == buffer) synchronous = 1; free(buffer); printf("Taking control "); if(synchronous) printf("synchronously...\n"); else printf("asynchronously...\n"); status = ibcac(ud, synchronous); if(status & ERR) return -1; printf("ATN asserted.\n"); return 0; } int prompt_for_eot(int ud) { int status; int assert_eoi; char *buffer; static const int buffer_size = 1024; char *endptr; buffer = malloc(buffer_size); if(buffer == NULL) return -ENOMEM; printf("Enter '1' to assert EOI with the last byte of writes, or '0' otherwise [1]: "); if(fgets(buffer, buffer_size, stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } assert_eoi = strtol(buffer, &endptr, 0); if(endptr == buffer) assert_eoi = 1; free(buffer); status = ibeot(ud, assert_eoi); if(status & ERR) return -1; printf("EOI will "); if(assert_eoi == 0) printf("not "); printf("be asserted with the last byte of writes.\n"); return 0; } int prompt_for_eos(int ud) { int status; int assert_eos; char *buffer; static const int buffer_size = 1024; char *endptr; buffer = malloc(buffer_size); if(buffer == NULL) return -ENOMEM; printf("Enter EOS character in hex received or '0' otherwise [0x0A]: "); if(fgets(buffer, buffer_size, stdin) == NULL) { fprintf(stderr, "Error reading from standard input.\n"); return -1; } assert_eos = strtol(buffer, &endptr, 16) & 0xFF; if(endptr == buffer) assert_eos = 0x0A; free(buffer); status = ibeos(ud, assert_eos == 0 ? 0 : REOS | assert_eos ); if(status & ERR) return -1; printf("Receipt of EOS will "); if(assert_eos == 0) printf("not "); printf("end read.\n"); return 0; } int main(int argc, char **argv) { int dev; int act; parsed_options_t parsed_opts; parse_options( argc, argv, &parsed_opts ); dev = prompt_for_descriptor(parsed_opts.minor); do { act = prompt_for_action(); if( act < 0 || act == GPIB_QUIT ) break; switch( act ) { case GPIB_COMMAND: prompt_for_commands(dev); break; case GPIB_DEVICE_CLEAR: device_clear(dev); break; case GPIB_EOT: prompt_for_eot(dev); break; case GPIB_EOS: prompt_for_eos(dev); break; case GPIB_GO_TO_LOCAL: go_to_local(dev); break; case GPIB_GO_TO_STANDBY: go_to_standby(dev); break; case GPIB_IFC: interface_clear(dev); break; case GPIB_LINE_STATUS: get_lines( dev ); break; case GPIB_READ: prompt_for_read(dev); break; case GPIB_REMOTE_ENABLE: prompt_for_remote_enable( dev ); break; case GPIB_REQUEST_SERVICE: request_service( dev ); break; case GPIB_SERIAL_POLL: do_serial_poll( dev ); break; case GPIB_TAKE_CONTROL: prompt_for_take_control(dev); break; case GPIB_TIMEOUT: prompt_for_timeout( dev ); break; case GPIB_WAIT: prompt_for_wait( dev ); break; case GPIB_WRITE: prompt_for_write( dev ); break; case GPIB_GROUP_EXECUTE_TRIGGER: group_execute_trigger(dev); break; default: fprintf( stderr, "bug, unknown selection\n"); break; } fprint_status( stdout, "gpib status is: " ); }while( act != GPIB_QUIT ); ibonl(dev, 0); if( act < 0 ) return act; else return 0; } /* * This is a simple error handling function * */ void fprint_status( FILE* filep, char *msg ) { fprintf( filep, "%s\n", msg); fprintf( filep, "ibsta = 0x%x < ", ThreadIbsta() ); if(ThreadIbsta() & ERR) fprintf(filep, "ERR "); if(ThreadIbsta() & TIMO) fprintf(filep, "TIMO "); if(ThreadIbsta() & END) fprintf(filep, "END "); if(ThreadIbsta() & SRQI) fprintf(filep, "SRQI "); if(ThreadIbsta() & RQS) fprintf(filep, "RQS "); if(ThreadIbsta() & SPOLL) fprintf(filep, "SPOLL "); if(ThreadIbsta() & EVENT) fprintf(filep, "EVENT "); if(ThreadIbsta() & CMPL) fprintf(filep, "CMPL "); if(ThreadIbsta() & LOK) fprintf(filep, "LOK "); if(ThreadIbsta() & REM) fprintf(filep, "REM "); if(ThreadIbsta() & CIC) fprintf(filep, "CIC "); if(ThreadIbsta() & ATN) fprintf(filep, "ATN "); if(ThreadIbsta() & TACS) fprintf(filep, "TACS "); if(ThreadIbsta() & LACS) fprintf(filep, "LACS "); if(ThreadIbsta() & DCAS) fprintf(filep, "DCAS "); if(ThreadIbsta() & DTAS) fprintf(filep, "DTAS "); fprintf( filep, ">\n" ); fprintf( filep,"iberr= %d\n", ThreadIberr()); if( ( ThreadIbsta() & ERR ) ) { fprintf( filep, "%s\n", gpib_error_string( ThreadIberr() ) ); } fprintf( filep, "\n" ); fprintf( filep, "ibcntl = %ld\n", ThreadIbcntl() ); } examples/master_read_to_file.c000066400000000000000000000072361507046215500170440ustar00rootroot00000000000000/*************************************************************************** master_read_to_file.c ------------------- Example program which uses gpib c library. I use this with slave_write_from_file in order to test read/write speed between two boards. Unlike master_write_from_file, we don't use ibrdf() here because I want to separate gpib transfer speed and disk io speed in my benchmarking. copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include "gpib/ib.h" char *myProg; void usage(int brief) { fprintf(stderr,"Usage: %s [-h] [-b ]" " [-d ] \n", myProg); if (brief) exit(1); fprintf(stderr," Default is 0\n"); fprintf(stderr," Default is 1\n"); exit(0); } int main( int argc, char *argv[] ) { int dev; int board_index = 0; int pad = 1; int sad = 0; int send_eoi = 1; int eos_mode = 0; char *file_path; int status; struct timeval start_time, end_time; float elapsed_time; FILE *filep; uint8_t *buffer; static const unsigned long buffer_length = 10000000; int c,unaddr; myProg = argv[0]; while ((c = getopt (argc, argv, "b:d:h")) != -1) { switch (c) { case 'b': board_index = atoi(optarg); break; case 'd': pad = atoi(optarg); break; case 'h': usage(0); break; default: usage(1); } } if (optind == argc) { fprintf( stderr, "Must provide file path as argument\n" ); usage(0); } file_path = argv[ optind ]; filep = fopen( file_path, "w" ); if( filep == NULL ) { perror( "fopen()"); return -1; } buffer = malloc( buffer_length ); if( buffer == NULL ) { perror( "malloc()"); return -1; } dev = ibdev( board_index, pad, sad, TNONE, send_eoi, eos_mode ); if( dev < 0 ) { fprintf( stderr, "ibdev() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } if (ERR & ibconfig(dev,IbcUnAddr,1)) { fprintf(stderr, "Could not set automatic unaddress mode\n"); } ibask(dev,IbaUnAddr,&unaddr); printf( "Device online: board index=%i, pad=%i, sad=%i, unaddr=%i\n" "\tfile path=%s\n", board_index, pad, sad, unaddr, file_path ); gettimeofday( &start_time, NULL ); status = ibrd( dev, buffer, buffer_length ); if( status & ERR ) { fprintf( stderr, "ibrd() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } gettimeofday( &end_time, NULL ); elapsed_time = end_time.tv_sec - start_time.tv_sec + ( end_time.tv_usec - start_time.tv_usec ) / 1e6; printf( "Transferred %lu bytes in %g seconds: %g bytes/sec\n", ThreadIbcntl(), elapsed_time, ThreadIbcntl() / elapsed_time ); if( fwrite( buffer, 1, ThreadIbcntl(), filep ) != ThreadIbcntl() ) { perror( "fwrite()" ); return -1; } fclose( filep ); free( buffer ); return 0; } examples/master_write_from_file.c000066400000000000000000000055641507046215500176060ustar00rootroot00000000000000/*************************************************************************** master_write_from_file.c ------------------- Example program which uses gpib c library. I use this with slave_read_to_file in order to test read/write speed between two boards. copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include "gpib/ib.h" char *myProg; void usage(int brief) { fprintf(stderr,"Usage: %s [-h] [-b ]" " [-d ] \n", myProg); if (brief) exit(1); fprintf(stderr," Default is 0\n"); fprintf(stderr," Default is 1\n"); exit(0); } int main( int argc, char *argv[] ) { int dev; int board_index = 0; int pad = 1; int sad = 0; int send_eoi = 1; int eos_mode = 0; char *file_path; int status; struct timeval start_time, end_time; float elapsed_time; int c; myProg = argv[0]; while ((c = getopt (argc, argv, "b:d:h")) != -1) { switch (c) { case 'b': board_index = atoi(optarg); break; case 'd': pad = atoi(optarg); break; case 'h': usage(0); break; default: usage(1); } } if (optind == argc) { fprintf( stderr, "Must provide file path as argument\n" ); usage(0); } file_path = argv[ optind ]; dev = ibdev( board_index, pad, sad, TNONE, send_eoi, eos_mode ); if( dev < 0 ) { fprintf( stderr, "ibdev() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } printf( "Device online: board index=%i, pad=%i, sad=%i\n" "\tfile path=%s\n", board_index, pad, sad, file_path ); gettimeofday( &start_time, NULL ); status = ibwrtf( dev, file_path ); if( status & ERR ) { fprintf( stderr, "ibwrtf() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } gettimeofday( &end_time, NULL ); elapsed_time = end_time.tv_sec - start_time.tv_sec + ( end_time.tv_usec - start_time.tv_usec ) / 1e6; printf( "Transferred %lu bytes in %g seconds: %g bytes/sec\n", ThreadIbcntl(), elapsed_time, ThreadIbcntl() / elapsed_time ); return 0; } examples/slave_read_to_file.c000066400000000000000000000050701507046215500166550ustar00rootroot00000000000000/*************************************************************************** slave_read_to_file.c ------------------- Example program which uses gpib c library. I use this with master_write_from_file in order to test read/write speed between two boards. copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include "gpib/ib.h" char *myProg; void usage(int brief) { fprintf(stderr,"Usage: %s [-h] [-b ] \n", myProg); if (brief) exit(1); fprintf(stderr," Default is 0\n"); exit(0); } int main( int argc, char *argv[] ) { int board = 0; int eos_mode = 0; char *file_path; int status; int c; myProg = argv[0]; while ((c = getopt (argc, argv, "b:h")) != -1) { switch (c) { case 'b': board = atoi(optarg); break; case 'h': usage(0); break; default: usage(1); } } if (optind == argc) { fprintf( stderr, "Must provide file path as argument\n" ); usage(0); } file_path = argv[ optind ]; status = ibeos( board, eos_mode ); if( status & ERR ) { fprintf( stderr, "ibeos() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibtmo( board, TNONE ); if( status & ERR ) { fprintf( stderr, "ibtmo() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibwait( board, LACS ); if( ( status & LACS ) == 0 ) { fprintf( stderr, "ibwait() for LACS failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibrdf( board, file_path ); if( status & ERR ) { fprintf( stderr, "ibrdf() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } return 0; } examples/slave_write_from_file.c000066400000000000000000000071061507046215500174170ustar00rootroot00000000000000/*************************************************************************** slave_write_from_file.c ------------------- Example program which uses gpib c library. I use this with master_read_to_file in order to test read/write speed between two boards. Unlike slave_read_to_file, this program does not use ibwrtf() because I want to separate gpib transfer speed and disk io speed in my benchmarking. copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "gpib/ib.h" char *myProg; void usage(int brief) { fprintf(stderr,"Usage: %s [-h] [-b ] \n", myProg); if (brief) exit(1); fprintf(stderr," Default is 0\n"); exit(0); } int main( int argc, char *argv[] ) { int board = 0; int eos_mode = 0; char *file_path; int status; int retval; FILE *filep; struct stat file_stats; uint8_t *buffer; unsigned long buffer_length; int c; myProg = argv[0]; while ((c = getopt (argc, argv, "b:h")) != -1) { switch (c) { case 'b': board = atoi(optarg); break; case 'h': usage(0); break; default: usage(1); } } if (optind == argc) { fprintf( stderr, "Must provide file path as argument\n" ); usage(0); } file_path = argv[ optind ]; filep = fopen( file_path, "r" ); if( filep == NULL ) { perror( "fopen()"); return -1; } retval = fstat( fileno( filep ), &file_stats ); if( retval < 0 ) { perror( "fstat()"); return -1; } buffer_length = file_stats.st_size; buffer = malloc( buffer_length ); if( buffer == NULL ) { perror( "malloc()"); return -1; } if( fread( buffer, 1, buffer_length, filep ) != buffer_length ) { perror( "fread()" ); return -1; } fclose( filep ); status = ibeos( board, eos_mode ); if( status & ERR ) { fprintf( stderr, "ibeos() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibtmo( board, TNONE ); if( status & ERR ) { fprintf( stderr, "ibtmo() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibconfig( board, IbcTIMING, T1_DELAY_350ns ); if( status & ERR ) { fprintf( stderr, "ibconfig() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibwait( board, TACS ); if( ( status & TACS ) == 0 ) { fprintf( stderr, "ibwait() for TACS failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } status = ibwrt( board, buffer, buffer_length ); if( status & ERR ) { fprintf( stderr, "ibwrt() failed\n" ); fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) ); return -1; } free( buffer ); return 0; } include/000077500000000000000000000000001507046215500125065ustar00rootroot00000000000000include/Makefile.am000066400000000000000000000005731507046215500145470ustar00rootroot00000000000000# include/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = gpib include/gpib/000077500000000000000000000000001507046215500134275ustar00rootroot00000000000000include/gpib/Makefile.am000066400000000000000000000011351507046215500154630ustar00rootroot00000000000000# include/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. headersdir = $(includedir)/gpib headers_HEADERS = gpib_user.h gpib.h ib.h gpib_version.h noinst_HEADERS = gpib_ioctl.h EXTRA_DIST = version_subst CLEANFILES =gpib_version.h gpib_version.h: echo $(VERSION) | $(SED) -f version_subst > $@ include/gpib/gpib.h000066400000000000000000000055371507046215500145330ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 */ /*************************************************************************** * copyright : (C) 2002 by Frank Mori Hess ***************************************************************************/ #ifndef _GPIB_H #define _GPIB_H #define GPIB_MAX_NUM_BOARDS 16 #define GPIB_MAX_NUM_DESCRIPTORS 0x1000 enum ibsta_bit_numbers { DCAS_NUM = 0, DTAS_NUM = 1, LACS_NUM = 2, TACS_NUM = 3, ATN_NUM = 4, CIC_NUM = 5, REM_NUM = 6, LOK_NUM = 7, CMPL_NUM = 8, EVENT_NUM = 9, SPOLL_NUM = 10, RQS_NUM = 11, SRQI_NUM = 12, END_NUM = 13, TIMO_NUM = 14, ERR_NUM = 15 }; /* IBSTA status bits (returned by all functions) */ enum ibsta_bits { DCAS = (1 << DCAS_NUM), /* device clear state */ DTAS = (1 << DTAS_NUM), /* device trigger state */ LACS = (1 << LACS_NUM), /* GPIB interface is addressed as Listener */ TACS = (1 << TACS_NUM), /* GPIB interface is addressed as Talker */ ATN = (1 << ATN_NUM), /* Attention is asserted */ CIC = (1 << CIC_NUM), /* GPIB interface is Controller-in-Charge */ REM = (1 << REM_NUM), /* remote state */ LOK = (1 << LOK_NUM), /* lockout state */ CMPL = (1 << CMPL_NUM), /* I/O is complete */ EVENT = (1 << EVENT_NUM), /* DCAS, DTAS, or IFC has occurred */ SPOLL = (1 << SPOLL_NUM), /* board serial polled by busmaster */ RQS = (1 << RQS_NUM), /* Device requesting service */ SRQI = (1 << SRQI_NUM), /* SRQ is asserted */ END = (1 << END_NUM), /* EOI or EOS encountered */ TIMO = (1 << TIMO_NUM), /* Time limit on I/O or wait function exceeded */ ERR = (1 << ERR_NUM), /* Function call terminated on error */ device_status_mask = ERR | TIMO | END | CMPL | RQS, board_status_mask = ERR | TIMO | END | CMPL | SPOLL | EVENT | LOK | REM | CIC | ATN | TACS | LACS | DTAS | DCAS | SRQI, }; /* End-of-string (EOS) modes for use with ibeos */ enum eos_flags { EOS_MASK = 0x1c00, REOS = 0x0400, /* Terminate reads on EOS */ XEOS = 0x800, /* assert EOI when EOS char is sent */ BIN = 0x1000 /* Do 8-bit compare on EOS */ }; /* GPIB Bus Control Lines bit vector */ enum bus_control_line { VALID_DAV = 0x01, VALID_NDAC = 0x02, VALID_NRFD = 0x04, VALID_IFC = 0x08, VALID_REN = 0x10, VALID_SRQ = 0x20, VALID_ATN = 0x40, VALID_EOI = 0x80, VALID_ALL = 0xff, BUS_DAV = 0x0100, /* DAV line status bit */ BUS_NDAC = 0x0200, /* NDAC line status bit */ BUS_NRFD = 0x0400, /* NRFD line status bit */ BUS_IFC = 0x0800, /* IFC line status bit */ BUS_REN = 0x1000, /* REN line status bit */ BUS_SRQ = 0x2000, /* SRQ line status bit */ BUS_ATN = 0x4000, /* ATN line status bit */ BUS_EOI = 0x8000 /* EOI line status bit */ }; enum ppe_bits { PPC_DISABLE = 0x10, PPC_SENSE = 0x8, /* parallel poll sense bit */ PPC_DIO_MASK = 0x7 }; enum { request_service_bit = 0x40, }; enum gpib_events { EVENT_NONE = 0, EVENT_DEV_TRG = 1, EVENT_DEV_CLR = 2, EVENT_IFC = 3 }; #endif /* _GPIB_H */ include/gpib/gpib_ioctl.h000066400000000000000000000101761507046215500157200ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 */ /*************************************************************************** * copyright : (C) 2002 by Frank Mori Hess ***************************************************************************/ #ifndef _GPIB_IOCTL_H #define _GPIB_IOCTL_H #include #include #define GPIB_CODE 160 struct gpib_board_type_ioctl { char name[100]; }; /* argument for read/write/command ioctls */ struct gpib_read_write_ioctl { __u64 buffer_ptr; __u32 requested_transfer_count; __u32 completed_transfer_count; __s32 end; /* end flag return for reads, end io suppression request for cmd*/ __s32 handle; }; struct gpib_open_dev_ioctl { __u32 handle; __u32 pad; __s32 sad; __u32 is_board; }; struct gpib_close_dev_ioctl { __u32 handle; }; struct gpib_serial_poll_ioctl { __u32 pad; __s32 sad; __u8 status_byte; __u8 padding[3]; // align to 32 bit boundary }; struct gpib_eos_ioctl { __s32 eos; __s32 eos_flags; }; struct gpib_wait_ioctl { __s32 handle; __s32 wait_mask; __s32 clear_mask; __s32 set_mask; __s32 ibsta; __s32 pad; __s32 sad; __u32 usec_timeout; }; struct gpib_online_ioctl { __u64 init_data_ptr; __s32 init_data_length; __s32 online; }; struct gpib_spoll_bytes_ioctl { __u32 num_bytes; __u32 pad; __s32 sad; }; struct gpib_board_info_ioctl { __u32 pad; __s32 sad; __s32 parallel_poll_configuration; __s32 autopolling; __s32 is_system_controller; __u32 t1_delay; unsigned ist : 1; unsigned no_7_bit_eos : 1; unsigned padding :30; // align to 32 bit boundary }; struct gpib_select_pci_ioctl { __s32 pci_bus; __s32 pci_slot; }; struct gpib_ppoll_config_ioctl { __u8 config; unsigned set_ist : 1; unsigned clear_ist : 1; unsigned padding :22; // align to 32 bit boundary }; struct gpib_pad_ioctl { __u32 handle; __u32 pad; }; struct gpib_sad_ioctl { __u32 handle; __s32 sad; }; // select a piece of hardware to attach by its sysfs device path struct gpib_select_device_path_ioctl { char device_path[0x1000]; }; // update status byte and request service struct gpib_request_service2 { __u8 status_byte; __u8 padding[3]; // align to 32 bit boundary __s32 new_reason_for_service; }; /* Standard functions. */ enum gpib_ioctl { IBRD = _IOWR(GPIB_CODE, 100, struct gpib_read_write_ioctl), IBWRT = _IOWR(GPIB_CODE, 101, struct gpib_read_write_ioctl), IBCMD = _IOWR(GPIB_CODE, 102, struct gpib_read_write_ioctl), IBOPENDEV = _IOWR(GPIB_CODE, 3, struct gpib_open_dev_ioctl), IBCLOSEDEV = _IOW(GPIB_CODE, 4, struct gpib_close_dev_ioctl), IBWAIT = _IOWR(GPIB_CODE, 5, struct gpib_wait_ioctl), IBRPP = _IOWR(GPIB_CODE, 6, __u8), IBSIC = _IOW(GPIB_CODE, 9, __u32), IBSRE = _IOW(GPIB_CODE, 10, __s32), IBGTS = _IO(GPIB_CODE, 11), IBCAC = _IOW(GPIB_CODE, 12, __s32), IBLINES = _IOR(GPIB_CODE, 14, __s16), IBPAD = _IOW(GPIB_CODE, 15, struct gpib_pad_ioctl), IBSAD = _IOW(GPIB_CODE, 16, struct gpib_sad_ioctl), IBTMO = _IOW(GPIB_CODE, 17, __u32), IBRSP = _IOWR(GPIB_CODE, 18, struct gpib_serial_poll_ioctl), IBEOS = _IOW(GPIB_CODE, 19, struct gpib_eos_ioctl), IBRSV = _IOW(GPIB_CODE, 20, __u8), CFCBASE = _IOW(GPIB_CODE, 21, __u64), CFCIRQ = _IOW(GPIB_CODE, 22, __u32), CFCDMA = _IOW(GPIB_CODE, 23, __u32), CFCBOARDTYPE = _IOW(GPIB_CODE, 24, struct gpib_board_type_ioctl), IBMUTEX = _IOW(GPIB_CODE, 26, __s32), IBSPOLL_BYTES = _IOWR(GPIB_CODE, 27, struct gpib_spoll_bytes_ioctl), IBPPC = _IOW(GPIB_CODE, 28, struct gpib_ppoll_config_ioctl), IBBOARD_INFO = _IOR(GPIB_CODE, 29, struct gpib_board_info_ioctl), IBQUERY_BOARD_RSV = _IOR(GPIB_CODE, 31, __s32), IBSELECT_PCI = _IOWR(GPIB_CODE, 32, struct gpib_select_pci_ioctl), IBEVENT = _IOR(GPIB_CODE, 33, __s16), IBRSC = _IOW(GPIB_CODE, 34, __s32), IB_T1_DELAY = _IOW(GPIB_CODE, 35, __u32), IBLOC = _IO(GPIB_CODE, 36), IBAUTOSPOLL = _IOW(GPIB_CODE, 38, __s16), IBONL = _IOW(GPIB_CODE, 39, struct gpib_online_ioctl), IBPP2_SET = _IOW(GPIB_CODE, 40, __s16), IBPP2_GET = _IOR(GPIB_CODE, 41, __s16), IBSELECT_DEVICE_PATH = _IOW(GPIB_CODE, 43, struct gpib_select_device_path_ioctl), // 44 was IBSELECT_SERIAL_NUMBER IBRSV2 = _IOW(GPIB_CODE, 45, struct gpib_request_service2) }; #endif /* _GPIB_IOCTL_H */ include/gpib/gpib_user.h000066400000000000000000000244261507046215500155670ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 */ /*************************************************************************** * copyright : (C) 2002 by Frank Mori Hess ***************************************************************************/ #ifndef _GPIB_USER_H #define _GPIB_USER_H #include #include "gpib.h" /* IBERR error codes */ enum iberr_code { EDVR = 0, /* system error */ ECIC = 1, /* not CIC */ ENOL = 2, /* no listeners */ EADR = 3, /* CIC and not addressed before I/O */ EARG = 4, /* bad argument to function call */ ESAC = 5, /* not SAC */ EABO = 6, /* I/O operation was aborted */ ENEB = 7, /* non-existent board (GPIB interface offline) */ EDMA = 8, /* DMA hardware error detected */ EOIP = 10, /* new I/O attempted with old I/O in progress */ ECAP = 11, /* no capability for intended opeation */ EFSO = 12, /* file system operation error */ EBUS = 14, /* bus error */ ESTB = 15, /* lost serial poll bytes */ ESRQ = 16, /* SRQ stuck on */ ECNF = 17, /* Configuration file error */ ETAB = 20 /* Table Overflow */ }; /* Timeout values and meanings */ enum gpib_timeout { TNONE = 0, /* Infinite timeout (disabled) */ T10us = 1, /* Timeout of 10 usec (ideal) */ T30us = 2, /* Timeout of 30 usec (ideal) */ T100us = 3, /* Timeout of 100 usec (ideal) */ T300us = 4, /* Timeout of 300 usec (ideal) */ T1ms = 5, /* Timeout of 1 msec (ideal) */ T3ms = 6, /* Timeout of 3 msec (ideal) */ T10ms = 7, /* Timeout of 10 msec (ideal) */ T30ms = 8, /* Timeout of 30 msec (ideal) */ T100ms = 9, /* Timeout of 100 msec (ideal) */ T300ms = 10, /* Timeout of 300 msec (ideal) */ T1s = 11, /* Timeout of 1 sec (ideal) */ T3s = 12, /* Timeout of 3 sec (ideal) */ T10s = 13, /* Timeout of 10 sec (ideal) */ T30s = 14, /* Timeout of 30 sec (ideal) */ T100s = 15, /* Timeout of 100 sec (ideal) */ T300s = 16, /* Timeout of 300 sec (ideal) */ T1000s = 17 /* Timeout of 1000 sec (maximum) */ }; /* Possible GPIB command messages */ enum cmd_byte { GTL = 0x1, /* go to local */ SDC = 0x4, /* selected device clear */ PP_CONFIG = 0x5, #ifndef PPC PPC = PP_CONFIG, /* parallel poll configure */ #endif GET = 0x8, /* group execute trigger */ TCT = 0x9, /* take control */ LLO = 0x11, /* local lockout */ DCL = 0x14, /* device clear */ PPU = 0x15, /* parallel poll unconfigure */ SPE = 0x18, /* serial poll enable */ SPD = 0x19, /* serial poll disable */ CFE = 0x1f, /* configure enable */ LAD = 0x20, /* value to be 'ored' in to obtain listen address */ UNL = 0x3F, /* unlisten */ TAD = 0x40, /* value to be 'ored' in to obtain talk address */ UNT = 0x5F, /* untalk */ SAD = 0x60, /* my secondary address (base) */ PPE = 0x60, /* parallel poll enable (base) */ PPD = 0x70 /* parallel poll disable */ }; static const int gpib_addr_max = 30; /* max address for primary/secondary gpib addresses */ static const int gpib_sad_max = 31; /* (0x1f) max address for secondary gpib addresses */ /* confine address to range 0 to 30. */ static inline unsigned int gpib_address_restrict(unsigned int addr) { addr &= 0x1f; if (addr == 0x1f) addr = 0; return addr; } static inline __u8 MLA(unsigned int addr) { return gpib_address_restrict(addr) | LAD; } static inline __u8 MTA(unsigned int addr) { return gpib_address_restrict(addr) | TAD; } static inline __u8 MSA(unsigned int addr) { return (addr & 0x1f) | SAD; } static inline __u8 PPE_byte(unsigned int dio_line, int sense) { __u8 cmd; cmd = PPE; if (sense) cmd |= PPC_SENSE; cmd |= (dio_line - 1) & 0x7; return cmd; } /* mask of bits that actually matter in a command byte */ enum { gpib_command_mask = 0x7f, }; static inline int is_PPE(__u8 command) { return (command & 0x70) == 0x60; } static inline int is_PPD(__u8 command) { return (command & 0x70) == 0x70; } static inline int in_addressed_command_group(__u8 command) { return (command & 0x70) == 0x0; } static inline int in_universal_command_group(__u8 command) { return (command & 0x70) == 0x10; } static inline int in_listen_address_group(__u8 command) { return (command & 0x60) == 0x20; } static inline int in_talk_address_group(__u8 command) { return (command & 0x60) == 0x40; } static inline int in_primary_command_group(__u8 command) { return in_addressed_command_group(command) || in_universal_command_group(command) || in_listen_address_group(command) || in_talk_address_group(command); } static inline int gpib_address_equal(unsigned int pad1, int sad1, unsigned int pad2, int sad2) { if (pad1 == pad2) { if (sad1 == sad2) return 1; if (sad1 < 0 && sad2 < 0) return 1; } return 0; } static __inline__ uint8_t CFGn( unsigned int meters ) { return 0x6 | (meters & 0xf); } enum ibask_option { IBA_PAD = 0x1, IBA_SAD = 0x2, IBA_TMO = 0x3, IBA_EOT = 0x4, IBA_PPC = 0x5, /* board only */ IBA_READ_DR = 0x6, /* device only */ IBA_AUTOPOLL = 0x7, /* board only */ IBA_CICPROT = 0x8, /* board only */ IBA_IRQ = 0x9, /* board only */ IBA_SC = 0xa, /* board only */ IBA_SRE = 0xb, /* board only */ IBA_EOS_RD = 0xc, IBA_EOS_WRT = 0xd, IBA_EOS_CMP = 0xe, IBA_EOS_CHAR = 0xf, IBA_PP2 = 0x10, /* board only */ IBA_TIMING = 0x11, /* board only */ IBA_DMA = 0x12, /* board only */ IBA_READ_ADJUST = 0x13, IBA_WRITE_ADJUST = 0x14, IBA_EVENT_QUEUE = 0x15, /* board only */ IBA_SPOLL_BIT = 0x16, /* board only */ IBA_SEND_LLO = 0x17, /* board only */ IBA_SPOLL_TIME = 0x18, /* device only */ IBA_PPOLL_TIME = 0x19, /* board only */ IBA_END_BIT_IS_NORMAL = 0x1a, IBA_UN_ADDR = 0x1b, /* device only */ IBA_HS_CABLE_LENGTH = 0x1f, /* board only */ IBA_IST = 0x20, /* board only */ IBA_RSV = 0x21, /* board only */ IBA_BNA = 0x200, /* device only */ /* linux-gpib extensions */ IBA_7_BIT_EOS = 0x1000 /* board only. Returns 1 if board supports 7 bit eos compares*/ }; enum ibconfig_option { IBC_PAD = 0x1, IBC_SAD = 0x2, IBC_TMO = 0x3, IBC_EOT = 0x4, IBC_PPC = 0x5, /* board only */ IBC_READDR = 0x6, /* device only */ IBC_AUTOPOLL = 0x7, /* board only */ IBC_CICPROT = 0x8, /* board only */ IBC_IRQ = 0x9, /* board only */ IBC_SC = 0xa, /* board only */ IBC_SRE = 0xb, /* board only */ IBC_EOS_RD = 0xc, IBC_EOS_WRT = 0xd, IBC_EOS_CMP = 0xe, IBC_EOS_CHAR = 0xf, IBC_PP2 = 0x10, /* board only */ IBC_TIMING = 0x11, /* board only */ IBC_DMA = 0x12, /* board only */ IBC_READ_ADJUST = 0x13, IBC_WRITE_ADJUST = 0x14, IBC_EVENT_QUEUE = 0x15, /* board only */ IBC_SPOLL_BIT = 0x16, /* board only */ IBC_SEND_LLO = 0x17, /* board only */ IBC_SPOLL_TIME = 0x18, /* device only */ IBC_PPOLL_TIME = 0x19, /* board only */ IBC_END_BIT_IS_NORMAL = 0x1a, IBC_UN_ADDR = 0x1b, /* device only */ IBC_HS_CABLE_LENGTH = 0x1f, /* board only */ IBC_IST = 0x20, /* board only */ IBC_RSV = 0x21, /* board only */ IBC_BNA = 0x200 /* device only */ }; enum t1_delays { T1_DELAY_2000ns = 1, T1_DELAY_500ns = 2, T1_DELAY_350ns = 3 }; enum gpib_stb { IB_STB_RQS = 0x40, /* IEEE 488.1 & 2 */ IB_STB_ESB = 0x20, /* IEEE 488.2 only */ IB_STB_MAV = 0x10 /* IEEE 488.2 only */ }; /* Compatibility defines due to removal of CamelCase identifiers in kernel code */ /* GPIB Bus Control Lines bit vector */ #define ValidDAV VALID_DAV #define ValidNDAC VALID_NDAC #define ValidNRFD VALID_NRFD #define ValidIFC VALID_IFC #define ValidREN VALID_REN #define ValidSRQ VALID_SRQ #define ValidATN VALID_ATN #define ValidEOI VALID_EOI #define ValidALL VALID_ALL #define BusDAV BUS_DAV #define BusNDAC BUS_NDAC #define BusNRFD BUS_NRFD #define BusIFC BUS_IFC #define BusREN BUS_REN #define BusSRQ BUS_SRQ #define BusATN BUS_ATN #define BusEOI BUS_EOI #define PPConfig PP_CONFIG /* ibask options */ #define IbaPAD IBA_PAD #define IbaSAD IBA_SAD #define IbaTMO IBA_TMO #define IbaEOT IBA_EOT #define IbaPPC IBA_PPC #define IbaREADDR IBA_READ_DR #define IbaAUTOPOLL IBA_AUTOPOLL #define IbaCICPROT IBA_CICPROT #define IbaIRQ IBA_IRQ #define IbaSC IBA_SC #define IbaSRE IBA_SRE #define IbaEOSrd IBA_EOS_RD #define IbaEOSwrt IBA_EOS_WRT #define IbaEOScmp IBA_EOS_CMP #define IbaEOSchar IBA_EOS_CHAR #define IbaPP2 IBA_PP2 #define IbaTIMING IBA_TIMING #define IbaDMA IBA_DMA #define IbaReadAdjust IBA_READ_ADJUST #define IbaWriteAdjust IBA_WRITE_ADJUST #define IbaEventQueue IBA_EVENT_QUEUE #define IbaSPollBit IBA_SPOLL_BIT #define IbaSpollBit IBA_SPOLL_BIT #define IbaSendLLO IBA_SEND_LLO #define IbaSPollTime IBA_SPOLL_TIME #define IbaPPollTime IBA_PPOLL_TIME #define IbaEndBitIsNormal IBA_END_BIT_IS_NORMAL #define IbaUnAddr IBA_UN_ADDR #define IbaHSCableLength IBA_HS_CABLE_LENGTH #define IbaIst IBA_IST #define IbaRsv IBA_RSV #define IbaBNA IBA_BNA #define Iba7BitEOS IBA_7_BIT_EOS /* ibconfig options */ #define IbcPAD IBC_PAD #define IbcSAD IBC_SAD #define IbcTMO IBC_TMO #define IbcEOT IBC_EOT #define IbcPPC IBC_PPC #define IbcREADDR IBC_READDR #define IbcAUTOPOLL IBC_AUTOPOLL #define IbcCICPROT IBC_CICPROT #define IbcIRQ IBC_IRQ #define IbcSC IBC_SC #define IbcSRE IBC_SRE #define IbcEOSrd IBC_EOS_RD #define IbcEOSwrt IBC_EOS_WRT #define IbcEOScmp IBC_EOS_CMP #define IbcEOSchar IBC_EOS_CHAR #define IbcPP2 IBC_PP2 #define IbcTIMING IBC_TIMING #define IbcDMA IBC_DMA #define IbcReadAdjust IBC_READ_ADJUST #define IbcWriteAdjust IBC_WRITE_ADJUST #define IbcEventQueue IBC_EVENT_QUEUE #define IbcSPollBit IBC_SPOLL_BIT #define IbcSpollBit IBC_SPOLL_BIT #define IbcSendLLO IBC_SEND_LLO #define IbcSPollTime IBC_SPOLL_TIME #define IbcPPollTime IBC_PPOLL_TIME #define IbcEndBitIsNormal IBC_END_BIT_IS_NORMAL #define IbcUnAddr IBC_UN_ADDR #define IbcHSCableLength IBC_HS_CABLE_LENGTH #define IbcIst IBC_IST #define IbcRsv IBC_RSV #define IbcBNA IBC_BNA /* gpib events */ #define EventNone EVENT_NONE #define EventDevTrg EVENT_DEV_TRG #define EventDevClr EVENT_DEV_CLR #define EventIFC EVENT_IFC /* standard status byte bits */ #define IbStbRQS IB_STB_RQS #define IbStbESB IB_STB_ESB #define IbStbMAV IB_STB_MAV #endif /* _GPIB_USER_H */ include/gpib/ib.h000066400000000000000000000150041507046215500141720ustar00rootroot00000000000000/*************************************************************************** ib.h - header file for gpib library ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _PUBLIC_GPIB_H #define _PUBLIC_GPIB_H #ifdef __cplusplus extern "C" { #endif #include #include "gpib_user.h" #include "gpib_version.h" #define GPIB_CHECK_VERSION(major,minor,micro) \ (GPIB_MAJOR_VERSION > (major) || \ (GPIB_MAJOR_VERSION == (major) && GPIB_MINOR_VERSION > (minor)) || \ (GPIB_MAJOR_VERSION == (major) && GPIB_MINOR_VERSION == (minor) && \ GPIB_MICRO_VERSION >= (micro))) typedef uint16_t Addr4882_t; static const Addr4882_t NOADDR = (Addr4882_t)-1; /* tells RcvRespMsg() to stop on EOI */ static const int STOPend = 0x100; enum sad_special_address { NO_SAD = 0, ALL_SAD = -1 }; enum send_eotmode { NULLend = 0, DABend = 1, NLend = 2 }; extern volatile int ibsta, ibcnt, iberr; extern volatile long ibcntl; extern void AllSPoll( int board_desc, const Addr4882_t addressList[], short resultList[] ); extern void AllSpoll( int board_desc, const Addr4882_t addressList[], short resultList[] ); extern void DevClear( int board_desc, Addr4882_t address ); extern void DevClearList( int board_desc, const Addr4882_t addressList[] ); extern void EnableLocal( int board_desc, const Addr4882_t addressList[] ); extern void EnableRemote( int board_desc, const Addr4882_t addressList[] ); extern void FindLstn( int board_desc, const Addr4882_t padList[], Addr4882_t resultList[], int maxNumResults ); extern void FindRQS( int board_desc, const Addr4882_t addressList[], short *result ); extern void PassControl( int board_desc, Addr4882_t address ); extern void PPoll( int board_desc, short *result ); extern void PPollConfig( int board_desc, Addr4882_t address, int dataLine, int lineSense ); extern void PPollUnconfig( int board_desc, const Addr4882_t addressList[] ); extern void RcvRespMsg( int board_desc, void *buffer, long count, int termination ); extern void ReadStatusByte( int board_desc, Addr4882_t address, short *result ); extern void Receive( int board_desc, Addr4882_t address, void *buffer, long count, int termination ); extern void ReceiveSetup( int board_desc, Addr4882_t address ); extern void ResetSys( int board_desc, const Addr4882_t addressList[] ); extern void Send( int board_desc, Addr4882_t address, const void *buffer, long count, int eot_mode ); extern void SendCmds( int board_desc, const void *cmds, long count ); extern void SendDataBytes( int board_desc, const void *buffer, long count, int eotmode ); extern void SendIFC( int board_desc ); extern void SendLLO( int board_desc ); extern void SendList( int board_desc, const Addr4882_t addressList[], const void *buffer, long count, int eotmode ); extern void SendSetup( int board_desc, const Addr4882_t addressList[] ); extern void SetRWLS( int board_desc, const Addr4882_t addressList[] ); extern void TestSRQ( int board_desc, short *result ); extern void TestSys( int board_desc, const Addr4882_t addressList[], short resultList[] ); extern int ThreadIbsta( void ); extern int ThreadIberr( void ); extern int ThreadIbcnt( void ); extern long ThreadIbcntl( void ); extern int AsyncIbsta( void ); extern int AsyncIberr( void ); extern int AsyncIbcnt( void ); extern long AsyncIbcntl( void ); extern void Trigger( int board_desc, Addr4882_t address ); extern void TriggerList( int board_desc, const Addr4882_t addressList[] ); extern void WaitSRQ( int board_desc, short *result ); extern int ibask( int ud, int option, int *value ); extern int ibbna( int ud, char *board_name ); extern int ibcac( int ud, int synchronous ); extern int ibclr( int ud ); extern int ibcmd( int ud, const void *cmd, long cnt ); extern int ibcmda( int ud, const void *cmd, long cnt ); extern int ibconfig( int ud, int option, int value ); extern int ibdev( int board_index, int pad, int sad, int timo, int send_eoi, int eosmode ); extern int ibdma( int ud, int v ); extern int ibeot( int ud, int v ); extern int ibeos( int ud, int v ); extern int ibevent( int ud, short *event ); extern int ibfind( const char *dev ); extern int ibgts(int ud, int shadow_handshake); extern int ibist( int ud, int ist ); extern int iblines( int ud, short *line_status ); extern int ibln( int ud, int pad, int sad, short *found_listener ); extern int ibloc( int ud ); extern int ibonl( int ud, int onl ); extern int ibpad( int ud, int v ); extern int ibpct( int ud ); extern int ibppc( int ud, int v ); extern int ibrd( int ud, void *buf, long count ); extern int ibrda( int ud, void *buf, long count ); extern int ibrdf( int ud, const char *file_path ); extern int ibrpp( int ud, char *ppr ); extern int ibrsc( int ud, int v ); extern int ibrsp( int ud, char *spr ); extern int ibrsv( int ud, int status_byte ); extern int ibrsv2( int ud, int status_byte, int new_reason_for_service ); extern int ibsad( int ud, int v ); extern int ibsic( int ud ); extern int ibspb( int ud, short *sp_bytes ); extern int ibsre( int ud, int v ); extern int ibstop( int ud ); extern int ibtmo( int ud, int v ); extern int ibtrg( int ud ); extern void ibvers( char **version); extern int ibwait( int ud, int mask ); extern int ibwrt( int ud, const void *buf, long count ); extern int ibwrta( int ud, const void *buf, long count ); extern int ibwrtf( int ud, const char *file_path ); extern const char* gpib_error_string( int iberr ); static __inline__ Addr4882_t MakeAddr( unsigned int pad, unsigned int sad ) { Addr4882_t address; address = ( pad & 0xff ); address |= ( sad << 8 ) & 0xff00; return address; } static __inline__ unsigned int GetPAD( Addr4882_t address ) { return address & 0xff; } static __inline__ unsigned int GetSAD( Addr4882_t address ) { return ( address >> 8 ) & 0xff; } #ifdef __cplusplus } #endif #endif /* _PUBLIC_GPIB_H */ include/gpib/version_subst000066400000000000000000000001631507046215500162570ustar00rootroot00000000000000s/^/#define GPIB_MAJOR_VERSION / s/\./\n#define GPIB_MINOR_VERSION / s/\./\n#define GPIB_MICRO_VERSION / s/\-.*$// language/000077500000000000000000000000001507046215500126465ustar00rootroot00000000000000language/Makefile.am000066400000000000000000000030261507046215500147030ustar00rootroot00000000000000# language/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = $(PYTHON_SUBDIR) $(PHP_SUBDIR) $(GUILE_SUBDIR) $(TCL_SUBDIR) EXTRA_DIST = $(PERL_DIST) do_subst = $(SED) -e 's,[@]abs_top_builddir[@],$(abs_top_builddir),g'\ -e 's,[@]abs_top_srcdir[@],$(abs_top_srcdir),g' PERL_DIST = perl/Changes perl/LinuxGpib.pm perl/LinuxGpib.xs \ perl/MANIFEST perl/Makefile.PL.in perl/README perl/test.pl \ perl/typemap perl/examples/ if BIND_PERL ALL_PERL = all-perl CLEAN_PERL = clean-perl DISTCLEAN_PERL = distclean-perl else ALL_PERL = CLEAN_PERL = DISTCLEAN_PERL = endif if BIND_PYTHON PYTHON_SUBDIR=python else PYTHON_SUBDIR= endif if BIND_PHP PHP_SUBDIR=php else PHP_SUBDIR= endif if BIND_GUILE GUILE_SUBDIR=guile else GUILE_SUBDIR= endif if BIND_TCL TCL_SUBDIR=tcl else TCL_SUBDIR= endif all-local: $(ALL_PERL) clean-local: $(CLEAN_PERL) distclean-local: $(DISTCLEAN_PERL) .PHONY: all-perl all-perl: perl/Makefile -$(MAKE) -C perl all .PHONY: clean-perl clean-perl: perl/Makefile -$(MAKE) -C perl clean .PHONY: distclean-perl distclean-perl: $(RM) perl/Makefile perl/Makefile.PL: perl/Makefile.PL.in $(do_subst) < $(srcdir)/perl/Makefile.PL.in >perl/Makefile.PL perl/Makefile: perl/Makefile.PL -(cd perl && $(PERL) Makefile.PL) language/guile/000077500000000000000000000000001507046215500137535ustar00rootroot00000000000000language/guile/Makefile.am000066400000000000000000000011451507046215500160100ustar00rootroot00000000000000# language/guile/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = gpib.scm lib_LTLIBRARIES = libgpib-guile.la noinst_HEADERS = gpib.h libgpib_guile_la_SOURCES = gpib.c libgpib_guile_la_CFLAGS = $(LIBGPIB_CFLAGS) -std=gnu17 libgpib_guile_la_LDFLAGS = -release $(VERSION) $(LIBGPIB_LDFLAGS) language/guile/README000066400000000000000000000032761507046215500146430ustar00rootroot00000000000000LinuxGpib guile extension version 0.0.1 ======================================= The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. INSTALLATION To install this module type the following: $ make $ make install USAGE In order to use the module you need to ensure that the libgpib-guile library can be located by the dynamic loader (e.g. by setting LD_LIBRARY_PATH appropriately). Then type this: $ guile guile> (primitive-load "gpib.scm") guile> (gpib:init) guile> (gpib:open 0 13 0 11 1 (char->integer '\n')) .. etc. ... DEPENDENCIES This module requires these other modules and libraries: libgpib (tested with linux-gpib version 4.3.7) libguile (tested with guile version 1.8.8) COPYRIGHT AND LICENCE This file is part of LinuxGpib. LinuxGpib is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. LinuxGpib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LinuxGpib; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright (C) 2003 Stefan Jahn language/guile/gpib.c000066400000000000000000000254341507046215500150500ustar00rootroot00000000000000/* * gpib.c - guile binding for LinuxGpib * * Copyright (C) 2003 Stefan Jahn * * LinuxGpib is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LinuxGpib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LinuxGpib; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include #include #include "gpib.h" #define FUNC_NAME "ibdev" SCM guile_ibdev (SCM board_index, SCM pad, SCM sad, SCM timeout, SCM eoi, SCM eos) { int fd, _eoi; SCM_ASSERT_TYPE (SCM_EXACTP (board_index), board_index, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (pad), pad, SCM_ARG2, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (sad), sad, SCM_ARG3, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (timeout), timeout, SCM_ARG4, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (eoi) || SCM_BOOLP (eoi), eoi, SCM_ARG5, FUNC_NAME, "exact or bool"); SCM_ASSERT_TYPE (SCM_EXACTP (eos), eos, SCM_ARG6, FUNC_NAME, "exact"); if (SCM_BOOLP (eoi)) _eoi = SCM_NFALSEP (eoi); else _eoi = SCM_NUM2INT (SCM_ARG5, eoi); if ((fd = ibdev (SCM_NUM2INT (SCM_ARG1, board_index), SCM_NUM2INT (SCM_ARG2, pad), SCM_NUM2INT (SCM_ARG3, sad), SCM_NUM2INT (SCM_ARG4, timeout), _eoi, SCM_NUM2INT (SCM_ARG6, eos))) < 0) { scm_syserror (FUNC_NAME); } return scm_int2num (fd); } #undef FUNC_NAME #define FUNC_NAME "ibwrt" SCM guile_ibwrt (SCM ud, SCM data) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_STRINGP (data), data, SCM_ARG2, FUNC_NAME, "string"); if ((ret = ibwrt (SCM_NUM2INT (SCM_ARG1, ud), SCM_STRING_CHARS (data), SCM_NUM2INT (SCM_ARG2, scm_string_length (data)))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibcmd" SCM guile_ibcmd (SCM ud, SCM commands) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_STRINGP (commands), commands, SCM_ARG2, FUNC_NAME, "string"); if ((ret = ibcmd (SCM_NUM2INT (SCM_ARG1, ud), SCM_STRING_CHARS (commands), SCM_NUM2INT (SCM_ARG2, scm_string_length (commands)))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibrd" SCM guile_ibrd (SCM ud, SCM bytes) { int ret, len; char *data; SCM val; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (bytes), bytes, SCM_ARG2, FUNC_NAME, "exact"); len = SCM_NUM2INT (SCM_ARG2, bytes); if ((data = (char *) malloc (len)) == NULL) { scm_memory_error (FUNC_NAME); } if ((ret = ibrd (SCM_NUM2INT (SCM_ARG1, ud), data, len)) & ERR) { free (data); return SCM_BOOL_F; } val = scm_mem2string (data, ibcnt); free (data); return val; } #undef FUNC_NAME #define FUNC_NAME "ibfind" SCM guile_ibfind (SCM name) { char *str; int ret; SCM_ASSERT_TYPE (SCM_STRINGP (name), name, SCM_ARG1, FUNC_NAME, "string"); str = guile_to_string (name); if ((ret = ibfind (str)) < 0) { free (str); return SCM_BOOL_F; } free (str); return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibsre" SCM guile_ibsre (SCM ud, SCM enable) { int ret, val; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (enable) || SCM_BOOLP (enable), enable, SCM_ARG2, FUNC_NAME, "exact or bool"); if (SCM_BOOLP (enable)) val = SCM_NFALSEP (enable); else val = SCM_NUM2INT (SCM_ARG2, enable); if ((ret = ibsre (SCM_NUM2INT (SCM_ARG1, ud), val)) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibsic" SCM guile_ibsic (SCM ud) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); if ((ret = ibsic (SCM_NUM2INT (SCM_ARG1, ud))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibclr" SCM guile_ibclr (SCM ud) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); if ((ret = ibclr (SCM_NUM2INT (SCM_ARG1, ud))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibonl" SCM guile_ibonl (SCM ud, SCM online) { int ret, val; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (online) || SCM_BOOLP (online), online, SCM_ARG2, FUNC_NAME, "exact or bool"); if (SCM_BOOLP (online)) val = SCM_NFALSEP (online); else val = SCM_NUM2INT (SCM_ARG2, online); if ((ret = ibonl (SCM_NUM2INT (SCM_ARG1, ud), val)) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibwait" SCM guile_ibwait (SCM ud, SCM status_mask) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (status_mask), status_mask, SCM_ARG2, FUNC_NAME, "exact"); if ((ret = ibwait (SCM_NUM2INT (SCM_ARG1, ud), SCM_NUM2INT (SCM_ARG2, status_mask))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibrsp" SCM guile_ibrsp (SCM ud) { int ret; char poll[16]; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); if ((ret = ibrsp (SCM_NUM2INT (SCM_ARG1, ud), poll)) & ERR) { return SCM_BOOL_F; } return scm_int2num (poll[0]); } #undef FUNC_NAME #define FUNC_NAME "ibtrg" SCM guile_ibtrg (SCM ud) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); if ((ret = ibtrg (SCM_NUM2INT (SCM_ARG1, ud))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "ibrsv" SCM guile_ibrsv (SCM ud, SCM status_byte) { int ret; SCM_ASSERT_TYPE (SCM_EXACTP (ud), ud, SCM_ARG1, FUNC_NAME, "exact"); SCM_ASSERT_TYPE (SCM_EXACTP (status_byte), status_byte, SCM_ARG2, FUNC_NAME, "exact"); if ((ret = ibrsv (SCM_NUM2INT (SCM_ARG1, ud), SCM_NUM2INT (SCM_ARG2, status_byte))) & ERR) { return SCM_BOOL_F; } return scm_int2num (ret); } #undef FUNC_NAME #define FUNC_NAME "iberr" SCM guile_iberr (void) { return scm_int2num (iberr); } #undef FUNC_NAME #define FUNC_NAME "ibcnt" SCM guile_ibcnt (void) { return scm_long2num (ibcntl); } #undef FUNC_NAME #pragma GCC diagnostic warning "-Wincompatible-pointer-types" void gpib_bindings (void) { scm_c_define_gsubr ("ibdev", 6, 0, 0, guile_ibdev); scm_c_define_gsubr ("ibwrt", 2, 0, 0, guile_ibwrt); scm_c_define_gsubr ("ibcmd", 2, 0, 0, guile_ibcmd); scm_c_define_gsubr ("ibrd", 2, 0, 0, guile_ibrd); scm_c_define_gsubr ("ibfind", 1, 0, 0, guile_ibfind); scm_c_define_gsubr ("ibsre", 2, 0, 0, guile_ibsre); scm_c_define_gsubr ("ibsic", 1, 0, 0, guile_ibsic); scm_c_define_gsubr ("ibclr", 1, 0, 0, guile_ibclr); scm_c_define_gsubr ("ibonl", 2, 0, 0, guile_ibonl); scm_c_define_gsubr ("ibwait", 2, 0, 0, guile_ibwait); scm_c_define_gsubr ("ibrsp", 1, 0, 0, guile_ibrsp); scm_c_define_gsubr ("ibtrg", 1, 0, 0, guile_ibtrg); scm_c_define_gsubr ("ibrsv", 1, 0, 0, guile_ibrsv); scm_c_define_gsubr ("iberr", 0, 0, 0, guile_iberr); scm_c_define_gsubr ("ibcnt", 0, 0, 0, guile_ibcnt); scm_c_define ("DCAS", scm_int2num (DCAS)); scm_c_define ("DTAS", scm_int2num (DTAS)); scm_c_define ("LACS", scm_int2num (LACS)); scm_c_define ("TACS", scm_int2num (TACS)); scm_c_define ("ATN", scm_int2num (ATN)); scm_c_define ("CIC", scm_int2num (CIC)); scm_c_define ("REM", scm_int2num (REM)); scm_c_define ("LOK", scm_int2num (LOK)); scm_c_define ("CMPL", scm_int2num (CMPL)); scm_c_define ("EVENT", scm_int2num (EVENT)); scm_c_define ("SPOLL", scm_int2num (SPOLL)); scm_c_define ("RQS", scm_int2num (RQS)); scm_c_define ("SRQI", scm_int2num (SRQI)); scm_c_define ("END", scm_int2num (END)); scm_c_define ("TIMO", scm_int2num (TIMO)); scm_c_define ("ERR", scm_int2num (ERR)); scm_c_define ("GTL", scm_int2num (GTL)); scm_c_define ("SDC", scm_int2num (SDC)); scm_c_define ("PPC", scm_int2num (PPC)); scm_c_define ("GET", scm_int2num (GET)); scm_c_define ("TCT", scm_int2num (TCT)); scm_c_define ("LLO", scm_int2num (LLO)); scm_c_define ("DCL", scm_int2num (DCL)); scm_c_define ("PPU", scm_int2num (PPU)); scm_c_define ("SPE", scm_int2num (SPE)); scm_c_define ("SPD", scm_int2num (SPD)); scm_c_define ("UNL", scm_int2num (UNL)); scm_c_define ("UNT", scm_int2num (UNT)); scm_c_define ("PPD", scm_int2num (PPD)); scm_c_define ("EDVR", scm_int2num (EDVR)); scm_c_define ("ECIC", scm_int2num (ECIC)); scm_c_define ("ENOL", scm_int2num (ENOL)); scm_c_define ("EADR", scm_int2num (EADR)); scm_c_define ("EARG", scm_int2num (EARG)); scm_c_define ("ESAC", scm_int2num (ESAC)); scm_c_define ("EABO", scm_int2num (EABO)); scm_c_define ("ENEB", scm_int2num (ENEB)); scm_c_define ("EOIP", scm_int2num (EOIP)); scm_c_define ("ECAP", scm_int2num (ECAP)); scm_c_define ("EFSO", scm_int2num (EFSO)); scm_c_define ("EBUS", scm_int2num (EBUS)); scm_c_define ("ESTB", scm_int2num (ESTB)); scm_c_define ("ESRQ", scm_int2num (ESRQ)); scm_c_define ("ETAB", scm_int2num (ETAB)); scm_c_define ("REOS", scm_int2num (REOS)); scm_c_define ("XEOS", scm_int2num (XEOS)); scm_c_define ("BIN", scm_int2num (BIN)); scm_c_define ("TNONE", scm_int2num (TNONE)); scm_c_define ("T10us", scm_int2num (T10us)); scm_c_define ("T30us", scm_int2num (T30us)); scm_c_define ("T100us", scm_int2num (T100us)); scm_c_define ("T300us", scm_int2num (T300us)); scm_c_define ("T1ms", scm_int2num (T1ms)); scm_c_define ("T3ms", scm_int2num (T3ms)); scm_c_define ("T10ms", scm_int2num (T10ms)); scm_c_define ("T30ms", scm_int2num (T30ms)); scm_c_define ("T100ms", scm_int2num (T100ms)); scm_c_define ("T300ms", scm_int2num (T300ms)); scm_c_define ("T1s", scm_int2num (T1s)); scm_c_define ("T3s", scm_int2num (T3s)); scm_c_define ("T10s", scm_int2num (T10s)); scm_c_define ("T30s", scm_int2num (T30s)); scm_c_define ("T100s", scm_int2num (T100s)); scm_c_define ("T300s", scm_int2num (T300s)); scm_c_define ("T1000s", scm_int2num (T1000s)); } extern void gpib_init () { scm_add_feature ("gpib"); gpib_bindings (); } language/guile/gpib.h000066400000000000000000000046451507046215500150560ustar00rootroot00000000000000/* * gpib.h - guile binding for LinuxGpib * * Copyright (C) 2003 Stefan Jahn * * LinuxGpib is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LinuxGpib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LinuxGpib; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef SCM_GPIB_H #define SCM_GPIB_H 1 #if defined (SCM_MINOR_VERSION) && (SCM_MINOR_VERSION >= 5) && \ defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION >= 1) #define SCM_VERSION_15X 1 #endif #if defined (SCM_MINOR_VERSION) && (SCM_MINOR_VERSION >= 7) && \ defined (SCM_MAJOR_VERSION) && (SCM_MAJOR_VERSION >= 1) #define SCM_VERSION_17X 1 #endif #ifndef SCM_VERSION_17X #define scm_c_string2str(obj, str, lenp) gh_scm2newstr (obj, lenp) #endif #ifndef SCM_VERSION_17X #define scm_c_symbol2str(obj, str, lenp) gh_symbol2newstr (obj, lenp) #endif #define guile_to_string(cell) \ (SCM_NULLP (cell) ? NULL : \ (SCM_STRINGP (cell) ? scm_c_string2str (cell, NULL, NULL) : \ (SCM_SYMBOLP (cell) ? scm_c_symbol2str (cell, NULL, NULL) : NULL))) #ifndef SCM_EXACTP #define SCM_EXACTP(obj) SCM_NFALSEP (scm_exact_p (obj)) #endif #ifndef SCM_NUM2INT #define SCM_NUM2INT(pos, obj) gh_scm2int (obj) #endif #ifndef SCM_BOOLP #define SCM_BOOLP(obj) SCM_NFALSEP (scm_boolean_p (obj)) #endif #ifndef SCM_BOOL #define SCM_BOOL(x) ((x) ? SCM_BOOL_T : SCM_BOOL_F) #endif #ifndef SCM_STRING_CHARS #define SCM_STRING_CHARS(obj) ((char *) SCM_VELTS (obj)) #endif #ifndef SCM_VERSION_15X #define scm_c_define_gsubr(name, req, opt, rst, fcn) \ gh_new_procedure (name, fcn, req, opt, rst) #endif #ifndef SCM_VERSION_15X #define scm_int2num(x) scm_long2num ((long) (x)) #endif #ifndef SCM_VERSION_15X #define scm_mem2string(str, len) gh_str2scm (str, len) #endif #ifndef SCM_VERSION_15X #define scm_c_define(name, val) gh_define (name, val) #endif #endif /* SCM_GPIB_H */ language/guile/gpib.scm000066400000000000000000000071101507046215500153770ustar00rootroot00000000000000;; ;; gpib.scm - guile binding for LinuxGpib ;; ;; Copyright (C) 2003 Stefan Jahn ;; ;; LinuxGpib is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; LinuxGpib is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with LinuxGpib; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; (define (println . args) (for-each display args) (newline)) (define gpib:handle '()) (define (gpib:init) (catch 'misc-error (lambda () (if (not (feature? 'gpib)) (begin (set! gpib:handle (dynamic-link "libgpib-guile.so")) (dynamic-call "gpib_init" gpib:handle)))) (lambda args #f))) (define (gpib:halt) (if (dynamic-object? gpib:handle) (begin (dynamic-unlink gpib:handle) (set! gpib:handle '())))) (define (gpib:open index pad sad timeout eoi eos) (ibdev index pad sad timeout eoi eos)) (define (gpib:command fd list) (let* ((clist '())) (for-each (lambda (c) (set! clist (cons (integer->char c) clist))) list) (ibcmd fd (list->string (reverse clist))))) (define (gpib:write fd string) (ibwrt fd string)) (define (gpib:read fd bytes) (ibrd fd bytes)) (define (gpib:find name) (ibfind name)) (define (gpib:remote-enable fd enable) (ibsre fd enable)) (define (gpib:interface-clear fd) (ibsic fd)) (define (gpib:device-clear fd) (ibclr fd)) (define (gpib:reset fd) (ibonl fd 1)) (define (gpib:close fd) (ibonl fd 0)) (define (gpib:wait fd status) (ibwait fd status)) (define (gpib:serial-poll fd) (ibrsp fd)) (define (gpib:trigger fd) (ibtrg fd)) (define (gpib:request-service fd service) (ibrsv fd service)) (define (gpib:error-code) (iberr)) (define (gpib:counter) (ibcnt)) (define (gpib:error) (let* ((error (iberr))) (cond ((equal? error EDVR) "") ((equal? error ECIC) "") ((equal? error ENOL) "") ((equal? error EADR) "") ((equal? error ECIC) "") ((equal? error ESAC) "") ((equal? error EABO) "") ((equal? error ENEB) "") ((equal? error EOIP) "") ((equal? error ECAP) "") ((equal? error EFSO) "") ((equal? error EBUS) "") ((equal? error ESTB) "") ((equal? error ESRQ) "") ((equal? error ETAB) "")))) (export ;; public Gpib procedures gpib:init gpib:halt gpib:open gpib:command gpib:write gpib:read gpib:find gpib:remote-enable gpib:interface-clear gpib:device-clear gpib:close gpib:reset gpib:wait gpib:serial-poll gpib:trigger gpib:request-service gpib:error-code gpib:counter gpib:error ;; status byte DCAS DTAS LACS TACS ATN CIC REM LOK CMPL EVENT SPOLL RQS SRQI END TIMO ERR ;; public Gpib commands GTL SDC PPC GET TCT LLO DCL PPU SPE SPD UNL UNT PPD ;; timeout constants TNONE T10us T30us T100us T300us T1ms T3ms T10ms T30ms T100ms T300ms T1s T3s T10s T30s T100s T300s T1000s ;; end-of-string constants REOS XEOS BIN ) language/perl/000077500000000000000000000000001507046215500136105ustar00rootroot00000000000000language/perl/Changes000066400000000000000000000002661507046215500151070ustar00rootroot00000000000000Revision history for Perl extension LinuxGpib. 0.01 Sun Oct 6 15:22:15 2002 - original version; created by h2xs 1.21 with options -Oxan LinuxGpib /usr/local/include/gpib/ib.h language/perl/LinuxGpib.pm000066400000000000000000000120531507046215500160500ustar00rootroot00000000000000package LinuxGpib; use 5.006; use strict; use warnings; use Carp; require Exporter; require DynaLoader; use AutoLoader; our @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use LinuxGpib ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ibcac ibclr ibcmd ibconfig ibdev ibdma ibeot ibevent ibfind ibgts iblines ibloc ibonl ibpad ibrd ibrdi ibrpp ibrsp ibrsv ibsad ibsic ibsre ibtmo ibtrg ibwait ibwrt ibwrti ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.01'; use constant EDVR => 0; use constant ECIC => 1; use constant ENOL => 2; use constant EADR => 3; use constant EARG => 4; use constant ESAC => 5; use constant EABO => 6; use constant ENEB => 7; use constant EDMA => 8; use constant EBTO => 9; use constant EOIP => 10; use constant ECAP => 11; use constant EFSO => 12; use constant EOWN => 13; use constant EBUS => 14; use constant ESTB => 15; use constant ESRQ => 16; use constant ETAB => 20; use constant ELCK => 21; use constant TNONE => 0; use constant T10us => 1; use constant T30us => 2; use constant T100us => 3; use constant T300us => 4; use constant T1ms => 5; use constant T3ms => 6; use constant T10ms => 7; use constant T30ms => 8; use constant T100ms => 9; use constant T300ms => 10; use constant T1s => 11; use constant T3s => 12; use constant T10s => 13; use constant T30s => 14; use constant T100s => 15; use constant T300s => 16; use constant T1000s => 17; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant() # XS function. If a constant is not found then control is passed # to the AUTOLOAD in AutoLoader. my $constname; our $AUTOLOAD; ($constname = $AUTOLOAD) =~ s/.*:://; croak "& not defined" if $constname eq 'constant'; my $val = constant($constname, @_ ? $_[0] : 0); if ($! != 0) { if ($! =~ /Invalid/ || $!{EINVAL}) { $AutoLoader::AUTOLOAD = $AUTOLOAD; goto &AutoLoader::AUTOLOAD; } else { croak "Your vendor has not defined LinuxGpib macro $constname"; } } { no strict 'refs'; # Fixed between 5.005_53 and 5.005_61 if ($] >= 5.00561) { *$AUTOLOAD = sub () { $val }; } else { *$AUTOLOAD = sub { $val }; } } goto &$AUTOLOAD; } bootstrap LinuxGpib $VERSION; # Preloaded methods go here. sub new { my $pkg = shift; my $dev = undef; my $i; if (@_ == 1) { $dev = ibfind($_[0]); } elsif (@_ == 6) { $dev = ibdev(@_); } else { die("Bad parameter list to LinuxGpib::new($pkg @_)"); } # This has to be tested changed (use status vars) # deadlock, if device not found bless \$dev, $pkg; return $dev; } # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME LinuxGpib - Perl extension for Gpib (uses libgpib from http://linux-gpib.sourceforge.net) =head1 SYNOPSIS use Gpib; =head1 DESCRIPTION This module allows access to libgpib.so from within Perl. WARNING: Not all functions have been tested yet! USE IT AT YOUR OWN RISK! =head2 EXPORT None by default. =head2 Exportable functions int ibcac(int ud, int v) int ibclr(int ud) int ibcmd(int ud, char *cmd, unsigned long cnt) int ibconfig( int ud, int option, int value ) int ibdev(int minor, int pad, int sad, int timo, int eot, int eos) int ibdma( int ud, int v ) int ibeot(int ud, int v) int ibevent(int ud, short *event) int ibfind(char *dev) int ibgts(int ud, int v) int iblines(int ud, unsigned short *buf) int ibloc(int ud) int ibonl(int ud, int onl) int ibpad(int ud, int v) int ibrd(int ud, char *rd, unsigned long cnt) int ibrdi(int ud, char *rd, unsigned long cnt) int ibrpp(int ud, char *ppr) int ibrsp(int ud, char *spr) int ibrsv(int ud, int v) int ibsad(int ud, int v) int ibsic(int ud) int ibsre(int ud, int v) int ibtmo(int ud,int v) int ibtrg(int ud) int ibwait(int ud, int mask) int ibwrt(int ud, char *rd, unsigned long cnt) int ibwrti(int ud, char *rd, unsigned long cnt) =head1 AUTHOR Thomas Nisius =head1 SEE ALSO =cut language/perl/LinuxGpib.xs000066400000000000000000000055431507046215500160740ustar00rootroot00000000000000#include #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include static int not_here(char *s) { croak("%s not implemented on this architecture", s); return -1; } static double constant(char *name, int len, int arg) { errno = EINVAL; return 0; } MODULE = LinuxGpib PACKAGE = LinuxGpib PROTOTYPES: ENABLE double constant(sv,arg) PREINIT: STRLEN len; INPUT: SV *sv char *s = SvPV(sv, len); int arg CODE: RETVAL = constant(s,len,arg); OUTPUT: RETVAL int ibcac(ud, v) int ud int v int ibclr(ud) int ud int ibcmd(ud, cmd, cnt) int ud char * cmd unsigned long cnt int ibconfig(ud, option, value) int ud int option int value int ibdev(minor, pad, sad, timo, eot, eos) int minor int pad int sad int timo int eot int eos int ibdma(ud, v) int ud int v int ibeot(ud, v) int ud int v int ibevent(int ud, OUT short event) int ibfind(dev) char * dev int ibgts(ud, v) int ud int v int iblines(int ud, OUT short line_status) int ibloc(ud) int ud int ibonl(ud, onl) int ud int onl int ibpad(ud, v) int ud int v int ibrd(ud, rd, cnt) int ud SV *rd unsigned long cnt PREINIT: char *buf; CODE: buf = malloc( cnt + 1 ); if( buf == NULL ) croak( "malloc() returned NULL in ibrd()\n" ); RETVAL = ibrd(ud, buf, cnt); sv_setpvn(rd, buf, ThreadIbcntl()); free( buf ); OUTPUT: RETVAL int ibrdi(ud, array, cnt) int ud AV *array unsigned long cnt PREINIT: int i; char *buf; CODE: av_clear( array ); buf = malloc( cnt ); if( buf == NULL ) croak( "malloc() returned NULL in ibrdi()\n" ); RETVAL = ibrd(ud, buf, cnt); if( ( RETVAL & ERR ) == 0 ) { for( i = 0; i < ThreadIbcntl(); i++ ) { av_push( array, newSViv( buf[ i ] & 0xff ) ); } } free( buf ); OUTPUT: RETVAL int ibrpp(ud, ppr) int ud SV *ppr CODE: char response; RETVAL = ibrsp( ud, &response ); if( ( RETVAL & ERR ) == 0 ) sv_setiv( ppr, response ); OUTPUT: RETVAL int ibrsp(ud, result) int ud SV *result CODE: char status; RETVAL = ibrsp( ud, &status ); if( ( RETVAL & ERR ) == 0 ) sv_setiv( result, status ); OUTPUT: RETVAL int ibrsv(ud, v) int ud int v int ibsad(ud, v) int ud int v int ibsic(ud) int ud int ibsre(ud, v) int ud int v int ibtmo(ud, v) int ud int v int ibtrg(ud) int ud int ibwait(ud, mask) int ud int mask int ibwrt(ud, rd, cnt) int ud char * rd unsigned long cnt int ibwrti(ud, array, cnt) int ud AV *array unsigned long cnt PREINIT: int i; char *buf; SV **sv_ptr; CODE: buf = malloc( cnt ); if( buf == NULL ) croak( "malloc() returned NULL in ibwrti()\n" ); for( i = 0; i < cnt; i++ ) { sv_ptr = av_fetch( array, i, 0 ); if( sv_ptr == NULL ) croak( "av_fetch returned NULL in ibwrti()\nn" ); buf[ i ] = SvIV(*sv_ptr); } RETVAL = ibwrt(ud, buf, cnt); free( buf ); OUTPUT: RETVAL int ThreadIbsta() int ThreadIberr() int ThreadIbcnt() long ThreadIbcntl() language/perl/MANIFEST000066400000000000000000000001171507046215500147400ustar00rootroot00000000000000Changes LinuxGpib.pm LinuxGpib.xs Makefile.PL MANIFEST README test.pl typemap language/perl/Makefile.PL.in000066400000000000000000000012561507046215500161730ustar00rootroot00000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'LinuxGpib', 'VERSION_FROM' => 'LinuxGpib.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 # 'ABSTRACT_FROM' => 'LinuxGpib.pm', # retrieve abstract from module 'AUTHOR' => 'Thomas Nisius ', 'LIBS' => ['-L@abs_top_builddir@/lib/.libs -lgpib -lpthread'], # 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '-I@abs_top_srcdir@/include', # 'OBJECT' => '$(O_FILES)', # link all the C files too 'DISTNAME' => 'LinuxGpib', ); language/perl/README000066400000000000000000000032101507046215500144640ustar00rootroot00000000000000LinuxGpib version 0.01 ====================== The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: libgpib (only tested with version 3.1.6) COPYRIGHT AND LICENCE This file is part of LinuxGpib. LinuxGpib is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. LinuxGpib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LinuxGpib; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright (C) 2002 Thomas Nisius language/perl/examples/000077500000000000000000000000001507046215500154265ustar00rootroot00000000000000language/perl/examples/n8ur/000077500000000000000000000000001507046215500163225ustar00rootroot00000000000000language/perl/examples/n8ur/hp3585b-control.pl000066400000000000000000000116501507046215500214360ustar00rootroot00000000000000#!/usr/bin/perl # # hp3585b-control.pl # version 0.8 -- 23 June 2003 # # Basic control of HP 3585B Spectrum Analyzer # # Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) # Licensed under the GPL version 2 or later; see the file COPYING # included with this distribution. I request, but do not require, that # any modifications that correct bugs or errors, or increase the program's # functionality, be sent via email to the author at the address above. # # Current status: # # Version 0.8 -- No code changes, but now licensed under the GPL. # # Version 0.7 -- basic functionality seems to work OK, with (very) modest # input validation. #---------- use strict; use POSIX qw(setsid); use Getopt::Std; use Time::HiRes qw(usleep time gettimeofday); use LinuxGpib; use GD; use GD::Text; use GD::Graph::mixed; use GD::Graph::colour; use Number::Format; use n8ur qw(trim squash parse_value); use hp3585b qw(get_settings fix_freq fix_db fix_sweep); my $device = "hp3585b"; my $j; my $command; my $reading; my $counter = 1; my $gpib_status; my $tmp_val; my $tmp_suffix; #---------- # usage and option initialization my $opt_string = 'hpc:d:s:l:a:r:v:t:b:'; sub usage() { print STDERR << "EOF"; usage: $0 [-p] [-c center freq] [-s span] [-l ref level] [-a range] [-r rbw] [-v vbw] [t sweep time] [-b db/div] [-h help] [-d device] This program provides basic control of an HP 8569B spectrum analyzer and displays current settings. Use value suffixes of Hz, kHz, MHz, dB, dBm, dBv as appropriate. If not specified, params are unchanged. Default device is "hp3585b". "-p" does an instrument preset EOF } #---------------------- getopts( "$opt_string", \my %opt ) or usage() and exit; usage() and exit if $opt{h}; my $preset = 0; if ($opt{p}) { $preset = 1; } if ($opt{d}) { $device = $opt{d}; } my $range = ""; if ($opt{a}) { my $tmp = trim($opt{a}); if ($tmp eq "-25") {$range = "AR0R01" }; if ($tmp eq "-20") {$range = "AR0R02" }; if ($tmp eq "-15") {$range = "AR0R03" }; if ($tmp eq "-10") {$range = "AR0R04" }; if (($tmp eq "-5") || ($tmp eq "-05")) {$range = "AR0R05" }; if ($tmp eq "0") {$range = "AR0R06" }; if (($tmp eq "5") || ($tmp eq "05")) {$range = "AR0R07" }; if ($tmp eq "10") {$range = "AR0R08" }; if ($tmp eq "15") {$range = "AR0R09" }; if ($tmp eq "20") {$range = "AR0R10" }; if ($tmp eq "25") {$range = "AR0R11" }; if ($tmp eq "30") {$range = "AR0R12" }; } my $db_div = ""; if ($opt{b}) { $tmp_val = fix_db($opt{b}); if ( ($tmp_val ne "10") && ($tmp_val ne "5") && ($tmp_val ne "2") && ($tmp_val ne "1") ) { die "Invalid dB/div value!"} else { $db_div = "DD" . $tmp_val . "DB"; } } my $cf = ""; if ($opt{c}) { $tmp_val = fix_freq($opt{c}); if ($tmp_val eq "") { die "Invalid Center Frequency value!"} else { $cf = "CF" . $tmp_val; } } my $fs = ""; if ($opt{s}) { $tmp_val = fix_freq($opt{s}); if ($tmp_val eq "") { die "Invalid Span value!"} else { $fs = "FS" . $tmp_val; } } my $rbw = ""; if ($opt{r}) { $tmp_val = fix_freq($opt{r}); if ($tmp_val eq "") { die "Invalid RBW value!"} else { $rbw = "RB" . $tmp_val; } } my $vbw = ""; if ($opt{v}) { $tmp_val = fix_freq($opt{v}); if ($tmp_val eq "") { die "Invalid RBW value!"} else { $rbw = "VB" . $tmp_val; } } my $rl = ""; if ($opt{l}) { $tmp_val = fix_db($opt{l}); if ($tmp_val eq "") { die "Invalid ref level value!"} else { $rbw = "RL" . $tmp_val; } } my $t = ""; if ($opt{t}) { $tmp_val = fix_sweep($opt{t}); if ($tmp_val eq "") { die "Invalid sweep time value!"} else { $rbw = "ST" . $tmp_val; } } #---------- # initialize instrument my $dev = LinuxGpib::ibfind($device) || die "Can't open device $device!\n"; #---------- # Send command if ($preset) { $command = "PO0"; } else { $command = "AC0" . $cf . $fs . $rbw . $rl . $range . $db_div . "AC1"; } LinuxGpib::ibwrt($dev,$command,length($command)); sleep 3; #---------- # get instrument state my ($start_freq,$center_freq,$stop_freq,$bin_freq,$top_right_pre, $top_right_val,$top_right_suf,$marker_freq,$marker_val,$rbw_val, $vbw_val,$db_div_val,$sweep_val,$sweep_suf,$range_val,$range_suf, $ref_val,$ref_suf,$ref_bottom,$span_val) = get_settings($dev); #---------- # create annotation strings for plotting my $numfmt = new Number::Format(-thousands_sep => ' ', -decimal_point => '.'); my $annotation1= $top_right_pre . ": " . $numfmt->format_number($top_right_val) . " Hz, " . $marker_val . " " . $ref_suf; my $annotation2= "RBW: " . $rbw_val . " Hz VBW: " . $vbw_val . " Hz Scale: " . $db_div_val . " dB/ Sweep: " . $sweep_val . " Sec. Range: " . $range_val . " " . $range_suf; print "\n"; print "Center: " . $numfmt->format_number($center_freq) . " Hz Span: " . $numfmt->format_number(squash($span_val)) . " Hz (" . squash($span_val)/10 . " Hz/)\n"; print "Start: " . $numfmt->format_number($start_freq) . " Hz Stop: " . $numfmt->format_number($stop_freq) . " Hz\n\n"; print $annotation1,"\n\n"; print "Ref. Level: " . $ref_val . $ref_suf . "\n"; print $annotation2,"\n\n"; language/perl/examples/n8ur/hp3585b-plot.pl000066400000000000000000000303521507046215500207340ustar00rootroot00000000000000#!/usr/bin/perl # # hp3585b-plot.pl # version 0.8 -- 23 June 2003 # # Plot display of HP 3585B Spectrum Analyzer # # Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) # Licensed under the GPL version 2 or later; see the file COPYING # included with this distribution. I request, but do not require, that # any modifications that correct bugs or errors, or increase the program's # functionality, be sent via email to the author at the address above. # # Current status: # Version 0.8 -- no code changes, but now licensed under the GPL. # # Version 0.7 -- works pretty well. Ability to plot "B" trace not yet # implemented, and may never be. If you resize the image from the # default, the text strings probably will not line up properly, so use # that feature at your own risk. # #---------- # Left and center footers; there's also a timestamp in the lower right corner my $left_footer = "HP 3585B \@ N8UR"; my $center_footer = "jra\@febo.com"; use strict; use POSIX qw(setsid); use Getopt::Std; use Time::HiRes qw(usleep time gettimeofday); use LinuxGpib; use GD; use GD::Text; use GD::Graph::mixed; use GD::Graph::colour; use Number::Format; use n8ur qw(trim collapse squash round); use hp3585b qw(make_trace get_settings); my $j; my $reading; my $tracedata; my @tmp_trace; my @traceA; my @min_traceA; my @max_traceA; my $command; my $last_cal; my $time_now; my $counter = 1; my $gpib_status; #---------- # usage and option initialization my $opt_string = 'bdhmr:c:f:t:x:y:v:'; sub usage() { print STDERR << "EOF"; usage: $0 [-h] [-b] [-d ] [-c 1..4] [-r] [[-v num_sweeps [-m]] [-x pixels -y pixels] [-t title] -f filename This program collects data from an HP 8569B spectrum analyzer and generates a PNG format graphic mimicking the the instrument's display. Most of the options affect the output format. By using the -c and -r options, multiple charts can be created that will overlay nicely on one another. The -r option not only makes the image background transparent, it suppresses the timestamp, so the timestamp of the underlying non-transparent image will not be blurred. The -v option switches the analyzer to single-sweep mode and triggers num_sweeps sweeps, the results of which are averaged into a single display. Adding the -m option to the -v option results in a display which shows the minimum and maximum values captured as well as the average. -h : this (help) message -b : display both traces; default is trace A only -c : use alternate 1 through 4 for trace colors; default is 1 (red,blue) -d : device name (from /etc/gpib.conf); default is "hp8569b" -r : make output file tRansparent and suppress timestamp; default is no -t : optional title (1 line max) -x,-y : output dimension in pixels; default 550x450 -v : video averaging over numsweeps (an integer from 1 to whatever) -m : show minimum and maximum values as well as average -f : filename for output PNG EOF } #---------------------- getopts( "$opt_string", \my %opt ) or usage() and exit; usage() and exit if $opt{h}; usage() and exit if !$opt{f}; # set variables to command line params my $picfile = $opt{f}; my $both = 0; if ($opt{b}) { $both = 1; } my $colorset = 1; if ($opt{c}) { $colorset = $opt{c}; } my $device = "hp3585b"; if ($opt{d}) { $device = $opt{d}; } my $transparent = 0; if ($opt{r}) { $transparent = 1; } # title my $title = ""; if ($opt{t}) { $title = $opt{t}; } # x size my $x = 550; if ($opt{x}) { $x = $opt{x}; } # y size my $y = 450; if ($opt{y}) { $y = $opt{y}; } # video averaging my $num_sweeps = 0; if ($opt{v}) { $num_sweeps = $opt{v}; } my $min_max = 0; if ($opt{m}) { $min_max = 1; } # set up picfile open (PIC, ">$picfile") || die "Can't open image file $picfile!\n"; # initialize instrument my $dev = LinuxGpib::ibfind($device) || die "Can't open device $device!\n"; #---------- my ($start_freq,$center_freq,$stop_freq,$bin_freq,$top_right_pre, $top_right_val,$top_right_suf,$marker_freq,$marker_val,$rbw_val, $vbw_val,$db_div_val,$sweep_val,$sweep_suf,$range_val,$range_suf, $ref_val,$ref_suf,$ref_bottom,$span_val) = get_settings($dev); #---------- # get data if ($num_sweeps == 0) { # get trace data - normal mode print "Getting trace in normal mode...\n"; $command = "TS5BD5"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$tracedata,2004); @traceA = make_trace($tracedata); } else { # get trace data - video averaging mode # set nonbuffered mode select(STDOUT), $| = 1; print "Generating Video Average over ",$num_sweeps, " sweeps (",$sweep_val," ",$sweep_suf,"/sweep):\n"; # set timeout; we get some long sweep times # 15 = 100s, 16 = 300s, 17 = 1000s LinuxGpib::ibtmo($dev,16); usleep(10000); # clear trace and set single sweep with operation-complete interrupt $command = "CACQ"; LinuxGpib::ibwrt($dev,$command,length($command)); usleep(10000); $command = "S2"; LinuxGpib::ibwrt($dev,$command,length($command)); usleep(10000); # initiate a calibration and set last cal time $command = "AC1"; $last_cal = time; LinuxGpib::ibwrt($dev,$command,length($command)); while ($counter <= $num_sweeps) { $time_now = time; if (($time_now - $last_cal) > 90) { # initiate a calibration and set last cal time $command = "AC1"; LinuxGpib::ibwrt($dev,$command,length($command)); $last_cal = time; } # poll status LinuxGpib::ibrsp($dev,$gpib_status); # trigger a sweep $command = "S2"; LinuxGpib::ibwrt($dev,$command,length($command)); usleep(175000); # wait until SRQ $gpib_status = LinuxGpib::ibwait($dev,(0x800 | 0x4000)); if ($gpib_status & 0x4000) { print "Failure: TIMO\n ";} # get reading $command = "TS5BD5"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$tracedata,2004); @tmp_trace = make_trace($tracedata); for ($j=0;$j<=1000;$j++) { $traceA[$j] += $tmp_trace[$j]; if ($counter == 1) { $min_traceA[$j] = $tmp_trace[$j]; $max_traceA[$j] = $tmp_trace[$j]; } else { if ($tmp_trace[$j] < $min_traceA[$j]) { $min_traceA[$j] = $tmp_trace[$j]; } if ($tmp_trace[$j] > $max_traceA[$j]) { $max_traceA[$j] = $tmp_trace[$j]; } } } $counter++; print "."; } # set back to continuous sweep and clear trace $command = "S1CA"; LinuxGpib::ibwrt($dev,$command,length($command)); print "\n\n"; } # convert trace values to dBm if necessary for ($j=0;$j<=1000;$j++) { if ($num_sweeps) { $traceA[$j] /= $num_sweeps; } if ($ref_suf eq "dBm") { $traceA[$j] += 13; $min_traceA[$j] += 13; $max_traceA[$j] += 13; } } # create x axis labels and marker plot my @x_array = (); my @marker_array = (); my $seed = $start_freq; for ($j = 0; $j <= 1000; $j++) { $x_array[$j] = $seed; if ($marker_freq == $seed) { if ($num_sweeps) { $marker_val = trim(sprintf("%5.2f",$traceA[$j])); } $marker_array[$j] = $marker_val; } else { $marker_array[$j] = undef; } $seed = round(4,($seed + $bin_freq)); } # create annotation strings for plotting if ($db_div_val == 10) { $marker_val = trim(sprintf("%5.1f",round(1,$marker_val))); } else { $marker_val = trim(sprintf("%5.2f",round(2,$marker_val))); } my $numfmt = new Number::Format(-thousands_sep => ' ', -decimal_point => '.'); my $annotation1= $top_right_pre . ": " . $numfmt->format_number($top_right_val) . " Hz, " . $marker_val . " " . $ref_suf; my $annotation2= "RBW: " . $rbw_val . " Hz VBW: " . $vbw_val . " Hz Scale: " . $db_div_val . " dB/ Sweep: " . $sweep_val . " Sec. Range: " . $range_val . " " . $range_suf; # plotting routines # chart types and colors; this is so the marker axis stays in the # right place and is plotted last to overwrite the trace my @chart_set; my @cset; if ($both) { @chart_set = [qw(lines lines points)]; @cset = [qw(lred blue green green)]; if ($colorset == 2) { @cset = [qw(lblue lred black)]; } if ($colorset == 3) { @cset = [qw(green purple black)]; } if ($colorset == 4) { @cset = [qw(purple green black)]; } } else { if ($min_max) { @cset = [qw(lred green green black)]; @chart_set = [qw(lines lines lines points)]; } else { @cset = [qw(lred black)]; @chart_set = [qw(lines points)]; } if ($colorset == 2) { @cset = [qw(lblue black)]; } if ($colorset == 3) { @cset = [qw(green black)]; } if ($colorset == 4) { @cset = [qw(purple black)]; } } # set some dimensions my $l_margin = 15; my $r_margin = 25; my $t_margin = 50; my $b_margin = 35; # format the x axis to nothing at all sub x_format { return ""; } my $spec_display = new GD::Graph::mixed($x,$y); $spec_display->set ( types => @chart_set, dclrs => @cset, markers => [2,2,2,2,2,2,2], marker_size => 3, l_margin => $l_margin, r_margin => $r_margin, t_margin => $t_margin, b_margin => $b_margin, transparent => $transparent, y_max_value => $ref_val, y_min_value => $ref_bottom, y_tick_number => 10, y_long_ticks => 1, x_number_format => \&x_format, x_min_value => $start_freq, x_max_value => $stop_freq, x_tick_number => 10, x_label_skip => 5, x_long_ticks => 1 ); my $foo; #if ($both) { # $foo = $spec_display->plot([\@x_array,\@traceA, # \@traceB,\@marker_array]); # } #else if ($min_max == 0) { $foo = $spec_display->plot([\@x_array,\@traceA,\@marker_array]); } else { $foo = $spec_display->plot([\@x_array,\@traceA,\@min_traceA,\@max_traceA,\@marker_array]); } my $black = $foo->colorAllocate(0,0,0); my $red = $foo->colorAllocate(255,0,0); #----------- # add text and number formatting features my $gd_text = GD::Text->new() or die GD::Text::error(); $gd_text->set_font(gdLargeFont); $gd_text->set_text($title); my ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdLargeFont,($x/2)-($w/2),3,$title,$black); $gd_text->set_font(gdSmallFont); $gd_text->set_text($annotation1); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,($x/2)-($w/2),20,$annotation1,$black); $gd_text->set_font(gdSmallFont); $gd_text->set_text($annotation2); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,($x/2)-($w/2),34,$annotation2,$black); $gd_text->set_font(gdSmallFont); $gd_text->set_text($ref_suf); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,19,32,$ref_suf,$black); if ($num_sweeps > 0) { $gd_text->set_font(gdSmallFont); $gd_text->set_text('VidAvg:'); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,44,57,'VidAvg:',$black); $gd_text->set_font(gdSmallFont); $gd_text->set_text($num_sweeps); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,63-($w/2),70,$num_sweeps,$black); } if ($min_max > 0) { $gd_text->set_font(gdSmallFont); $gd_text->set_text('Min/Max'); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,44,90,'Min/Max',$black); } my $startstring = "Start: " . $numfmt->format_number($start_freq); $gd_text->set_font(gdTinyFont); $gd_text->set_text($startstring); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,50,$y-38,$startstring,$black); my $cfstring = "Center: " . $numfmt->format_number($center_freq) . " Hz"; $gd_text->set_font(gdSmallFont); $gd_text->set_text($cfstring); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,($x/2)-($w/2)+($l_margin/2),$y-40,$cfstring,$black); my $stopstring = "Stop: " . $numfmt->format_number($stop_freq); $gd_text->set_font(gdTinyFont); $gd_text->set_text($stopstring); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,440,$y-38,$stopstring,$black); my $spanstring = "Span: " . $numfmt->format_number(squash($span_val)) . " Hz (" . squash($span_val)/10 . " Hz/)"; ; $gd_text->set_font(gdSmallFont); $gd_text->set_text($spanstring); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,($x/2)-($w/2)+($l_margin/2),$y-26, $spanstring,$black); $gd_text->set_font(gdTinyFont); $gd_text->set_text($left_footer); $foo->string(gdTinyFont,20,$y-10,$left_footer,$black); $gd_text->set_font(gdTinyFont); $gd_text->set_text($center_footer); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,($x/2)-($w/2)+($l_margin/2),$y-10, $center_footer,$black); my $timestamp; if (!$transparent) { $timestamp = gmtime() . " (UTC)"; $gd_text->set_font(gdTinyFont); $gd_text->set_text($timestamp); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,$x-$w-12,$y-10,$timestamp,$black); } binmode PIC; print PIC $foo->png; close PIC; exit 0; language/perl/examples/n8ur/hp3585b.pm000066400000000000000000000211611507046215500177570ustar00rootroot00000000000000package hp3585b; # # John R. Ackermann N8UR (jra@febo.com) # Mon Jun 9 09:19:03 2003 # # hp3585b - Functions for HP 3585B Spectrum Analyzer # # Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) # Licensed under the GPL version 2 or later; see the file COPYING # included with this distribution. I request, but do not require, that # any modifications that correct bugs or errors, or increase the program's # functionality, be sent via email to the author at the address above. use strict; use warnings; use diagnostics; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use n8ur qw(trim squash collapse round parse_value lower_case); $VERSION = '0.01'; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(make_trace get_settings fix_freq fix_db fix_sweep); sub make_trace { # The binary dump starts with two sync bytes, so we throw those away. # Then we convert 1001 pairs of bytes from 2s-complement to integers, # which represent dBV*100 (unless we're doing B-A, in which case they're # pure dB*100). The calling routine needs to add 13 to convert from dBV # to dBm (50 ohm) if that's required. my $j; my $rawtrace = shift; my @trace = unpack 'n*', substr($rawtrace,2,2002); for ($j=0;$j<=1000;$j++) { if ($trace[$j] > 32767) { $trace[$j] -= 65536; } $trace[$j] = ($trace[$j]/100); } return @trace; } sub get_settings { my $command; my $reading; my $dev = shift; # get screen annotation $command = "D7T4"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,174); # parse the string into one variable for each reading; there's much more # work to be done later my ($ref,$top_right,$db_div,$range,$marker,$center,$span,$rbw,$vbw,$sweep) = split(/\n/,$reading); # get marker freq and amplitude (overrides the previous dump) $command = "D2T4"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,26); my ($marker_freq,$marker_val) = split(/,/,$reading); $marker_freq = substr(trim($marker_freq),1); $marker_val = trim(sprintf("%5.2f",trim($marker_val))); #--------------- # Now, start string handling. The annotation data is dumped in a # non-parser-friendly way and breaking all the elements out is a lot more # work than it should be. Varying field lengths and embedded spaces in # frequency strings make life interesting. $ref = trim($ref); my ($ref_pre,$ref_val,$ref_suf) = split(/\s/,$ref); if ($ref_suf eq "DBM") {$ref_suf = "dBm"; } if ($ref_suf eq "DBV") {$ref_suf = "dBV"; } if ($ref_suf eq "DB") {$ref_suf = "dB"; } $top_right = trim($top_right); my $top_right_suf = trim(substr($top_right,length($top_right)-2,2)); my $top_right_pre = trim(substr($top_right,0,index($top_right," "))); if ($top_right_pre eq "COUNTER") {$top_right_pre = "Counter"; } if ($top_right_pre eq "MARKER") {$top_right_pre = "Marker"; } if ($top_right_pre eq "OFFSET") {$top_right_pre = "Offset"; } if ($top_right_pre eq "MANUAL") {$top_right_pre = "Manual"; } my $top_right_val = squash(trim(substr( $top_right,length($top_right_pre), length($top_right)-length($top_right_pre)-length($top_right_suf)))); if ($top_right_suf eq "DBM") {$top_right_suf = "dBm"; } if ($top_right_suf eq "DBV") {$top_right_suf = "dBV"; } if ($top_right_suf eq "DB") {$top_right_suf = "dB"; } $db_div = trim($db_div); my ($db_div_val,$db_div_suf) = split(/\s/,$db_div); $db_div_val = trim($db_div_val); $db_div_suf = trim($db_div_suf); $range = trim($range); my ($range_pre,$range_val,$range_suf) = split(/\s/,$range); $range_pre = trim($range_pre); $range_val = trim($range_val); $range_suf = trim($range_suf); if ($range_suf eq "DBM") {$range_suf = "dBm"; } if ($range_suf eq "DB") {$range_suf = "dB"; } $center = trim($center); my $center_suf = trim(substr($center,length($center)-2,2)); my $center_pre = trim(substr($center,0,index($center," "))); my $center_val = squash(trim(substr( $center,length($center_pre), length($center)-length($center_pre)-length($center_suf)))); $span = trim($span); my $span_suf = trim(substr($span,length($span)-2,2)); my $span_pre = trim(substr($span,0,index($span," "))); my $span_val = squash(trim(substr( $span,length($span_pre), length($span)-length($span_pre)-length($span_suf)))); $rbw = trim($rbw); my ($rbw_pre,$rbw_val,$rbw_suf) = split(/\s/,$rbw); $rbw_pre = trim($rbw_pre); $rbw_val = trim($rbw_val); $rbw_suf = "Hz"; $vbw = trim($vbw); my ($vbw_pre,$vbw_val,$vbw_suf) = split(/\s/,$vbw); $vbw_pre = trim($vbw_pre); $vbw_val = trim($vbw_val); $vbw_suf = "Hz"; $sweep = trim($sweep); my ($sweep_pre,$sweep_val,$sweep_suf) = split(/\s/,$sweep); $sweep_pre = trim($sweep_pre); $sweep_val = trim($sweep_val); if (trim($sweep_suf) eq "SEC") {$sweep_suf = "Sec."}; if (trim($sweep_suf) eq "MIN") {$sweep_suf = "Min."}; if (trim($sweep_suf) eq "HR") {$sweep_suf = "Hr."}; # get bottom of scale my $ref_bottom = $ref_val-($db_div_val*10); # figure out start, center, stop, and Hz/bin my $start_freq; my $center_freq; my $stop_freq; my $span_freq; my $bin_freq; if (($center_pre eq "CENTER") && ($span_pre eq "SPAN")) { $center_freq = $center_val; $span_freq = $span_val; $start_freq = $center_freq - ($span_freq/2); $stop_freq = $center_freq + ($span_freq/2); $bin_freq = $span_freq/1000; } if (($center_pre eq "START") && ($span_pre eq "STOP")) { $span_freq = $span_val - $center_val; $start_freq = $center_freq; $stop_freq = $span_freq; $center_freq = $start_freq + ($span/2); $bin_freq = $span_freq/1000; } return $start_freq,$center_freq,$stop_freq,$bin_freq,$top_right_pre, $top_right_val,$top_right_suf,$marker_freq,$marker_val,$rbw_val, $vbw_val,$db_div_val,$sweep_val,$sweep_suf,$range_val,$range_suf, $ref_val,$ref_suf,$ref_bottom,$span_val; } sub fix_freq { # input is a string with embedded frequency and suffix # strips commas and spaces (but not periods) from frequency # returns frequency . suffix in 3585B-compatible format my $tmp_val = ""; my $tmp_suffix = ""; (undef,$tmp_val,$tmp_suffix) = parse_value(shift); $tmp_suffix = lower_case($tmp_suffix); if ( ($tmp_suffix ne "hz") && ($tmp_suffix ne "khz") && ($tmp_suffix ne "kz") && ($tmp_suffix ne "mhz") && ($tmp_suffix ne "mz" ) ) { return ""; } $tmp_val = squash($tmp_val); local $_ = $tmp_val; /s/,//gs; $tmp_val = $_; if ($tmp_suffix eq "hz") { $tmp_suffix = "HZ"}; if ($tmp_suffix eq "khz") { $tmp_suffix = "KZ"}; if ($tmp_suffix eq "kz") { $tmp_suffix = "KZ"}; if ($tmp_suffix eq "mhz") { $tmp_suffix = "MZ"}; if ($tmp_suffix eq "mz") { $tmp_suffix = "MZ"}; return $tmp_val . $tmp_suffix; } sub fix_db { # input is a string with embedded value and suffix # strips commas and spaces (but not periods) from value # returns db value . suffix in 3585B-compatible format my $tmp_val = ""; my $tmp_suffix = ""; (undef,$tmp_val,$tmp_suffix) = parse_value(shift); $tmp_suffix = lower_case($tmp_suffix); if ( ($tmp_suffix ne "db") && ($tmp_suffix ne "dbm") && ($tmp_suffix ne "dbv" ) ) { return ""; } $tmp_val = squash($tmp_val); local $_ = $tmp_val; /s/,//gs; $tmp_val = $_; if ($tmp_suffix eq "db") { $tmp_suffix = "DB"}; if ($tmp_suffix eq "dbm") { $tmp_suffix = "DM"}; if ($tmp_suffix eq "dbv") { $tmp_suffix = "DV"}; return $tmp_val . $tmp_suffix; } sub fix_sweep { # input is a string with embedded value and suffix # strips commas and spaces (but not periods) from value # returns seconds . suffix in 3585B-compatible format my $tmp_val = ""; my $tmp_suffix = ""; (undef,$tmp_val,$tmp_suffix) = parse_value(shift); $tmp_val = squash($tmp_val); local $_ = $tmp_val; /s/,//gs; $tmp_val = $_; return $tmp_val . "SC"; } 1; =pod =head1 NAME hp3585b - Functions for HP 3585B Spectrum Analyzer =head1 SYNOPSIS use hp3585b; @array = get_settings(@bin_dump) ($start_freq,$center_freq,$stop_freq,$bin_freq,$top_right_pre, $top_right_val,$top_right_suf,$marker_freq,$marker_val,$rbw_val, $vbw_val,$db_div_val,$sweep_val,$sweep_suf,$range_val,$range_suf, $ref_val,$ref_suf,$ref_bottom,$span_val) = get_settings(device) $freq = fix_freq($raw_freq) $db = fix_freq($raw_db) $sweep_time = fix_sweep($raw_sweep) =head1 ABSTRACT =head1 DESCRIPTION =head1 FUNCTIONS =head2 C =over 4 =item Arg Argument =back =cut =head1 SEE ALSO L, L, L =head1 LICENSE This software is released under the same terms as perl itself. If you don't know what that means visit http://perl.com/ =head1 AUTHOR Copyright (C) root 2003 All rights Reserved =cut language/perl/examples/n8ur/hp8569b.pl000066400000000000000000000206721507046215500177730ustar00rootroot00000000000000#!/usr/bin/perl # # 8569b.pl # version 0.7 -- 23 June 2003 # # Plot display of HP 8569B Spectrum Analyzer # # Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) # Licensed under the GPL version 2 or later; see the file COPYING # included with this distribution. I request, but do not require, that # any modifications that correct bugs or errors, or increase the program's # functionality, be sent via email to the author at the address above. # # Current status: # Version 0.7 -- no code changes, but licensed under the GPL now. # # Version 0.6 -- this is a stable, working version that I'm going to gut # pretty soon; I want to rewrite it to match some of the features of the # hp3585b.pl program. I also want to add the ability to display not only # the peak signal, but also the minimum signal and the delta between them. # # If you use the -x,-x params to change the image size, the text probably # won't line up correctly. Use these at your own risk. use strict; use POSIX qw(setsid); use Getopt::Std; use Time::HiRes qw(usleep); use LinuxGpib; use GD; use GD::Text; use GD::Graph::lines; #---------- # subroutines sub trim { local $_ = shift; s/\n/ /sg; # convert newlines to spaces s/\r/ /sg; # convert carriage returns to spaces s/\000/ /sg; # convert nulls to spaces s/^\s+//sg; # trim leading spaces s/\s+$//sg; # trim trailing spaces return $_; } sub collapse { local $_ = shift; s/\s+/ /sg; # collapse multiple spaces to just one return $_; } sub round { my($number) = shift; return int($number +.5 * ($number <=> 0) ); }; #---------- # usage and option initialization my $opt_string = 'bdhmr:c:f:t:x:y:'; sub usage() { print STDERR << "EOF"; usage: $0 [-h] [-b] [-d ] [-c 1..4] [-m] [-r] [-t title] -f filename This program collects data from an HP 8569B spectrum analyzer and generates a PNG format graphic mimicking the the instrument's display. Most of the options affect the output format. By using the -c and -r options, multiple charts can be created that will overlay nicely on one another. The -r option not only makes the image background transparent, it suppresses the timestamp, so the timestamp of the underlying non-transparent image will not be blurred. -h : this (help) message -b : display both traces; default is trace A only -c : use alternate 1 through 4 for trace colors; default is 1 (red,blue) -d : device name (from /etc/gpib.conf); default is "hp8569b" -m : mark and display values of peak signal -r : make output file tRansparent and suppress timestamp; default is no -t : optional title (1 line max) -x,-y : output dimension in pixels; default 550x440 -f : filename for output PNG EOF } #---------------------- getopts( "$opt_string", \my %opt ) or usage() and exit; usage() and exit if $opt{h}; usage() and exit if !$opt{f}; # set variables to command line params my $picfile = $opt{f}; my $both = 0; if ($opt{b}) { $both = 1; } my $colorset = 1; if ($opt{c}) { $colorset = $opt{c}; } my $device = "hp8569b"; if ($opt{d}) { $device = $opt{d}; } my $show_marker = 0; if ($opt{m}) { $show_marker = 1; } my $transparent = 0; if ($opt{r}) { $transparent = 1; } # title my $title = ""; if ($opt{t}) { $title = $opt{t}; } # x size my $x = 550; if ($opt{x}) { $x = $opt{x}; } # y size my $y = 440; if ($opt{y}) { $y = $opt{y}; } # set up picfile open (PIC, ">$picfile") || die "Can't open image file $picfile!\n"; #---------- # initialize instrument my $dev = LinuxGpib::ibfind($device) || die "Can't open device $device!\n"; # clear instrument LinuxGpib::ibclr($dev); sleep 1; #---------- # get data # first, get screen annotation my $command = "CS"; my $reading; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,127); my (undef,undef,$c_freq,$c_freq_unit,undef,$span,$span_unit,undef,undef, $rbw,$rbw_unit,undef,$vf,$ref_point,$ref,$ref_value,$db_div,undef, undef,$atten,undef,undef,$sweep) = split(/\s/,collapse($reading)); my $annotation1 = "CTR " . trim($c_freq) . " " . trim($c_freq_unit) . " | SPAN ". trim($span) . " ". trim($span_unit) . " | RBW " . trim($rbw) . " " . trim($rbw_unit) . " | VF " . trim($vf); my $annotation2 = trim($ref_point) . " " . trim($ref) . " " . trim($ref_value) . " | " . trim($db_div) . " dB/ | ATTEN " . trim($atten) . " dB | SWP " . trim($sweep); #------------- # get trace data $command = "TA"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,1924); my @traceA = split(/,/, trim($reading)); my @traceB; if ($both) { $command = "TB"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,1924); @traceB = split(/,/, trim($reading)); } my ($peaka_x, $peaka_y, $peakb_x, $peakb_y); if ($show_marker) { $command = "AP"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,7); ($peaka_x,$peaka_y) = split(/,/,trim($reading)); if ($both) { $command = "BP"; LinuxGpib::ibwrt($dev,$command,length($command)); LinuxGpib::ibrd($dev,$reading,7); ($peakb_x,$peakb_y) = split(/,/,trim($reading)); } } #--------------- # plotting routines # this is just so GD::Graph has x axis labels for us to ignore my @x_array; my $i; for ($i = 0; $i <= 480; $i++) { $x_array[$i] = $i; } # these format the axis labels sub y_format { my $value = shift; my $ret; if ($ref_point eq "MID") { $ret = ($value/10) - 40; } else { $ret = ($value/10) - 80; } $ret = $ret/(10/trim($db_div)); } sub x_format { my $value = shift; my $ret = (($value/48)-5)*trim($span); } # set the trace colors; four sets to choose from my @cset = [qw(lred lblue)]; if ($colorset == 2) { @cset = [qw(lblue lred)]; } if ($colorset == 3) { @cset = [qw(green purple)]; } if ($colorset == 4) { @cset = [qw(purple green)]; } # set some dimensions my $l_margin = 15; my $r_margin = 15; my $t_margin = 50; my $b_margin = 15; my $spec_display = new GD::Graph::lines($x,$y); $spec_display->set_title_font(gdTinyFont); $spec_display->set ( dclrs => @cset, l_margin => $l_margin, r_margin => $r_margin, t_margin => $t_margin, b_margin => $b_margin, transparent => $transparent, y_max_value => 800, y_tick_number => 8, y_long_ticks => 1, y_number_format => \&y_format, x_number_format => \&x_format, x_max_value => 480, x_tick_number => 10, x_long_ticks => 1 ); my $foo; if ($both) { $foo = $spec_display->plot([\@x_array,\@traceA,\@traceB]); } else { $foo = $spec_display->plot([\@x_array,\@traceA]); } my $black = $foo->colorAllocate(0,0,0); my $red = $foo->colorAllocate(255,0,0); # plot the marker if ($show_marker) { $foo->char(gdSmallFont, (($peaka_x/480)*($x-$l_margin-$r_margin))+($l_margin*2)-2, $y-(($peaka_y/800)*($y-$t_margin-$b_margin))-($t_margin/2)-8, "o",$black); if ($both) { $foo->char(gdSmallFont, (($peakb_x/480)*($x-$l_margin))+$l_margin-1, $y-(($peakb_y/800)*($y-$t_margin-$b_margin))- ($t_margin/2)-8, "o",$black); } } #----------- # add text features my $gd_text = GD::Text->new() or die GD::Text::error(); $gd_text->set_font(gdLargeFont); $gd_text->set_text($title); my ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdLargeFont,275-($w/2),10,$title,$black); $gd_text->set_font(gdTinyFont); $gd_text->set_text($annotation1." | ".$annotation2); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,285-($w/2),35,$annotation1." | ".$annotation2,$black); # display marker values my $marker_x_offset; my $marker_y_offset; if ($show_marker) { $marker_x_offset = round((($peaka_x-240)/48)*$span); my $marker_x_text = "Marker: ". $marker_x_offset . " " . substr(trim($span_unit),0,3); $gd_text->set_font(gdSmallFont); $gd_text->set_text($marker_x_text); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,40,60,$marker_x_text,$red); $marker_y_offset = (($peaka_y - 800)/100)*$db_div; my $marker_y_text = " ". $marker_y_offset . " dB"; $gd_text->set_font(gdSmallFont); $gd_text->set_text($marker_y_text); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdSmallFont,40,75,$marker_y_text,$red); } my $id = "HP 8569B @ N8UR"; $gd_text->set_font(gdTinyFont); $gd_text->set_text($id); $foo->string(gdTinyFont,30,420,$id,$black); my $timestamp; if (!$transparent) { $timestamp = gmtime() . " (UTC)"; $gd_text->set_font(gdTinyFont); $gd_text->set_text($timestamp); ($w, $h) = $gd_text->get('width', 'height'); $foo->string(gdTinyFont,540-$w,420,$timestamp,$black); } binmode PIC; print PIC $foo->png; close PIC; # clear LinuxGpib::ibclr($dev); exit 0; language/perl/examples/n8ur/n8ur.pm000066400000000000000000000070251507046215500175600ustar00rootroot00000000000000package n8ur; # John R. Ackermann N8UR (jra@febo.com) # Mon Jun 9 09:19:03 2003 # # n8ur - my useful functions # # Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) # Licensed under the GPL version 2 or later; see the file COPYING # included with this distribution. I request, but do not require, that # any modifications that correct bugs or errors, or increase the program's # functionality, be sent via email to the author at the address above. use strict; use warnings; use diagnostics; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = '0.01'; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(trim collapse squash lower_case upper_case round parse_value is_number); sub trim { local $_ = shift; s/\n/ /sg; # convert newlines to spaces s/\r/ /sg; # convert carriage returns to spaces s/\000/ /sg; # convert nulls to spaces s/^\s+//sg; # trim leading spaces s/\s+$//sg; # trim trailing spaces return $_; } sub collapse { local $_ = shift; s/\s+/ /sg; # collapse multiple spaces to just one return $_; } sub squash { local $_ = shift; s/\s//sg; # remove all spaces return $_; } sub lower_case { local $_ = shift; $_ =~ tr [A-Z] [a-z]; return $_; } sub upper_case { local $_ = shift; $_ =~ tr [a-z] [A-Z]; return $_; } sub round { my($places) = shift; my($number) = shift; my($rounded); if ($number < 0) { $rounded = int(($number*10**$places) -.5 * ($number <=> 0) )/10**$places; } else { $rounded = int(($number*10**$places) +.5 * ($number <=> 0) )/10**$places; } return $rounded }; sub parse_value { # splits input into alpha prefix, numeric value, and alpha suffix # first split is when a digit, or "+", "-", or "." is encountered # second split is at first alpha after the number my($val) = shift; my $prefix = ""; my $value = ""; my $suffix = ""; my $j = 0; my $end = 0; # get rid of any embedded spaces $val = squash($val); until ( (substr($val,$j,1) =~ /[\d+-\.]/) || ($j == length($val)) ) { $prefix .= substr($val,$j,1); $j++; $end = $j; } if ($end > 1) { $val = substr($val,$end); } $j = 0; $end = 0; until ( (substr($val,$j,1) =~ /[a-z]/i) || ($j == length($val)) ) { $j++; $end = $j; } $value = substr($val,0,$end); $suffix = substr($val,$end); return $prefix,$value,$suffix; } sub is_number { # returns true if input is a decimal number local $_ = shift; if ( /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/ ) { return 1; } else { return 0; } } 1; =pod =head1 NAME hp3585b - Functions for HP 3585B Spectrum Analyzer =head1 SYNOPSIS $string = trim($input) $string = collapse($input) $string = squash($input) $string = lower_case($input) $string = upper_case($input) $num = round($num_places,$input) ($prefix,$value,$suffix) = parse_value($string) $boolean = is_number($input) =head1 ABSTRACT =head1 DESCRIPTION =head1 FUNCTIONS =back =cut =head1 SEE ALSO =head1 LICENSE Copyright 2003 by John R. Ackermann N8UR (jra@febo.com) This program may be copied, modified, distributed and used for any legal purpose provided that (a) the copyright notice above as well as these terms are retained on all copies; (b) any modifications that correct bugs or errors, or increase the program's functionality, are sent via email to the author at the address above; and (c) such modifications are made subject to these license terms. =head1 AUTHOR John Ackermann N8UR (jra@febo.com Copyright (C) 2003 All rights Reserved =cut language/perl/test.pl000066400000000000000000000007511507046215500151270ustar00rootroot00000000000000# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test; BEGIN { plan tests => 1 }; use LinuxGpib; ok(1); # If we made it this far, we're ok. ######################### # Insert your test code below, the Test module is use()ed here so read # its man page ( perldoc Test ) for help writing this test script. language/perl/typemap000066400000000000000000000000631507046215500152110ustar00rootroot00000000000000short * T_PTROBJ unsigned short * T_PTROBJ language/php/000077500000000000000000000000001507046215500134355ustar00rootroot00000000000000language/php/Makefile.am000066400000000000000000000014211507046215500154670ustar00rootroot00000000000000# language/php/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = TESTS EXTRA_DIST = sample-php.ini run lib_LTLIBRARIES = gpib_php.la gpib_php_la_SOURCES = gpib.c EXTENSIONDIR = `$(PHP_CONFIG) --extension-dir` PHP_INCLUDES = `$(PHP_CONFIG) --includes` gpib_php_la_CPPFLAGS = $(PHP_INCLUDES) -DUSE_LINUX_GPIB -DCOMPILE_DL=1 gpib_php_la_CFLAGS = $(LIBGPIB_CFLAGS) gpib_php_la_LDFLAGS = -release $(VERSION) $(LIBGPIB_LDFLAGS) -module -rdynamic libdir = $(EXTENSIONDIR) language/php/TESTS/000077500000000000000000000000001507046215500143375ustar00rootroot00000000000000language/php/TESTS/Makefile.am000066400000000000000000000007411507046215500163750ustar00rootroot00000000000000# language/php/TEST/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = alim1.php hp4194.php hp4194a.php vers.php tek11402a.php tek11402b.php infile1.txt infile2.txt language/php/TESTS/alim1.php000077500000000000000000000002041507046215500160520ustar00rootroot00000000000000#!/usr/bin/php -q language/php/TESTS/hp4194.php000077500000000000000000000016211507046215500160040ustar00rootroot00000000000000#!/usr/bin/php -q language/php/TESTS/hp4194a.php000077500000000000000000000013631507046215500161500ustar00rootroot00000000000000#!/usr/bin/php -q language/php/TESTS/infile1.txt000066400000000000000000000000041507046215500164210ustar00rootroot00000000000000ID? language/php/TESTS/infile2.txt000066400000000000000000000000231507046215500164230ustar00rootroot00000000000000OUT TRA1;WFM?;WAV? language/php/TESTS/tek11402a.php000066400000000000000000000011011507046215500163550ustar00rootroot00000000000000#!/usr/local/bin/php 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $ii = ibrd($dev,$xx,1000); $zz = ibcnt(); echo("ibrd returns: $ii $zz\n"); echo("($xx)\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } echo("done.\n"); } ?> language/php/TESTS/tek11402b.php000066400000000000000000000026511507046215500163710ustar00rootroot00000000000000#!/usr/local/bin/php 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $ii = ibrd($dev,$xx,1000); $zz = ibcnt(); echo("ibrd returns: $ii $zz\n"); echo("($xx)\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $xx = "infile1.txt"; $ii = ibwrtf($dev,$xx); $zz = ibcnt(); echo("ibwrt returns: $ii $zz\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $ii = ibrdf($dev,"outfile1.txt"); $zz = ibcnt(); echo("ibrd returns: $ii $zz\n"); echo("($xx)\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $xx = "infile2.txt"; $ii = ibwrtf($dev,$xx); $zz = ibcnt(); echo("ibwrt returns: $ii $zz\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } $ii = ibrdf($dev,"outfile2.txt"); $zz = ibcnt(); echo("ibrd returns: $ii $zz\n"); echo("($xx)\n"); $err = iberr(); if($err > 0) { echo("iberr: $err\n"); echo(gpib_error_string($err)); echo("\n"); } echo("done.\n"); } ?> language/php/TESTS/vers.php000077500000000000000000000001171507046215500160310ustar00rootroot00000000000000#!/usr/bin/php language/php/gpib.c000066400000000000000000000334031507046215500145250ustar00rootroot00000000000000/* -*- linux-c -*- A PHP extension for GPIB commands written by Michel Billaud, billaud@labri.fr, Laboratoire Bordelais de Recherche en Informatique Université Bordeaux 1 - France billaud@labri.fr for the Minerva "Emerge" project, in February 2003 (C) Michel Billaud, 2003 php5 modifications suggested Richard Klingler, richard@klingler.net Updated for PHP 5.6 by Vince Vielhaber, vev@michvhf.com *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************** STATUS: alpha code LIMITS: Only ib* command are considered for the moment. CREDITS: The list of variable and function names was borrowed from the linux-gpib-3.1.92 files. http://linux-gpib.sourceforge.net MODIFICATIONS * 2017/08/18 : updated to current PHP library : added more error checking in ibrd * 2016/07/06 : removed checks for pass by ref for php5 removed support for old NI_GPIB library added ibvers * 2003/02/25 : in ibrd, string terminated after ibcnt chars * 2003/03/14 : more comments TODO: - support for $r = ibrd($ud, $buffer) - integrate more constants (for ibconf) NOTES : * Installation under Debian requires the php dev package. * For convenience, install the gpib.so where dynamic extensions live * and add the following line to your php.ini files: extension=gpib.so BIBLIOGRAPHY: [php4] PHP Developpement d'applications WEB, Tobias Ratschiller et Till Gerken, Campus Press, pp. 327-... file://localhost/opt/doc.php.nexen.html/zend.structure.exporting-functions.html */ #define _GNU_SOURCE #include "gpib/ib.h" #include "php.h" #include "ext/standard/info.h" /* ---- macros for declarations -------------------------- */ #if ( PHP_MAJOR_VERSION >= 8) #define TSRMLS_CC #endif #define FUN_ACCESSOR(functionName) \ ZEND_FUNCTION(functionName)\ { \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) \ { \ RETURN_NULL(); \ } \ RETURN_LONG(functionName); \ } #define FUN_STRING(functionName) \ ZEND_FUNCTION(functionName) \ { \ char *s; \ int s_len; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "s", &s , &s_len \ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(s); \ RETURN_LONG(r); \ } #define FUN_INT_STRING(functionName) \ ZEND_FUNCTION(functionName) \ { \ long n; \ char *s; \ int s_len; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "ls", &n , &s , &s_len \ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(n,s); \ RETURN_LONG(r); \ } #define FUN_INT_STRING_INT(functionName) \ ZEND_FUNCTION(functionName) \ { \ long n,nn; \ char *s; \ int s_len; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "lsl", &n , &s , &s_len ,&nn\ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(n,s,nn); \ RETURN_LONG(r); \ } #define FUN_INT(functionName) \ ZEND_FUNCTION(functionName) \ { \ long n; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "l", &n \ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(n); \ RETURN_LONG(r); \ } #define FUN_INT_INT(functionName) \ ZEND_FUNCTION(functionName) \ { \ long n,nn; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "ll", &n, &nn \ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(n,nn); \ RETURN_LONG(r); \ } #define FUN_6INT(functionName) \ ZEND_FUNCTION(functionName) \ { \ long n1,n2,n3,n4,n5,n6; \ int r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "llllll", &n1,&n2,&n3,&n4,&n5,&n6 \ ) == FAILURE) { \ RETURN_NULL(); \ } \ r = functionName(n1,n2,n3,n4,n5,n6); \ RETURN_LONG(r); \ } #define FUN_INT_PINT(functionName) \ ZEND_FUNCTION(functionName) { \ long n; \ zval *z; \ char result; \ long r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "lz", &n, &z) \ == FAILURE) { \ return; \ } \ r=functionName(n,&result); \ ZVAL_LONG(z,result); \ RETURN_LONG(r); \ } #define FUN_INT_PSHORT(functionName) \ ZEND_FUNCTION(functionName) { \ long n; \ zval *z; \ short result; \ long r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "lz", &n, &z) \ == FAILURE) { \ return; \ } \ r=functionName(n,&result); \ ZVAL_LONG(z,result); \ RETURN_LONG(r); \ } #define FUN_INT_INT_PINT(functionName) \ ZEND_FUNCTION(functionName) { \ long n,nn; \ zval *z; \ int result; \ long r; \ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \ "llz", &n, &nn, &z) \ == FAILURE) { \ return; \ } \ r=functionName(n,nn,&result); \ ZVAL_LONG(z,result); \ RETURN_LONG(r); \ } #define NOT_IMPLEMENTED_YET(functionName) \ ZEND_FUNCTION(functionName) \ { \ zend_error(E_WARNING, \ "GPIB-PHP: Function not implemented yet"); \ } /* * predefinition of all functions */ ZEND_FUNCTION(ibfind); ZEND_FUNCTION(ibbna); ZEND_FUNCTION(ibclr); ZEND_FUNCTION(ibcac); ZEND_FUNCTION(ibloc); ZEND_FUNCTION(ibonl); ZEND_FUNCTION(ibpad); ZEND_FUNCTION(ibpct); ZEND_FUNCTION(ibppc); ZEND_FUNCTION(ibrdf); ZEND_FUNCTION(ibrsc); ZEND_FUNCTION(ibrsv); ZEND_FUNCTION(ibsad); ZEND_FUNCTION(ibsic); ZEND_FUNCTION(ibsre); ZEND_FUNCTION(ibtmo); ZEND_FUNCTION(ibtrg); ZEND_FUNCTION(ibvers); ZEND_FUNCTION(ibwait); ZEND_FUNCTION(ibwrtf); ZEND_FUNCTION(gpib_error_string); ZEND_FUNCTION(ibsta); ZEND_FUNCTION(ibcnt); ZEND_FUNCTION(iberr); ZEND_FUNCTION(ibwrt); ZEND_FUNCTION(ibrd); ZEND_FUNCTION (ibask); ZEND_FUNCTION (ibcmd); ZEND_FUNCTION (ibcmda); ZEND_FUNCTION (ibdev); ZEND_FUNCTION (ibevent); ZEND_FUNCTION (iblines); ZEND_FUNCTION (ibrpp); ZEND_FUNCTION (ibrsp); ZEND_MINIT_FUNCTION(start_module); PHP_MINFO_FUNCTION(gpib); /* * table of all PHP GPIB functions */ zend_function_entry php_gpib_functions[] = { ZEND_FE(ibfind, NULL) ZEND_FE(ibbna, NULL) ZEND_FE(ibclr, NULL) ZEND_FE(ibcac, NULL) ZEND_FE(ibloc, NULL) ZEND_FE(ibonl, NULL) ZEND_FE(ibpad, NULL) ZEND_FE(ibpct, NULL) ZEND_FE(ibppc, NULL) ZEND_FE(ibrdf, NULL) ZEND_FE(ibrsc, NULL) ZEND_FE(ibrsv, NULL) ZEND_FE(ibsad, NULL) ZEND_FE(ibsic, NULL) ZEND_FE(ibsre, NULL) ZEND_FE(ibtmo, NULL) ZEND_FE(ibtrg, NULL) ZEND_FE(ibvers, NULL) ZEND_FE(ibwait, NULL) ZEND_FE(ibwrtf, NULL) ZEND_FE(gpib_error_string, NULL) ZEND_FE(ibsta, NULL) ZEND_FE(ibcnt, NULL) ZEND_FE(iberr, NULL) ZEND_FE(ibwrt, NULL) ZEND_FE(ibrd, NULL) ZEND_FE (ibask, NULL) ZEND_FE (ibcmd, NULL) ZEND_FE (ibcmda, NULL) ZEND_FE (ibdev, NULL) ZEND_FE (ibevent, NULL) ZEND_FE (iblines, NULL) ZEND_FE (ibrpp, NULL) ZEND_FE (ibrsp, NULL) { NULL, NULL, NULL} }; zend_module_entry php_gpib_module_entry = { STANDARD_MODULE_HEADER, "gpib", php_gpib_functions, ZEND_MINIT(start_module), /* module startup */ NULL, /* module shutdown */ NULL, /* request startup */ NULL, /* request shutdown */ PHP_MINFO(gpib), /* info function */ NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; PHP_MINFO_FUNCTION(gpib) { php_info_print_table_start(); php_info_print_table_row(2,"GPIB Support","Enabled"); php_info_print_table_row(2,"Supported library", "Linux GPIB " "(http://linux-gpib/sourceforge.net)"); php_info_print_table_end(); } /* * Definition of PHP constants */ ZEND_MINIT_FUNCTION(start_module) { REGISTER_LONG_CONSTANT("DCAS", DCAS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DTAS", DTAS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LACS", LACS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("TACS", TACS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ATN", ATN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CIC", CIC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REM", REM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LOK", LOK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CMPL", CMPL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EVENT", EVENT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SPOLL", SPOLL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("RQS", RQS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SRQI", SRQI, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("END", END, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("TIMO", TIMO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ERR", ERR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EDVR", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ECIC", 1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ENOL", 2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EADR", 3, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EARG", 4, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ESAC", 5, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EABO", 6, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ENEB", 7, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EDMA", 8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EOIP", 10, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ECAP", 11, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EFSO", 12, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EBUS", 14, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ESTB", 15, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ESRQ", 16, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ETAB", 20, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("TNONE", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T10us", 1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T30us", 2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T100us", 3, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T300us", 4, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T1ms", 5, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T3ms", 6, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T10ms", 7, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T30ms", 8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T100ms", 9, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T300ms", 10, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T1s", 11, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T3s", 12, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T10s", 13, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T30s", 14, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T100s", 15, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T300s", 16, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T1000s", 17, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EOS_ASK",0x1c00, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REOS", 0x0400, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XEOS", 0x800, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("BIN", 0x1000, CONST_CS | CONST_PERSISTENT); return(SUCCESS); } #if COMPILE_DL DLEXPORT zend_module_entry *get_module(void) { return &php_gpib_module_entry; } #endif /* * the accessors for the status variables and * most functions are defined by macros */ FUN_ACCESSOR(iberr) FUN_ACCESSOR(ibcnt) FUN_ACCESSOR(ibsta) FUN_STRING(ibfind) FUN_INT_STRING(ibbna) FUN_INT(ibclr) FUN_INT_INT(ibcac) FUN_INT(ibloc) FUN_INT_INT(ibonl) FUN_INT_INT(ibpad) FUN_INT(ibpct) FUN_INT_INT(ibppc) FUN_INT_STRING(ibrdf) FUN_INT_INT(ibrsc) FUN_INT_INT(ibrsv) FUN_INT_INT(ibsad) FUN_INT(ibsic) FUN_INT_INT(ibsre) FUN_INT_INT(ibtmo) FUN_INT(ibtrg) FUN_INT_INT(ibwait) FUN_INT_STRING(ibwrtf) FUN_INT_PINT(ibrpp) FUN_INT_PINT(ibrsp) FUN_INT_PSHORT(ibevent) FUN_INT_PSHORT(iblines) FUN_INT_INT_PINT(ibask) FUN_INT_STRING_INT(ibcmd) FUN_INT_STRING_INT(ibcmda) FUN_6INT(ibdev) /* * a few functions need a special treatment */ ZEND_FUNCTION(gpib_error_string) { long n; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &n ) == FAILURE) { return; } RETURN_STRING((char*)gpib_error_string(n)); } ZEND_FUNCTION(ibwrt) { long n,llen; char *s; int s_len; int len; if (ZEND_NUM_ARGS() == 2) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &n, &s, &s_len) == FAILURE) { return; } len = s_len; } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsl", &n, &s, &s_len, &llen) == FAILURE) { return; } len = (int)llen; } RETURN_LONG(ibwrt(n,s,len)); } ZEND_FUNCTION(ibvers) { zval *z; char *version; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z) == FAILURE) { return; } ibvers(&version); ZVAL_STRING(z,version); RETURN_STRING(version); } ZEND_FUNCTION(ibrd) { /* at the moment only the traditional form is supported $r = ibrd($ud,$string,$count) (read at most $count bytes into $string) but $r = ibrd($ud,$string) (read unlimited number of bytes) will be. Soon. Really. */ long n; zval *z; long len; char *p; long r; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzl", &n, &z, &len) == FAILURE) { return; } p = (char *) emalloc(len + 1); if(p == NULL) { ibsta |= ERR; iberr = EABO; // should be ENOMEM RETURN_LONG(ibsta); } memset(p,0,len+1); r=ibrd(n,p,len); p[ibcnt]='\0'; ZVAL_STRING(z,p); efree(p); RETURN_LONG(r); } language/php/run000077500000000000000000000000211507046215500141600ustar00rootroot00000000000000/usr/bin/php -qa language/php/sample-php.ini000066400000000000000000000560201507046215500162070ustar00rootroot00000000000000 [PHP] ;;;;;;;;;;;;;;;;;;; ; About this file ; ;;;;;;;;;;;;;;;;;;; ; This file controls many aspects of PHP's behavior. In order for PHP to ; read it, it must be named 'php.ini'. PHP looks for it in the current ; working directory, in the path designated by the environment variable ; PHPRC, and in the path that was defined in compile time (in that order). ; Under Windows, the compile-time path is the Windows directory. The ; path in which the php.ini file is looked for can be overriden using ; the -c argument in command line mode. ; ; The syntax of the file is extremely simple. Whitespace and Lines ; beginning with a semicolon are silently ignored (as you probably guessed). ; Section headers (e.g. [Foo]) are also silently ignored, even though ; they might mean something in the future. ; ; Directives are specified using the following syntax: ; directive = value ; Directive names are *case sensitive* - foo=bar is different from FOO=bar. ; ; The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one ; of the INI constants (On, Off, True, False, Yes, No and None) or an expression ; (e.g. E_ALL & ~E_NOTICE), or a quoted string ("foo"). ; ; Expressions in the INI file are limited to bitwise operators and parentheses: ; | bitwise OR ; & bitwise AND ; ~ bitwise NOT ; ! boolean NOT ; ; Boolean flags can be turned on using the values 1, On, True or Yes. ; They can be turned off using the values 0, Off, False or No. ; ; An empty string can be denoted by simply not writing anything after the equal ; sign, or by using the None keyword: ; ; foo = ; sets foo to an empty string ; foo = none ; sets foo to an empty string ; foo = "none" ; sets foo to the string 'none' ; ; If you use constants in your value, and these constants belong to a dynamically ; loaded extension (either a PHP extension or a Zend extension), you may only ; use these constants *after* the line that loads the extension. ; ; All the values in the php.ini-dist file correspond to the builtin ; defaults (that is, if no php.ini is used, or if you delete these lines, ; the builtin defaults will be identical). ;;;;;;;;;;;;;;;;;;;; ; Language Options ; ;;;;;;;;;;;;;;;;;;;; engine = On ; Enable the PHP scripting language engine under Apache short_open_tag = On ; allow the tags are recognized. asp_tags = Off ; allow ASP-style <% %> tags precision = 14 ; number of significant digits displayed in floating point numbers y2k_compliance = Off ; whether to be year 2000 compliant (will cause problems with non y2k compliant browsers) output_buffering = Off ; Output buffering allows you to send header lines (including cookies) ; even after you send body content, in the price of slowing PHP's ; output layer a bit. ; You can enable output buffering by in runtime by calling the output ; buffering functions, or enable output buffering for all files ; by setting this directive to On. implicit_flush = Off ; Implicit flush tells PHP to tell the output layer to flush itself ; automatically after every output block. This is equivalent to ; calling the PHP function flush() after each and every call to print() ; or echo() and each and every HTML block. ; Turning this option on has serious performance implications, and ; is generally recommended for debugging purposes only. allow_call_time_pass_reference = On ; whether to enable the ability to force arguments to be ; passed by reference at function-call time. This method ; is deprecated, and is likely to be unsupported in future ; versions of PHP/Zend. The encouraged method of specifying ; which arguments should be passed by reference is in the ; function declaration. You're encouraged to try and ; turn this option Off, and make sure your scripts work ; properly with it, to ensure they will work with future ; versions of the language (you will receive a warning ; each time you use this feature, and the argument will ; be passed by value instead of by reference). ; Safe Mode safe_mode = Off safe_mode_exec_dir = safe_mode_allowed_env_vars = PHP_ ; Setting certain environment variables ; may be a potential security breach. ; This directive contains a comma-delimited ; list of prefixes. In Safe Mode, the ; user may only alter environment ; variables whose names begin with the ; prefixes supplied here. ; By default, users will only be able ; to set environment variables that begin ; with PHP_ (e.g. PHP_FOO=BAR). ; Note: If this directive is empty, PHP ; will let the user modify ANY environment ; variable! safe_mode_protected_env_vars = LD_LIBRARY_PATH ; This directive contains a comma- ; delimited list of environment variables, ; that the end user won't be able to ; change using putenv(). ; These variables will be protected ; even if safe_mode_allowed_env_vars is ; set to allow to change them. disable_functions = ; This directive allows you to disable certain ; functions for security reasons. It receives ; a comma separated list of function names. ; This directive is *NOT* affected by whether ; Safe Mode is turned on or off. ; Colors for Syntax Highlighting mode. Anything that's acceptable in would work. highlight.string = #DD0000 highlight.comment = #FF8000 highlight.keyword = #007700 highlight.bg = #FFFFFF highlight.default = #0000BB highlight.html = #000000 ; Misc expose_php = On ; Decides whether PHP may expose the fact that it is installed on the ; server (e.g., by adding its signature to the Web server header). ; It is no security threat in any way, but it makes it possible ; to determine whether you use PHP on your server or not. ;;;;;;;;;;;;;;;;;;; ; Resource Limits ; ;;;;;;;;;;;;;;;;;;; max_execution_time = 30 ; Maximum execution time of each script, in seconds memory_limit = 8M ; Maximum amount of memory a script may consume (8MB) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; error_reporting is a bit-field. Or each number up to get desired error reporting level ; E_ALL - All errors and warnings ; E_ERROR - fatal run-time errors ; E_WARNING - run-time warnings (non fatal errors) ; E_PARSE - compile-time parse errors ; E_NOTICE - run-time notices (these are warnings which often result from a bug in ; your code, but it's possible that it was intentional (e.g., using an ; uninitialized variable and relying on the fact it's automatically ; initialized to an empty string) ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup ; E_CORE_WARNING - warnings (non fatal errors) that occur during PHP's initial startup ; E_COMPILE_ERROR - fatal compile-time errors ; E_COMPILE_WARNING - compile-time warnings (non fatal errors) ; E_USER_ERROR - user-generated error message ; E_USER_WARNING - user-generated warning message ; E_USER_NOTICE - user-generated notice message ; Examples: ; error_reporting = E_ALL & ~E_NOTICE ; show all errors, except for notices ; error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; show only errors error_reporting = E_ALL & ~E_NOTICE ; Show all errors except for notices display_errors = On ; Print out errors (as a part of the output) ; For production web sites, you're strongly encouraged ; to turn this feature off, and use error logging instead (see below). ; Keeping display_errors enabled on a production web site may reveal ; security information to end users, such as file paths on your Web server, ; your database schema or other information. display_startup_errors = Off ; Even when display_errors is on, errors that occur during ; PHP's startup sequence are not displayed. It's strongly ; recommended to keep display_startup_errors off, except for ; when debugging. log_errors = Off ; Log errors into a log file (server-specific log, stderr, or error_log (below)) ; As stated above, you're strongly advised to use error logging in place of ; error displaying on production web sites. track_errors = Off ; Store the last error/warning message in $php_errormsg (boolean) ;error_prepend_string = "" ; string to output before an error message ;error_append_string = "" ; string to output after an error message ;error_log = filename ; log errors to specified file ;error_log = syslog ; log errors to syslog (Event Log on NT, not valid in Windows 95) warn_plus_overloading = Off ; warn if the + operator is used with strings ;;;;;;;;;;;;;;;;; ; Data Handling ; ;;;;;;;;;;;;;;;;; ; Note - track_vars is ALWAYS enabled as of PHP 4.0.3 variables_order = "EGPCS" ; This directive describes the order in which PHP registers ; GET, POST, Cookie, Environment and Built-in variables (G, P, ; C, E & S respectively, often referred to as EGPCS or GPC). ; Registration is done from left to right, newer values override ; older values. register_globals = On ; Whether or not to register the EGPCS variables as global ; variables. You may want to turn this off if you don't want ; to clutter your scripts' global scope with user data. This makes ; most sense when coupled with track_vars - in which case you can ; access all of the GPC variables through the $HTTP_*_VARS[], ; variables. ; You should do your best to write your scripts so that they do ; not require register_globals to be on; Using form variables ; as globals can easily lead to possible security problems, if ; the code is not very well thought of. register_argc_argv = On ; This directive tells PHP whether to declare the argv&argc ; variables (that would contain the GET information). If you ; don't use these variables, you should turn it off for ; increased performance post_max_size = 8M ; Maximum size of POST data that PHP will accept. gpc_order = "GPC" ; This directive is deprecated. Use variables_order instead. ; Magic quotes magic_quotes_gpc = On ; magic quotes for incoming GET/POST/Cookie data magic_quotes_runtime= Off ; magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. magic_quotes_sybase = Off ; Use Sybase-style magic quotes (escape ' with '' instead of \') ; automatically add files before or after any PHP document auto_prepend_file = auto_append_file = ; As of 4.0b4, PHP always outputs a character encoding by default in ; the Content-type: header. To disable sending of the charset, simply ; set it to be empty. ; PHP's built-in default is text/html default_mimetype = "text/html" ;default_charset = "iso-8859-1" ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; ;;;;;;;;;;;;;;;;;;;;;;;;; include_path = ; UNIX: "/path1:/path2" Windows: "\path1;\path2" doc_root = ; the root of the php pages, used only if nonempty user_dir = ; the directory under which php opens the script using /~username, used only if nonempty extension_dir = /usr/lib/php4/cgi ; directory in which the loadable extensions (modules) reside enable_dl = On ; Whether or not to enable the dl() function. ; The dl() function does NOT properly work in multithreaded ; servers, such as IIS or Zeus, and is automatically disabled ; on them. ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; file_uploads = On ; Whether to allow HTTP file uploads ;upload_tmp_dir = ; temporary directory for HTTP uploaded files (will use system default if not specified) upload_max_filesize = 2M ; Maximum allowed size for uploaded files ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; ; if you wish to have an extension loaded automaticly, use the ; following syntax: extension=modulename.extension ; for example, on windows, ; extension=msql.dll ; or under UNIX, ; extension=msql.so ; Note that it should be the name of the module only, no directory information ; needs to go here. Specify the location of the extension with the extension_dir directive above. ;Windows Extensions ;Note that MySQL and ODBC support is now built in, so no dll is needed for it. ; ;extension=php_cpdf.dll ;extension=php_cybercash.dll ;extension=php_db.dll ;extension=php_dbase.dll ;extension=php_domxml.dll ;extension=php_dotnet.dll ;extension=php_exif.dll ;extension=php_fdf.dll ;extension=php_gd.dll ;extension=php_gettext.dll ;extension=php_ifx.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_java.dll ;extension=php_ldap.dll ;extension=php_mhash.dll ;extension=php_mssql65.dll ;extension=php_mssql70.dll ;extension=php_oci8.dll ;extension=php_oracle.dll ;extension=php_pdf.dll ;extension=php_pgsql.dll ;extension=php_sablot.dll ;extension=php_swf.dll ;extension=php_sybase_ct.dll ;extension=php_zlib.dll ;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;; [Syslog] define_syslog_variables = Off ; Whether or not to define the various syslog variables, ; e.g. $LOG_PID, $LOG_CRON, etc. Turning it off is a ; good idea performance-wise. In runtime, you can define ; these variables by calling define_syslog_variables() [mail function] SMTP = localhost ;for win32 only sendmail_from = me@localhost.com ;for win32 only ;sendmail_path = ;for unix only, may supply arguments as well (default is 'sendmail -t -i') [Debugger] debugger.host = localhost debugger.port = 7869 debugger.enabled = False [Logging] ; These configuration directives are used by the example logging mechanism. ; See examples/README.logging for more explanation. ;logging.method = db ;logging.directory = /path/to/log/directory [Java] ;java.class.path = .\php_java.jar ;java.home = c:\jdk ;java.library = c:\jdk\jre\bin\hotspot\jvm.dll ;java.library.path = .\ [SQL] sql.safe_mode = Off [ODBC] ;uodbc.default_db = Not yet implemented ;uodbc.default_user = Not yet implemented ;uodbc.default_pw = Not yet implemented uodbc.allow_persistent = On ; allow or prevent persistent links uodbc.check_persistent = On ; check that a connection is still validbefore reuse uodbc.max_persistent = -1 ; maximum number of persistent links. -1 means no limit uodbc.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit uodbc.defaultlrl = 4096 ; Handling of LONG fields. Returns number of bytes to variables, 0 means passthru uodbc.defaultbinmode = 1 ; Handling of binary data. 0 means passthru, 1 return as is, 2 convert to char ; See the documentation on odbc_binmode and odbc_longreadlen for an explanation of uodbc.defaultlrl ; and uodbc.defaultbinmode [MySQL] mysql.allow_persistent = On ; allow or prevent persistent link mysql.max_persistent = -1 ; maximum number of persistent links. -1 means no limit mysql.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit mysql.default_port = ; default port number for mysql_connect(). If unset, ; mysql_connect() will use the $MYSQL_TCP_PORT, or the mysql-tcp ; entry in /etc/services, or the compile-time defined MYSQL_PORT ; (in that order). Win32 will only look at MYSQL_PORT. mysql.default_socket = ; default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults mysql.default_host = ; default host for mysql_connect() (doesn't apply in safe mode) mysql.default_user = ; default user for mysql_connect() (doesn't apply in safe mode) mysql.default_password = ; default password for mysql_connect() (doesn't apply in safe mode) ; Note that this is generally a *bad* idea to store passwords ; in this file. *Any* user with PHP access can run ; 'echo cfg_get_var("mysql.default_password")' and reveal that ; password! And of course, any users with read access to this ; file will be able to reveal the password as well. [mSQL] msql.allow_persistent = On ; allow or prevent persistent link msql.max_persistent = -1 ; maximum number of persistent links. -1 means no limit msql.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit [PostgresSQL] pgsql.allow_persistent = On ; allow or prevent persistent link pgsql.max_persistent = -1 ; maximum number of persistent links. -1 means no limit pgsql.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit [Sybase] sybase.allow_persistent = On ; allow or prevent persistent link sybase.max_persistent = -1 ; maximum number of persistent links. -1 means no limit sybase.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit ;sybase.interface_file = "/usr/sybase/interfaces" sybase.min_error_severity = 10 ; minimum error severity to display sybase.min_message_severity = 10 ; minimum message severity to display sybase.compatability_mode = Off ; compatability mode with old versions of PHP 3.0. ; If on, this will cause PHP to automatically assign types to results ; according to their Sybase type, instead of treating them all as ; strings. This compatability mode will probably not stay around ; forever, so try applying whatever necessary changes to your code, ; and turn it off. [Sybase-CT] sybct.allow_persistent = On ; allow or prevent persistent link sybct.max_persistent = -1 ; maximum number of persistent links. -1 means no limit sybct.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit sybct.min_server_severity = 10 ; minimum server message severity to display sybct.min_client_severity = 10 ; minimum client message severity to display [bcmath] bcmath.scale = 0 ; number of decimal digits for all bcmath functions [browscap] ;browscap = extra/browscap.ini [Informix] ifx.default_host = ; default host for ifx_connect() (doesn't apply in safe mode) ifx.default_user = ; default user for ifx_connect() (doesn't apply in safe mode) ifx.default_password = ; default password for ifx_connect() (doesn't apply in safe mode) ifx.allow_persistent = On ; allow or prevent persistent link ifx.max_persistent = -1 ; maximum number of persistent links. -1 means no limit ifx.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit ifx.textasvarchar = 0 ; if set on, select statements return the contents of a text blob instead of it's id ifx.byteasvarchar = 0 ; if set on, select statements return the contents of a byte blob instead of it's id ifx.charasvarchar = 0 ; trailing blanks are stripped from fixed-length char columns. May help the life ; of Informix SE users. ifx.blobinfile = 0 ; if set on, the contents of text&byte blobs are dumped to a file instead of ; keeping them in memory ifx.nullformat = 0 ; NULL's are returned as empty strings, unless this is set to 1. In that case, ; NULL's are returned as string 'NULL'. [Session] session.save_handler = files ; handler used to store/retrieve data session.save_path = /tmp ; argument passed to save_handler ; in the case of files, this is the ; path where data files are stored session.use_cookies = 1 ; whether to use cookies session.name = PHPSESSID ; name of the session ; is used as cookie name session.auto_start = 0 ; initialize session on request startup session.cookie_lifetime = 0 ; lifetime in seconds of cookie ; or if 0, until browser is restarted session.cookie_path = / ; the path the cookie is valid for session.cookie_domain = ; the domain the cookie is valid for session.serialize_handler = php ; handler used to serialize data ; php is the standard serializer of PHP session.gc_probability = 1 ; percentual probability that the ; 'garbage collection' process is started ; on every session initialization session.gc_maxlifetime = 1440 ; after this number of seconds, stored ; data will be seen as 'garbage' and ; cleaned up by the gc process session.referer_check = ; check HTTP Referer to invalidate ; externally stored URLs containing ids session.entropy_length = 0 ; how many bytes to read from the file session.entropy_file = ; specified here to create the session id ; session.entropy_length = 16 ; session.entropy_file = /dev/urandom session.cache_limiter = nocache ; set to {nocache,private,public} to ; determine HTTP caching aspects session.cache_expire = 180 ; document expires after n minutes session.use_trans_sid = 1 ; use transient sid support if enabled ; by compiling with --enable-trans-sid [MSSQL] ;extension=php_mssql.dll mssql.allow_persistent = On ; allow or prevent persistent link mssql.max_persistent = -1 ; maximum number of persistent links. -1 means no limit mssql.max_links = -1 ; maximum number of links (persistent+non persistent). -1 means no limit mssql.min_error_severity = 10 ; minimum error severity to display mssql.min_message_severity = 10 ; minimum message severity to display mssql.compatability_mode = Off ; compatability mode with old versions of PHP 3.0. [Assertion] ;assert.active = On ; assert(expr); active by default ;assert.warning = On ; issue a PHP warning for each failed assertion. ;assert.bail = Off ; don't bail out by default. ;assert.callback = 0 ; user-function to be called if an assertion fails. ;assert.quiet_eval = 0 ; eval the expression with current error_reporting(). set to true if you want error_reporting(0) around the eval(). [Ingres II] ingres.allow_persistent = On ; allow or prevent persistent link ingres.max_persistent = -1 ; maximum number of persistent links. (-1 means no limit) ingres.max_links = -1 ; maximum number of links, including persistents (-1 means no limit) ingres.default_database = ; default database (format : [node_id::]dbname[/srv_class] ingres.default_user = ; default user ingres.default_password = ; default password [Verisign Payflow Pro] pfpro.defaulthost = "test.signio.com" ; default Signio server pfpro.defaultport = 443 ; default port to connect to pfpro.defaulttimeout = 30 ; default timeout in seconds ; pfpro.proxyaddress = ; default proxy IP address (if required) ; pfpro.proxyport = ; default proxy port ; pfpro.proxylogon = ; default proxy logon ; pfpro.proxypassword = ; default proxy password ; Local Variables: ; tab-width: 4 ; End: ;extension=gd.so ;extension=imap.so ; extension=mhash.so ;extension=mysql.so ;extension=xml.so extension_dir = /home/billaud/Essais/PHP-GPIB extension=gpib_php.so language/python/000077500000000000000000000000001507046215500141675ustar00rootroot00000000000000language/python/Gpib.py000066400000000000000000000041541507046215500154260ustar00rootroot00000000000000 import gpib RQS = (1<<11) SRQ = (1<<12) TIMO = (1<<14) class Gpib(object): '''Three ways to create a Gpib object: Gpib("name") returns a board or device object, from a name in the config file Gpib(board_index) returns a board object, with the given board number Gpib(board_index, pad[, sad[, timeout[, send_eoi[, eos_mode]]]]) returns a device object, like ibdev()''' def __init__(self, name = 'gpib0', pad = None, sad = 0, timeout = 13, send_eoi = 1, eos_mode = 0): self._own = False if isinstance(name, str): self.id = gpib.find(name) self._own = True elif pad is None: self.id = name else: self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode) self._own = True # automatically close descriptor when instance is deleted def __del__(self): self.close() def __repr__(self): return "%s(%d)" % (self.__class__.__name__, self.id) def close(self): if self._own: gpib.close(self.id) self._own = False def command(self,str): gpib.command(self.id, str) def config(self,option,value): self.res = gpib.config(self.id,option,value) return self.res def interface_clear(self): gpib.interface_clear(self.id) def write(self,str): gpib.write(self.id, str) def write_async(self,str): gpib.write_async(self.id, str) def read(self,len=512): self.res = gpib.read(self.id,len) return self.res def listener(self,pad,sad=0): self.res = gpib.listener(self.id,pad,sad) return self.res def lines(self): self.res = gpib.lines(self.id) return self.res def ask(self,option): self.res = gpib.ask(self.id,option) return self.res def clear(self): gpib.clear(self.id) def wait(self,mask): gpib.wait(self.id,mask) def serial_poll(self): self.spb = gpib.serial_poll(self.id) return self.spb def trigger(self): gpib.trigger(self.id) def remote_enable(self,val): gpib.remote_enable(self.id,val) def ibloc(self): self.res = gpib.ibloc(self.id) return self.res def ibsta(self): self.res = gpib.ibsta() return self.res def ibcnt(self): self.res = gpib.ibcnt() return self.res def timeout(self,value): return gpib.timeout(self.id,value) language/python/Makefile.am000066400000000000000000000013231507046215500162220ustar00rootroot00000000000000# python/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = gpibtest.py setup.py Gpib.py gpibinter.c srq_board.py srq_device.py all-local: build build: gpibinter.c -{ $(PYTHON) setup.py build && touch build; } || { $(RM) -r build; exit 1; } install-data-local: -$(PYTHON) -m pip install . --prefix=$(DESTDIR)$(prefix) --root-user-action=ignore -$(RM) -r gpib.egg-info/ clean-local: -$(RM) -r build language/python/README000066400000000000000000000017151507046215500150530ustar00rootroot00000000000000 This is a python GPIB interface to use gpib library calls from python language. (Quick hacked) 27 January 2004 -- added functions gpib.readbin() and gpib.writebin(), as well as variables gpib.ibsta() and gpib.ibcnt(). -- John Ackermann Installation: 'make' then 'make install' To use the GPIB extension directly the call syntax is similar as in the C library: ## # Include the GPIB extension ## import gpib ## # find & initialize the device ## device = gpib.find("my_device") ## # write a string to the device ## gpib.write(device,"A Command_String") ## # write a binary string to the device ## gpib.writebin(device,"A Command_String",16) ## # read a 25 byte string ## result = gpib.read(device,25) print 'the result is: ' + result ## # read a binary string ## result = gpib.readbin(device,4096) #length of result equals ibcnt To use the Gpib Class module see gpibtest.py Have Fun! clausi language/python/gpibinter.c000066400000000000000000000535311507046215500163250ustar00rootroot00000000000000 /*********************************************************** * Python wrapper module for gpib library functions. ************************************************************/ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifdef USE_INES #include #else #include #endif #if PY_MAJOR_VERSION >= 3 #define IS_PY3K #define PyInt_FromLong PyLong_FromLong #define PyString_FromString PyBytes_FromString #define PyString_FromStringAndSize PyBytes_FromStringAndSize #define PyString_AS_STRING PyBytes_AS_STRING #define _PyString_Resize _PyBytes_Resize #endif #include #include #include #include static PyObject *GpibError; struct _iberr_string { int code; char *meaning; } _iberr_string; static struct _iberr_string GPIB_errors[] = { {EDVR, "A system call has failed. ibcnt/ibcntl will be set to the value of errno."}, {ECIC, "Your interface board needs to be controller-in-charge, but is not."}, {ENOL, "You have attempted to write data or command bytes, but there are no listeners currently addressed."}, {EADR, "The interface board has failed to address itself properly before starting an io operation."}, {EARG, "One or more arguments to the function call were invalid."}, {ESAC, "The interface board needs to be system controller, but is not."}, {EABO, "A read or write of data bytes has been aborted, possibly due to a timeout or reception of a device clear command."}, {ENEB, "The GPIB interface board does not exist, its driver is not loaded, or it is in use by another process."}, {EDMA, "Not used (DMA error), included for compatibility purposes."}, {EOIP, "Function call can not proceed due to an asynchronous IO operation (ibrda(), ibwrta(), or ibcmda()) in progress."}, {ECAP, "Incapable of executing function call, due the GPIB board lacking the capability, or the capability being disabled in software."}, {EFSO, "File system error. ibcnt/ibcntl will be set to the value of errno."}, {EBUS, "An attempt to write command bytes to the bus has timed out."}, {ESTB, "One or more serial poll status bytes have been lost. This can occur due to too many status bytes accumulating (through automatic serial polling) without being read."}, {ESRQ, "The serial poll request service line is stuck on."}, {ETAB, "This error can be returned by ibevent(), FindLstn(), or FindRQS(). See their descriptions for more information."}, {0, NULL}, }; void _SetGpibError(const char *funcname) { char *errstr; struct _iberr_string entry; int sverrno, code; code = ThreadIberr(); errstr = (char *) PyMem_Malloc(4096); if (code == EDVR || code == EFSO) { sverrno = ThreadIbcntl(); snprintf(errstr, 4096, "%s() error: %s (errno: %d)", funcname, strerror(sverrno), sverrno); } else { int i; for (i=0; entry=GPIB_errors[i], entry.meaning!=NULL; i++) { if (entry.code == code) break; } if (entry.meaning != NULL) snprintf(errstr, 4096, "%s() failed: %s", funcname, entry.meaning); else snprintf(errstr, 4096, "%s() failed: unknown reason (iberr: %d).", funcname, code); } PyErr_SetString(GpibError, errstr); PyMem_Free(errstr); } /* ----------------------------------------------------- */ static char gpib_find__doc__[] = "find -- get a device handle from configuration file\n" "find(name) -> handle"; static PyObject* gpib_find(PyObject *self, PyObject *args) { char *name; int ud; if (!PyArg_ParseTuple(args, "s:find", &name)) return NULL; Py_BEGIN_ALLOW_THREADS ud = ibfind(name); Py_END_ALLOW_THREADS if(ud < 0){ _SetGpibError("find"); return NULL; } return PyInt_FromLong(ud); } static char gpib_dev__doc__[] = "dev -- get a device handle\n" "dev(boardid, pad, [sad, timeout, eot, eos_mode]) -> handle"; static PyObject* gpib_dev(PyObject *self, PyObject *args) { int ud = -1; int board = 0; int pad = 0; int sad = NO_SAD; int tmo = T30s; int eot = 1; int eos_mode = 0; if (!PyArg_ParseTuple(args, "ii|iiii:dev", &board, &pad, &sad, &tmo, &eot, &eos_mode)) return NULL; Py_BEGIN_ALLOW_THREADS ud = ibdev(board, pad, sad, tmo, eot, eos_mode); Py_END_ALLOW_THREADS if (ud < 0) { _SetGpibError("dev"); return NULL; } return PyInt_FromLong(ud); } static char gpib_ask__doc__[] = "ask -- query configuration (board or device)\n" "ask(handle, option) -> result\n\n" "option should be one one of the symbolic constants gpib.IbaXXXX"; static PyObject* gpib_ask(PyObject *self, PyObject *args) { int device; int option; int result; if (!PyArg_ParseTuple(args, "ii:ask", &device, &option)) return NULL; if (ibask(device, option, &result) & ERR) { _SetGpibError("ask"); return NULL; } return PyInt_FromLong(result); } static char gpib_config__doc__[] = "config -- change configuration (board or device)\n" "config(handle, option, setting)\n\n" "option should be one one of the symbolic constants gpib.IbcXXXX"; static PyObject* gpib_config(PyObject *self, PyObject *args) { int device; int option; int setting; int sta; if (!PyArg_ParseTuple(args, "iii:config", &device, &option, &setting)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibconfig(device, option, setting); Py_END_ALLOW_THREADS if(sta & ERR) { _SetGpibError("config"); return NULL; } return PyInt_FromLong(sta); } static char gpib_listener__doc__[] = "listener -- check if listener is present (board or device)\n" "listener(handle, pad, [sad]) -> boolean"; static PyObject* gpib_listener(PyObject *self, PyObject *args) { int device; int pad; int sad = NO_SAD; short found_listener; if(!PyArg_ParseTuple(args, "ii|i:listener", &device, &pad, &sad)) return NULL; if(ibln(device, pad, sad, &found_listener) & ERR){ _SetGpibError("listener"); return NULL; } return PyBool_FromLong(found_listener); } static char gpib_lines__doc__[] = "lines -- get status of the control and handshaking bus lines (board)\n" "lines(handle) -> line_status_int"; static PyObject* gpib_lines(PyObject *self, PyObject *args) { int board; int sta; short line_status; if(!PyArg_ParseTuple(args, "i:lines", &board)) return NULL; Py_BEGIN_ALLOW_THREADS sta = iblines(board, &line_status); Py_END_ALLOW_THREADS if(sta & ERR){ _SetGpibError("lines"); return NULL; } return PyInt_FromLong(line_status); } static char gpib_read__doc__[] = "read -- read data bytes (board or device)\n" "read(handle, num_bytes) -> string"; static PyObject* gpib_read(PyObject *self, PyObject *args) { int device; int len; int sta; PyObject *retval; if (!PyArg_ParseTuple(args, "ii:read", &device,&len)) return NULL; /* Instead of using a C-buffer and then copying it into a Python-string, just build up an uninitialized Python-string. No copying needed, more efficient. (yes, this is legal, see http://www.python.org/doc/current/api/stringObjects.html) */ retval = PyString_FromStringAndSize(NULL, len); if(retval == NULL) { PyErr_SetString(GpibError, "Read Error: can't get Memory."); return NULL; } Py_BEGIN_ALLOW_THREADS sta = ibrd(device, PyString_AS_STRING(retval), len); Py_END_ALLOW_THREADS if( sta & ERR ) { _SetGpibError("read"); Py_DECREF(retval); return NULL; } _PyString_Resize(&retval, ThreadIbcntl()); return retval; } static char gpib_write__doc__[] = "write -- write data bytes (board or device)\n" "write(handle, data)"; static PyObject* gpib_write(PyObject *self, PyObject *args) { char *command; Py_ssize_t command_len; int device; int sta; if (!PyArg_ParseTuple(args, "is#:write",&device, &command, &command_len)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibwrt(device, command, command_len); Py_END_ALLOW_THREADS if( sta & ERR ){ _SetGpibError("write"); return NULL; } return PyInt_FromLong(sta); } static char gpib_write_async__doc__[] = "write_async -- write data bytes asynchronously (board or device)\n" "write_async(handle, data)"; static PyObject* gpib_write_async(PyObject *self, PyObject *args) { char *command; Py_ssize_t command_len; int device; int sta; if (!PyArg_ParseTuple(args, "is#:write_async", &device, &command, &command_len)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibwrta(device, command, command_len); Py_END_ALLOW_THREADS if( sta & ERR ){ _SetGpibError("write_async"); return NULL; } return PyInt_FromLong(sta); } static char gpib_command__doc__[] = "command -- write command bytes (board)\n" "command(handle, data)"; static PyObject* gpib_command(PyObject *self, PyObject *args) { char *command; Py_ssize_t command_len; int device; int sta; if (!PyArg_ParseTuple(args, "is#:command", &device, &command, &command_len)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibcmd(device, command, command_len); Py_END_ALLOW_THREADS if ( sta & ERR ) { _SetGpibError("cmd"); return NULL; } return PyInt_FromLong(sta); } static char gpib_remote_enable__doc__[] = "remote_enable -- set remote enable (board)\n" "remote_enable(handle, enable)"; static PyObject* gpib_remote_enable(PyObject *self, PyObject *args) { int device; int val; int sta; if (!PyArg_ParseTuple(args, "ii:remote_enable", &device,&val)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibsre(device,val); Py_END_ALLOW_THREADS if( sta & ERR){ _SetGpibError("remote_enable"); return NULL; } return PyInt_FromLong(sta); } static char gpib_clear__doc__[] = "clear -- clear device (device)\n" "clear(handle)"; static PyObject* gpib_clear(PyObject *self, PyObject *args) { int device; int sta; if (!PyArg_ParseTuple(args, "i:clear", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibclr(device); Py_END_ALLOW_THREADS if( sta & ERR){ _SetGpibError("clear"); return NULL; } return PyInt_FromLong(sta); } static char gpib_ibloc__doc__[] = "ibloc -- push device to local mode (device)\n" "ibloc(handle)"; static PyObject* gpib_ibloc(PyObject *self, PyObject *args) { int device; int sta; if (!PyArg_ParseTuple(args, "i:ibloc", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibloc(device); Py_END_ALLOW_THREADS if( sta & ERR){ _SetGpibError("ibloc"); return NULL; } return PyInt_FromLong(sta); } static char gpib_interface_clear__doc__[] = "interface_clear -- perform interface clear (board)\n" "interface_clear(handle)"; static PyObject* gpib_interface_clear(PyObject *self, PyObject *args) { int device; int sta; if (!PyArg_ParseTuple(args, "i:interface_clear", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibsic(device); Py_END_ALLOW_THREADS if ( sta & ERR){ _SetGpibError("interface_clear"); return NULL; } return PyInt_FromLong(sta); } static char gpib_close__doc__[] = "close -- close descriptor (board or device)\n" "close(handle)"; static PyObject* gpib_close(PyObject *self, PyObject *args) { int device; int sta; if (!PyArg_ParseTuple(args, "i:close", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibonl(device, 0); Py_END_ALLOW_THREADS if( sta & ERR ){ _SetGpibError("close"); return NULL; } return PyInt_FromLong(sta); } static char gpib_wait__doc__[] = "wait -- wait for event (board or device)\n" "wait(handle, mask)"; static PyObject* gpib_wait(PyObject *self, PyObject *args) { int device; int mask; int sta; if (!PyArg_ParseTuple(args, "ii:wait", &device, &mask)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibwait(device, mask); Py_END_ALLOW_THREADS if(sta & ERR) { _SetGpibError("wait"); return NULL; } return PyInt_FromLong(sta); } static char gpib_timeout__doc__[] = "timeout -- adjust io timeout (board or device)\n" "timeout(handle, timeout)\n\n" "timeout should be one of the symbolic constants TNONE to T1000s"; static PyObject* gpib_timeout(PyObject *self, PyObject *args) { int device; int value; int sta; if (!PyArg_ParseTuple(args, "ii:timeout", &device,&value)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibtmo(device, value); Py_END_ALLOW_THREADS if( sta & ERR){ _SetGpibError("tmo"); return NULL; } return PyInt_FromLong(sta); } static char gpib_serial_poll__doc__[] = "serial_poll -- read status byte / conduct serial poll (device)\n" "serial_poll(handle) -> status_byte"; static PyObject* gpib_serial_poll(PyObject *self, PyObject *args) { char spr; int device; int sta; if (!PyArg_ParseTuple(args, "i:serial_poll", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibrsp(device, &spr); Py_END_ALLOW_THREADS if( sta & ERR ){ _SetGpibError("serial_poll"); return NULL; } return PyInt_FromLong((int)spr); } static char gpib_spoll_bytes_doc__[] = "spoll_bytes -- get length of status byte queue (device)\n" "spoll_bytes(handle) -> status_byte_queue_length"; static PyObject* gpib_spoll_bytes(PyObject *self, PyObject *args) { short spb; int device; int sta; if (!PyArg_ParseTuple(args, "i:spoll_bytes", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibspb(device, &spb); Py_END_ALLOW_THREADS if( sta & ERR ){ _SetGpibError("spoll_bytes"); return NULL; } return PyInt_FromLong(spb); } static char gpib_trigger__doc__[] = "trigger -- trigger device (device)\n" "trigger(handle)"; static PyObject* gpib_trigger(PyObject *self, PyObject *args) { int device; int sta; if (!PyArg_ParseTuple(args, "i:trigger", &device)) return NULL; Py_BEGIN_ALLOW_THREADS sta = ibtrg(device); Py_END_ALLOW_THREADS if( sta & ERR){ _SetGpibError("trg"); return NULL; } return PyInt_FromLong(sta); } static char gpib_ibsta__doc__[] = "ibsta -- retrieve status\n" "ibsta()"; static PyObject* gpib_ibsta(PyObject *self, PyObject *args) { return PyInt_FromLong(ThreadIbsta()); } static char gpib_ibcnt__doc__[] = "ibcnt -- retrieve number of bytes transferred\n" "ibcnt()"; static PyObject* gpib_ibcnt(PyObject *self, PyObject *args) { return PyInt_FromLong(ThreadIbcntl()); } static char gpib_version__doc__[] = "version -- obtain the current linux gpib version\n" "version()"; static PyObject* gpib_version(PyObject *self, PyObject *args) { char *version; ibvers(&version); return PyString_FromString(version); } /* List of methods defined in the module */ static struct PyMethodDef gpib_methods[] = { {"find", gpib_find, METH_VARARGS, gpib_find__doc__}, {"ask", gpib_ask, METH_VARARGS, gpib_ask__doc__}, {"dev", gpib_dev, METH_VARARGS, gpib_dev__doc__}, {"config", gpib_config, METH_VARARGS, gpib_config__doc__}, {"listener", gpib_listener, METH_VARARGS, gpib_listener__doc__}, {"lines", gpib_lines, METH_VARARGS, gpib_lines__doc__}, {"read", gpib_read, METH_VARARGS, gpib_read__doc__}, {"write", gpib_write, METH_VARARGS, gpib_write__doc__}, {"write_async", gpib_write_async, METH_VARARGS, gpib_write_async__doc__}, {"command", gpib_command, METH_VARARGS, gpib_command__doc__}, {"remote_enable", gpib_remote_enable, METH_VARARGS, gpib_remote_enable__doc__}, {"clear", gpib_clear, METH_VARARGS, gpib_clear__doc__}, {"interface_clear", gpib_interface_clear, METH_VARARGS, gpib_interface_clear__doc__}, {"close", gpib_close, METH_VARARGS, gpib_close__doc__}, {"wait", gpib_wait, METH_VARARGS, gpib_wait__doc__}, {"timeout", gpib_timeout, METH_VARARGS, gpib_timeout__doc__}, {"serial_poll", gpib_serial_poll, METH_VARARGS, gpib_serial_poll__doc__}, {"spoll_bytes", gpib_spoll_bytes, METH_VARARGS, gpib_spoll_bytes_doc__}, {"trigger", gpib_trigger, METH_VARARGS, gpib_trigger__doc__}, {"ibsta", gpib_ibsta, METH_NOARGS, gpib_ibsta__doc__}, {"ibcnt", gpib_ibcnt, METH_NOARGS, gpib_ibcnt__doc__}, {"ibloc", gpib_ibloc, METH_VARARGS, gpib_ibloc__doc__}, {"version", gpib_version, METH_NOARGS, gpib_version__doc__}, {NULL, NULL} /* sentinel */ }; /* Initialization function for the module (*must* be called initgpib) */ static char gpib_module_documentation[] = "This module is a thin wrapper around the Linux GPIB C library.\n" "Documentation for the C library is available at:\n" " http://linux-gpib.sourceforge.net\n\n" "As in the C API, all functions return the value of ibsta,\n" "except where otherwise specified."; #ifdef IS_PY3K static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "gpib", /* m_name */ gpib_module_documentation, /* m_doc */ -1, /* m_size */ gpib_methods, /* m_methods */ NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL, /* m_free */ }; #endif PyMODINIT_FUNC #ifdef IS_PY3K PyInit_gpib(void) #else initgpib(void) #endif { PyObject *m; /* Create the module and add the functions */ #ifdef IS_PY3K m = PyModule_Create(&moduledef); #else m = Py_InitModule4("gpib", gpib_methods, gpib_module_documentation, (PyObject*)NULL, PYTHON_API_VERSION); #endif /* Add GpibError exception to the module */ GpibError = PyErr_NewException("gpib.GpibError", NULL, NULL); PyModule_AddObject(m, "GpibError", GpibError); /* Add some symbolic constants to the module */ /* timeout values */ PyModule_AddIntConstant(m, "TNONE", TNONE); PyModule_AddIntConstant(m, "T10us", T10us); PyModule_AddIntConstant(m, "T30us", T30us); PyModule_AddIntConstant(m, "T100us", T100us); PyModule_AddIntConstant(m, "T300us", T300us); PyModule_AddIntConstant(m, "T1ms", T1ms); PyModule_AddIntConstant(m, "T3ms", T3ms); PyModule_AddIntConstant(m, "T10ms", T10ms); PyModule_AddIntConstant(m, "T30ms", T30ms); PyModule_AddIntConstant(m, "T100ms", T100ms); PyModule_AddIntConstant(m, "T300ms", T300ms); PyModule_AddIntConstant(m, "T1s", T1s); PyModule_AddIntConstant(m, "T3s", T3s); PyModule_AddIntConstant(m, "T10s", T10s); PyModule_AddIntConstant(m, "T30s", T30s); PyModule_AddIntConstant(m, "T100s", T100s); PyModule_AddIntConstant(m, "T300s", T300s); PyModule_AddIntConstant(m, "T1000s", T1000s); /* ibconfig() option values */ PyModule_AddIntConstant(m, "IbcPAD", IbcPAD); PyModule_AddIntConstant(m, "IbcSAD", IbcSAD); PyModule_AddIntConstant(m, "IbcTMO", IbcTMO); PyModule_AddIntConstant(m, "IbcEOT", IbcEOT); PyModule_AddIntConstant(m, "IbcPPC", IbcPPC); PyModule_AddIntConstant(m, "IbcREADDR", IbcREADDR); PyModule_AddIntConstant(m, "IbcAUTOPOLL", IbcAUTOPOLL); PyModule_AddIntConstant(m, "IbcCICPROT", IbcCICPROT); PyModule_AddIntConstant(m, "IbcSC", IbcSC); PyModule_AddIntConstant(m, "IbcSRE", IbcSRE); PyModule_AddIntConstant(m, "IbcEOSrd", IbcEOSrd); PyModule_AddIntConstant(m, "IbcEOSwrt", IbcEOSwrt); PyModule_AddIntConstant(m, "IbcEOScmp", IbcEOScmp); PyModule_AddIntConstant(m, "IbcEOSchar", IbcEOSchar); PyModule_AddIntConstant(m, "IbcPP2", IbcPP2); PyModule_AddIntConstant(m, "IbcTIMING", IbcTIMING); PyModule_AddIntConstant(m, "IbcReadAdjust", IbcReadAdjust); PyModule_AddIntConstant(m, "IbcWriteAdjust", IbcWriteAdjust); PyModule_AddIntConstant(m, "IbcEventQueue", IbcEventQueue); PyModule_AddIntConstant(m, "IbcSPollBit", IbcSPollBit); PyModule_AddIntConstant(m, "IbcSendLLO", IbcSendLLO); PyModule_AddIntConstant(m, "IbcSPollTime", IbcSPollTime); PyModule_AddIntConstant(m, "IbcPPollTime", IbcPPollTime); PyModule_AddIntConstant(m, "IbcEndBitIsNormal", IbcEndBitIsNormal); PyModule_AddIntConstant(m, "IbcUnAddr", IbcUnAddr); PyModule_AddIntConstant(m, "IbcHSCableLength", IbcHSCableLength); PyModule_AddIntConstant(m, "IbcIst", IbcIst); PyModule_AddIntConstant(m, "IbcRsv", IbcRsv); PyModule_AddIntConstant(m, "IbcBNA", IbcBNA); /* ibask() option values */ PyModule_AddIntConstant(m, "IbaPAD", IbaPAD); PyModule_AddIntConstant(m, "IbaSAD", IbaSAD); PyModule_AddIntConstant(m, "IbaTMO", IbaTMO); PyModule_AddIntConstant(m, "IbaEOT", IbaEOT); PyModule_AddIntConstant(m, "IbaPPC", IbaPPC); PyModule_AddIntConstant(m, "IbaREADDR", IbaREADDR); PyModule_AddIntConstant(m, "IbaAUTOPOLL", IbaAUTOPOLL); PyModule_AddIntConstant(m, "IbaCICPROT", IbaCICPROT); PyModule_AddIntConstant(m, "IbaSC", IbaSC); PyModule_AddIntConstant(m, "IbaSRE", IbaSRE); PyModule_AddIntConstant(m, "IbaEOSrd", IbaEOSrd); PyModule_AddIntConstant(m, "IbaEOSwrt", IbaEOSwrt); PyModule_AddIntConstant(m, "IbaEOScmp", IbaEOScmp); PyModule_AddIntConstant(m, "IbaEOSchar", IbaEOSchar); PyModule_AddIntConstant(m, "IbaPP2", IbaPP2); PyModule_AddIntConstant(m, "IbaTIMING", IbaTIMING); PyModule_AddIntConstant(m, "IbaReadAdjust", IbaReadAdjust); PyModule_AddIntConstant(m, "IbaWriteAdjust", IbaWriteAdjust); PyModule_AddIntConstant(m, "IbaEventQueue", IbaEventQueue); PyModule_AddIntConstant(m, "IbaSPollBit", IbaSPollBit); PyModule_AddIntConstant(m, "IbaSendLLO", IbaSendLLO); PyModule_AddIntConstant(m, "IbaSPollTime", IbaSPollTime); PyModule_AddIntConstant(m, "IbaPPollTime", IbaPPollTime); PyModule_AddIntConstant(m, "IbaEndBitIsNormal", IbaEndBitIsNormal); PyModule_AddIntConstant(m, "IbaUnAddr", IbaUnAddr); PyModule_AddIntConstant(m, "IbaHSCableLength", IbaHSCableLength); PyModule_AddIntConstant(m, "IbaIst", IbaIst); PyModule_AddIntConstant(m, "IbaRsv", IbaRsv); PyModule_AddIntConstant(m, "IbaBNA", IbaBNA); PyModule_AddIntConstant(m, "Iba7BitEOS", Iba7BitEOS); /* ibwait() condition bits */ PyModule_AddIntConstant(m, "RQS", RQS); PyModule_AddIntConstant(m, "SRQI", SRQI); PyModule_AddIntConstant(m, "TIMO", TIMO); /* GPIB status byte bits */ PyModule_AddIntConstant(m, "IbStbRQS", IbStbRQS); PyModule_AddIntConstant(m, "IbStbESB", IbStbESB); PyModule_AddIntConstant(m, "IbStbMAV", IbStbMAV); /* line status bits */ PyModule_AddIntConstant(m, "ValidDAV", ValidDAV); PyModule_AddIntConstant(m, "ValidNDAC", ValidNDAC); PyModule_AddIntConstant(m, "ValidNRFD", ValidNRFD); PyModule_AddIntConstant(m, "ValidIFC", ValidIFC); PyModule_AddIntConstant(m, "ValidREN", ValidREN); PyModule_AddIntConstant(m, "ValidSRQ", ValidSRQ); PyModule_AddIntConstant(m, "ValidATN", ValidATN); PyModule_AddIntConstant(m, "ValidEOI", ValidEOI); PyModule_AddIntConstant(m, "BusDAV", BusDAV); PyModule_AddIntConstant(m, "BusNDAC", BusNDAC); PyModule_AddIntConstant(m, "BusNRFD", BusNRFD); PyModule_AddIntConstant(m, "BusIFC", BusIFC); PyModule_AddIntConstant(m, "BusREN", BusREN); PyModule_AddIntConstant(m, "BusSRQ", BusSRQ); PyModule_AddIntConstant(m, "BusATN", BusATN); PyModule_AddIntConstant(m, "BusEOI", BusEOI); /* Check for errors */ if (PyErr_Occurred()) Py_FatalError("can't initialize module gpib"); #ifdef IS_PY3K return m; #endif } language/python/gpibtest.py000066400000000000000000000002221507046215500163560ustar00rootroot00000000000000from time import sleep from Gpib import * v = Gpib('voltmeter') v.clear() v.write('D0 Q0') sleep(1) for i in range(0,10): print v.read() language/python/setup.py000066400000000000000000000006521507046215500157040ustar00rootroot00000000000000#!/usr/bin/env python import sys if sys.version_info < (3,10): from distutils.core import setup,Extension else: from setuptools import setup, Extension setup(name="gpib", version="1.0", description="Linux GPIB Python Bindings", py_modules = ['Gpib'], ext_modules=[ Extension("gpib", ["gpibinter.c"], include_dirs=["../../include"], library_dirs = ['../../lib/.libs'], libraries=["gpib", "pthread"] )] ) language/python/srq_board.py000066400000000000000000000031311507046215500165130ustar00rootroot00000000000000import sys sys.path.append('/usr/local/lib64/python3.9/site-packages') import gpib board = 1 device = 1 def query(handle, command, numbytes=100): gpib.write(handle,command) response = gpib.read(handle,numbytes) response = response.rstrip("\r\n") return response def initialise_device(handle): # set up device to assert SRQ/RQS gpib.write(handle,"*CLS") # Clear status registers gpib.write(handle,"*SRE 32") # Assert SRQ on OPC return def show_devid(handle): # Show device ID print query(handle,"*IDN?") return print gpib.version() # Show package version ud = gpib.dev(board,device) # Open the device gpib.config(board,gpib.IbcTMO, gpib.T30s) # Set timeout to 30 seconds show_devid(ud); initialise_device(ud); gpib.write(handle,"*TST;*OPC") # Initiate selftest and request OPC # Wait for Timeout or Service Request on board sta = gpib.wait(board, gpib.TIMO | gpib.SRQI) if (sta & gpib.TIMO) != 0: print "Timed out" else: print "SRQ asserted " # For each device which might pull SRQ stb = gpib.serial_poll(ud) # Read status byte print "stb = %#x"%(stb) if (stb & gpib.IbStbRQS) != 0: # Check for RQS bit print "Device asserted RQS" if (stb & gpib.IbStbESB) != 0: # Check for Event Status bit esr = int(query(ud,"ESR?")) # Read Event Status Register if (esr & 1) != 0: # Check for operation completed print "Device Operation Completed" # done gpib.close(ud) language/python/srq_device.py000066400000000000000000000030151507046215500166640ustar00rootroot00000000000000import sys sys.path.append('/usr/local/lib64/python3.9/site-packages') import gpib board = 1 device = 1 def query(handle, command, numbytes=100): gpib.write(handle,command) response = gpib.read(handle,numbytes) response = response.rstrip("\r\n") return response def initialise_device(handle): # set up device to assert SRQ/RQS gpib.write(handle,"*CLS") # Clear status registers gpib.write(handle,"*SRE 32") # Assert SRQ on Event return def show_devid(handle): # Show device ID print query(handle,"*IDN?") return print gpib.version() # Show package version ud = gpib.dev(board,device) # Open the device gpib.config(board,gpib.IbcAUTOPOLL,1) # Enable automatic serial polling gpib.config(ud,gpib.IbcTMO, gpib.T30s) # Set timeout to 30 seconds show_devid(ud); initialise_device(ud); gpib.write(handle,"*TST;*OPC") # Selftest and request OPC event # Wait for Timeout or Request Service on device sta = gpib.wait(ud, gpib.TIMO | gpib.RQS) if (sta & gpib.TIMO) != 0: print "Timed out" else: print "Device asserted RQS" stb = gpib.serial_poll(ud) # Read status byte print "stb = %#x"%(stb) if (stb & gpib.IbStbESB) != 0: # Check for Event Status bit esr = int(query(ud,"ESR?")) # Read Event Status Register if (esr & 1) != 0: # Check for operation completed print "Device Operation Completed" # done gpib.close(ud) language/tcl/000077500000000000000000000000001507046215500134305ustar00rootroot00000000000000language/tcl/.xsetup000066400000000000000000000005041507046215500147600ustar00rootroot00000000000000set Status(sens) "0" set Status(point) "0" set Status(mscan) "1" set Status(nref) "10" set Status(comment) "" set Status(to) "50" set Status(scan) "1" set Status(unsaved) "0" set Status(from) "0" set Status(run) "0" set Status(path) "./test" set Status(pause) "0" set Status(fnum) "1" set Status(delay) "1000" language/tcl/Makefile.am000066400000000000000000000015071507046215500154670ustar00rootroot00000000000000# language/tcl/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = gpib.n examples lib_LTLIBRARIES = libgpib_tcl.la libgpib_tcl_la_SOURCES = ibCmds.c TCL_CONFIG = $(TCL_BIN_DIR)/tclConfig.sh TCL_LIB_SPEC = `$(SHELL) -c '. $(TCL_CONFIG); eval echo $${TCL_LIB_SPEC};'` TCL_INC = `$(SHELL) -c '. $(TCL_CONFIG); eval echo $${TCL_INCLUDE_SPEC};'` #fix tcl directory for version independence libgpib_tcl_la_CFLAGS = $(LIBGPIB_CFLAGS) $(TCL_INC) libgpib_tcl_la_LDFLAGS = -release $(VERSION) $(LIBGPIB_LDFLAGS) $(TCL_LIB_SPEC) language/tcl/README000066400000000000000000000002421507046215500143060ustar00rootroot00000000000000'make' to compile, 'make install' to install. To load this extension just add the line load [info library]/libgpib_tcl.so near the beginning of your scripts. language/tcl/examples/000077500000000000000000000000001507046215500152465ustar00rootroot00000000000000language/tcl/examples/.xsetup000066400000000000000000000005111507046215500165740ustar00rootroot00000000000000set Status(sens) "0" set Status(point) "27" set Status(mscan) "1" set Status(nref) "5" set Status(comment) "" set Status(to) "500" set Status(scan) "0" set Status(unsaved) "0" set Status(from) "0" set Status(run) "1" set Status(path) "./test.dat" set Status(pause) "0" set Status(fnum) "5" set Status(delay) "1000" language/tcl/examples/example1.tcl000077500000000000000000000040101507046215500174640ustar00rootroot00000000000000#!/usr/bin/wish -f # # This example is a simple Digital Voltmeter display # # # load ../libgpib_tcl.so # # init device #--------------------------------------------- set device [gpib find voltmeter ] gpib sic $device gpib ren $device 1 gpib clear $device gpib write $device "D1Ready" gpib write $device "D0L0Q1OT1A1" #gpib write $device "D0L0Q1OT2" #--------------------------------------------- # set result [gpib read $device 15] set mode "V" set refresh 50 set block 0 proc displ_refresh {} { global result device refresh block mode gpib wait $device srq .light configure -background red update set result [gpib read $device 15 ]$mode if { $block == 0 } { after $refresh displ_refresh } .light configure -background steelblue update } proc Mode { mod } { global mode set mode $mod } label .lab -text "GPIB Demo" -font -adobe-times-bold-r-normal--18-180-75-75-p-99-iso8859-1 -justify right label .light -width 1 -height 1 -relief raised -text "*" label .val -width 15 -textvariable result -relief sunken -font -adobe-helvetica-bold-r-normal--24-240-75-75-p-138-iso8859-1 button .but1 -text "Quit" -command { set block 1; update idletasks ;gpib close $device ; exit} button .but2 -text "Ohm" -command { gpib write $device "O2" ; Mode "Ohm" } button .but3 -text "V ~" -command { gpib write $device "VA" ; Mode "V" } button .but4 -text "V =" -command { gpib write $device "VD" ; Mode "V" } button .but5 -text "A ~" -command { gpib write $device "IA" ; Mode "A" } button .but6 -text "A =" -command { gpib write $device "ID" ; Mode "A" } button .but7 -text "AutoRange" -command { gpib write $device "A1" } button .but8 -text "NoAuto" -command { gpib write $device "A0" } pack append . .lab { top fillx} .val { top fillx } .light {right fillx } pack append . .but1 { bottom fillx } .but2 { bottom fillx } .but3 { bottom fillx } \ .but4 { bottom fillx} .but5 { bottom fillx} .but6 { bottom fillx} \ .but7 { top filly } .but8 { top filly } displ_refresh language/tcl/examples/example2.tcl000077500000000000000000000156461507046215500175060ustar00rootroot00000000000000#!/usr/bin/wish -f # # This example uses the BLT extension that is provided as binary # distribution in the contrib package, it can be obtained from # ftp://ftp.neosoft.com/tcl/extensions/BLT2.1.tar.gz # # It is a simple life display measurement program for slow data aquisition # that can be changed for own needs. # see DoMeas for this. # # If you change this for taking your data please let me know # clausi@chemie.fu-berlin.de # load ../libgpib_tcl.so load ../../../contrib/tcltk/modules/libBLT.so.2.1 set auto_path [linsert $auto_path 0 ./tclib] ## init device set device [gpib find "voltmeter"] gpib sic $device gpib ren $device 1 gpib clear $device gpib write $device "D1Ready" # setup device gpib write $device "D0L0Q1OT1A1" ######################################################################### set setup_file .xsetup ############################## # Global variables # set yval 0 set Status(scan) 0 set Status(point) 0 set Status(mscan) 5 set Status(unsaved) 0 set Status(run) 0 set Status(pause) 0 set Status(from) 0 set Status(to) 50 set Status(delay) 500 set Status(sens) 0 set Status(path) "./test.dat" set Status(fnum) 0 set Status(comment) "" set Status(nref) 5 set Status(delay) 1000 ### load setup if one if [file exists $setup_file] { source $setup_file } ###################################################################### proc ExitGracefully { } { global Status setup_file if { $Status(unsaved) } { } else { SaveSetup Status $setup_file destroy . } } ###################################################################### B_Init DataA B_Init DataB B_Init DataC proc Start {} { global Status DataA DataB DataC set Status(run) 1 set Status(pause) 0 set Status(point) $Status(from) set Status(scan) 0 B_Init DataA B_Init DataB B_Init DataC .graph.xy xaxis configure -min $Status(from) -max $Status(to) .labels.t10 configure -background red set Status(mscan) [.scales.s get] RunTask } proc Stop {} { global Status set Status(run) 0 } proc Pause {} { global Status if { $Status(pause) } { set Status(pause) 0 .bbar.p configure -text "Pause" } else { set Status(pause) 1 .bbar.p configure -text "Cont" } } #### # Task Scheduler #### proc RunTask {} { global Status if { $Status(run) } { if { ! $Status(pause) } { .labels.t4 configure -background blue ; update idletasks DoMeas .labels.t4 configure -background grey ; update idletasks } after $Status(delay) RunTask } } #### # Measurement #### proc DoMeas {} { global Status DataA DataB DataC yval device if { $Status(point) >= $Status(to) } { B_AddY DataA DataB DataC DisplayRefresh set Status(point) $Status(from) incr Status(scan) # After scan save added buffer do meas buffer # and clear temp buffer B_Copy DataC DataB # write backup file B_WriteFile DataC "temp.bak" B_Init DataA } if { $Status(scan) < $Status(mscan) } { # # Here the Data String is read from the device # # begin read data set yval [ gpib read $device 15 ] # # end read data # B_Put DataA $Status(point) $yval B_AddY DataA DataB DataC DisplayRefresh ################## # enable this if you want the plot not to be refreshed on each data point # if { [expr $Status(point) % $Status(nref) ] == 0 } { # B_AddY DataA DataB DataC # DisplayRefresh # } incr Status(point) } else { #finished ! # if { [llength DataA] > 0 } { # B_AddY DataA DataB DataC # } # DisplayRefresh set Status(run) 0 Save } } #### # display #### proc DisplayRefresh { } { global Status DataC # if { [llength DataC ] > 1 } { .graph.xy element configure display -xdata $DataC(x) -ydata $DataC(y) .graph.xy element show display # } } ###### # Menus and Buttons ###################################################################### frame .labels -relief ridge -borderwidth 2 pack .labels -side top -fill x label .labels.t1 -text "Scans: " label .labels.t2 -textvariable Status(scan) -background grey -width 5 pack .labels.t1 .labels.t2 -side left label .labels.t3 -text "Point: " label .labels.t4 -textvariable Status(point) -background grey -width 5 pack .labels.t3 .labels.t4 -side left label .labels.t5 -text "=" label .labels.t6 -textvariable yval -background grey -width 15 label .labels.t7 -text " V" pack .labels.t5 .labels.t6 .labels.t7 -side left label .labels.t8 -text "File: " label .labels.t9 -textvariable Status(path) -background grey label .labels.t10 -textvariable Status(fnum) -background grey pack .labels.t8 .labels.t9 .labels.t10 -side left -padx 5 ############################## frame .cmt label .cmt.l1 -text Comment entry .cmt.e1 -relief sunken -background grey90 -textvariable Status(comment) pack .cmt.l1 -side left pack .cmt.e1 -side left -fill x -expand yes pack .cmt -fill x ############################## frame .graph -relief ridge -borderwidth 2 pack .graph graph .graph.xy -relief sunken -background grey -borderwidth 2 -width 600 -height 400 pack .graph.xy .graph.xy element line display -xdata {0 0} -ydata {0 1} ############################## frame .entrys -relief ridge -borderwidth 2 label .entrys.l1 -text From entry .entrys.e1 -background grey90 -textvariable Status(from)\ -relief sunken pack .entrys.l1 .entrys.e1 label .entrys.l2 -text To entry .entrys.e2 -background grey90 -textvariable Status(to)\ -relief sunken pack .entrys.l2 .entrys.e2 pack .entrys -side left -fill x ############################## frame .bbar -relief ridge -borderwidth 2 pack .bbar -fill x -anchor n button .bbar.q -text "Quit" -command "ExitGracefully" button .bbar.s -text "Start" -command "Start" button .bbar.o -text "Stop" -command "Stop" button .bbar.p -text "Pause" -command "Pause" button .bbar.sv -text "Save" -command "Save" pack .bbar.q .bbar.s .bbar.o .bbar.p .bbar.sv -side left frame .scales -relief ridge -borderwidth 2 scale .scales.s -label "Scans" -from 1 -to 200 \ -sliderlength 15 -width 20 -showvalue 1 -orient horizontal pack .scales.s -side left -fill x pack .scales -side top -fill x label .scales.l3 -text Path: entry .scales.e3 -background grey90 -textvariable Status(path)\ -relief sunken pack .scales.l3 -side top -fill x pack .scales.e3 -fill x #### # #### proc Save { } { global DataC DataA DataB Status set fpath $Status(path).$Status(fnum) while { [file exists $fpath] } { set Status(fnum) [expr $Status(fnum) + 1] set fpath $Status(path).$Status(fnum) } B_WriteFile DataC $fpath "$Status(comment)" .labels.t10 configure -background grey } #### # #### proc SaveSetup { arr fname } { global $arr set fds [ open $fname "w" ] foreach n [array names $arr ] { set val [eval "set $arr\($n\)" ] puts $fds "set $arr\($n\) \"$val\" " } close $fds } language/tcl/examples/tclib/000077500000000000000000000000001507046215500163435ustar00rootroot00000000000000language/tcl/examples/tclib/Buffer.tcl000077500000000000000000000032731507046215500202700ustar00rootroot00000000000000###################################################################### # #@---- Buffer.tcl Data Buffer manipulation routines # # ###################################################################### #### #@ B_Init { name } initialize new Buffer or clear old one #### proc B_Init { name } { upvar $name F set F(x) {} set F(y) {} set F(i) 0 } #### #@ B_Dim { buf } returns the actual length of a buffer #### proc B_Dim { buf } { upvar $buf F return [llength $F(x)] } #### #@ B_WriteFile { Buf File } writes buffer to file #### proc B_WriteFile { Buf File { comment "none" } } { upvar $Buf A set fd [open $File "w"] puts $fd "\#f XY(raw)" puts $fd "\#c $comment" for { set i 0 } { $i < $A(i) } { incr i } { puts -nonewline $fd [lindex $A(x) $i] puts -nonewline $fd " " puts $fd [lindex $A(y) $i] } close $fd } #### #@ B_Copy { A B } Copy Buff A to B (dim A is significant) #### proc B_Copy { BufA BufB } { upvar $BufA A $BufB B B_Init B set B(x) $A(x) set B(y) $A(y) set B(i) $A(i) } #### #@ B_Put { Buf X Y } Adds a pair X,Y to buffer #### proc B_Put { Buf X Y } { upvar $Buf A lappend A(x) $X lappend A(y) $Y incr A(i) } #### #@ B_AddY { A B C } Performs an addition of the Y elements of two Buffers #### proc B_AddY { A B C } { upvar $A A1 $B A2 $C C1 B_Init C1 for { set i 0 } { $i < $A1(i) } { incr i } { lappend C1(x) [lindex $A1(x) $i] if { $A2(i) > $i } { lappend C1(y) [expr ([lindex $A1(y) $i] + [lindex $A2(y) $i]) / 2.0 ] } else { lappend C1(y) [lindex $A1(y) $i] } } set C1(i) $i } ###################################################################### language/tcl/examples/tclib/FileDia.tcl000066400000000000000000000031501507046215500203430ustar00rootroot00000000000000 # # File Dialog routines # set File(path) "./data/" set File(base) "test" set File(num) 1 set File(result) 0 proc GetFile { { number $File(num) } } { global File toplevel .f label .f.l -text "File Selector" -relief ridge -borderwidth 2 pack .f.l -side top -fill x frame .f.e -relief ridge -borderwidth 2 label .f.e.l1 -text "Basename" entry .f.e.e1 -relief sunken -background grey90 -textvariable File(base) -width 20 pack .f.e.l1 -side left pack .f.e.e1 -side left -fill x selector .f.e File(num) "File Number" pack .f.e -side top -fill both frame .f.b -relief ridge -borderwidth 2 button .f.b.q -text "Cancel" -command "set File(result) 0;destroy .f" button .f.b.o -text "OK" -command "set File(result) 1;destroy .f" pack .f.b.q -side left -padx 20 -pady 10 pack .f.b.o -side right -padx 20 -pady 10 pack .f.b -side top -fill x } ###################################################################### proc selector { w var label } { global $var bitmap_path frame $w.frame$var -relief ridge -borderwidth 2 button $w.frame$var.up -text + -command "incr $var 1" button $w.frame$var.down -text - -command "incr $var -1" label $w.frame$var.disp -background grey90 -textvariable $var -width 2 \ -relief sunken label $w.frame$var.label -text $label pack $w.frame$var -padx 8 -pady 5 -side left -fill x -expand yes pack $w.frame$var.down -side left -padx 8 -pady 8 pack $w.frame$var.disp -side left -pady 8 pack $w.frame$var.up -side left -padx 8 -pady 8 pack $w.frame$var.label -side left -expand yes -padx 5 } #GetFilelanguage/tcl/examples/tclib/tclIndex000066400000000000000000000015601507046215500200420ustar00rootroot00000000000000# Tcl autoload index file, version 2.0 # This file is generated by the "auto_mkindex" command # and sourced to set up indexing information for one or # more commands. Typically each line is a command that # sets an element in the auto_index array, where the # element name is the name of a command and the value is # a script that loads the command. set auto_index(B_Init) [list source [file join $dir Buffer.tcl]] set auto_index(B_Dim) [list source [file join $dir Buffer.tcl]] set auto_index(B_WriteFile) [list source [file join $dir Buffer.tcl]] set auto_index(B_Copy) [list source [file join $dir Buffer.tcl]] set auto_index(B_Put) [list source [file join $dir Buffer.tcl]] set auto_index(B_AddY) [list source [file join $dir Buffer.tcl]] set auto_index(GetFile) [list source [file join $dir FileDia.tcl]] set auto_index(selector) [list source [file join $dir FileDia.tcl]] language/tcl/gpib.n000066400000000000000000000135411507046215500145340ustar00rootroot00000000000000.\" '\" Copyright 1990 Regents of the University of California '\" Permission to use, copy, modify, and distribute this '\" documentation for any purpose and without fee is hereby '\" granted, provided that this notice appears in all copies. '\" The University of California makes no representations about '\" the suitability of this material for any purpose. It is '\" provided "as is" without express or implied warranty. '\" '\" $Header$ SPRITE (Berkeley) .\" The definitions below are for supplemental macros used in Sprite .\" manual entries. .\" .\" .HS name section [date [version]] .\" Replacement for .TH in other man pages. See below for valid .\" section names. .\" .\" .AP type name in/out [indent] .\" Start paragraph describing an argument to a library procedure. .\" type is type of argument (int, etc.), in/out is either "in", "out", .\" or "in/out" to describe whether procedure reads or modifies arg, .\" and indent is equivalent to second arg of .IP (shouldn't ever be .\" needed; use .AS below instead) .\" .\" .AS [type [name]] .\" Give maximum sizes of arguments for setting tab stops. Type and .\" name are examples of largest possible arguments that will be passed .\" to .AP later. If args are omitted, default tab stops are used. .\" .\" .BS .\" Start box enclosure. From here until next .BE, everything will be .\" enclosed in one large box. .\" .\" .BE .\" End of box enclosure. .\" .\" .VS .\" Begin vertical sidebar, for use in marking newly-changed parts .\" of man pages. .\" .\" .VE .\" End of vertical sidebar. .\" .\" .DS .\" Begin an indented unfilled display. .\" .\" .DE .\" End of indented unfilled display. .\" .\" # Heading for Sprite man pages .de HS .if '\\$2'cmds' .TH \\$1 1 \\$3 \\$4 .if '\\$2'lib' .TH \\$1 3 \\$3 \\$4 .if '\\$2'tcl' .TH \\$1 3 \\$3 \\$4 .if '\\$2'tk' .TH \\$1 3 \\$3 \\$4 .if t .wh -1.3i ^B .nr ^l \\n(.l .ad b .. .\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ie !"\\$3"" \{\ .ta \\n()Au \\n()Bu \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. .\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .\" # BS - start boxed text .\" # ^y = starting y location .\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. .\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. .\" # VS - start vertical sidebar .\" # ^Y = starting y location .\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. .\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. .\" # Special macro to handle page bottom: finish off current .\" # box/sidebar if in box/sidebar mode, then invoked standard .\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. .\" # DS - begin display .de DS .RS .nf .sp .. .\" # DE - end display .de DE .fi .RE .sp .5 .. .HS gpib cmds .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME gpib \- Command Interface to GPIB Command Library .SH SYNOPSIS \fBgpib\fI \fIcommand \fR[\fIparameter\fR] .SH "COMMANDS" .LP .nf .ta 4c 8c 12c \fBfind\fR \fBread\fR \fBwrite\fR \fBclose\fR \fBclear\fR \fBren\fR \fBsic\fR \fBcmd\fR \fBwait\fR .fi .LP .BE .SH "INTRODUCTON" .ta 4c .IP The GPIB Extension provides some essential commands from the GPIB Library to TCL/Tk. With this TCL commands you can initialize your GPIB Interface, send strings and commands to devices and get their measurement results. .LP .SH "DESCRIPTION" .ta 4c .LP .nf \fBfind\fR \fImnemonic\fR .fi .IP Returns a device descriptor for the device with name \fImnemonic\fR and initializes the device. The device must have been configured in /etc/gpib.conf with correct mnemonic name and GPIB adress. .LP .nf \fBread\fR \fIdevice\fR \fInum-bytes\fR .fi .IP Reads \fInum-bytes\fR from \fIdevice\fR. .LP .nf \fBwrite\fR \fIdevice\fR \fIstring\fR .fi .IP Sends \fIstring\fR to the device. .LP .nf \fBcmd\fR \fIdevice\fR \fIstring\fR .fi .IP Sends \fIstring\fR as GPIB Command to device. .LP .nf \fBren\fR \fIdevice\fR \fIflag\fR .fi .IP If \fIflag\fR is 1 the device is set to Remote Enable (REM) state, if 0 local mode is selected. .LP .nf \fBsic\fR \fIdevice\fR .fi .IP Performs the 'Send Interface Clear' command for 100us .LP .nf \fBwait\fR \fIdevice\fR \fImasks\fR .fi .IP Waits for a event. Valid values for \fImasks\fR are: .PP \fBsrq\fR SRQ line is asserted. .PP \fBtimo\fR A timeout occured. .LP .nf \fBclose\fR \fIdevice\fR .fi .IP Disconnects the desired device Descriptor from device and closes the device driver's file handler. .LP .SH KEYWORDS gpib, ieee488 .SH BUGS .PP The Buffer size for read/write and command operations is limited to 512 bytes at this time. This could cause problems if you have more data to read/write. language/tcl/ibCmds.c000066400000000000000000000265141507046215500150050ustar00rootroot00000000000000#include #include #include #include #include #undef _ANSI_ARGS_ #define _ANSI_ARGS_(x) x void ib_CreateVerboseError(Tcl_Interp *interp,char *entry ); int Gpib_tcl_Init ( Tcl_Interp *interp ){ extern int gpibCmd _ANSI_ARGS_(( ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[] )); Tcl_CreateCommand(interp,"gpib",gpibCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL ); return TCL_OK; } /**********************************************************************/ int ibWrite _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])){ if( argc != 3 ){ Tcl_SetResult(interp, "Error: write ", TCL_STATIC); return TCL_ERROR; } if( ibwrt( atoi( argv[1]) , argv[2], strlen(argv[2]) ) & ERR ){ ib_CreateVerboseError(interp,"ibwrt"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc != 3 ){ Tcl_SetResult(interp, "Error: cmd ", TCL_STATIC); return TCL_ERROR; } if( ibcmd( atoi( argv[1]) , argv[2], strlen(argv[2]) ) & ERR ){ ib_CreateVerboseError(interp,"ibcmd"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibRead _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ char *buf; int len; int desc; if( argc != 3 ){ Tcl_SetResult(interp, "Error: read ", TCL_STATIC); return TCL_ERROR; } desc = strtol(argv[1], NULL, 0); len = strtol(argv[2], NULL, 0); if ((buf = (char *)malloc( len + 1 )) == NULL) { Tcl_SetResult(interp, "Error: Out of Memory", TCL_STATIC); return TCL_ERROR; } if( ibrd( desc , buf, len ) & ERR ){ /* ib_CreateVerboseError(interp,"ibrd"); return TCL_ERROR; */ Tcl_AppendResult(interp, "ERROR" , (char *) NULL ); free(buf); return TCL_ERROR; } buf[ibcnt] = '\0'; Tcl_AppendResult(interp, buf, (char *) NULL ); free(buf); return TCL_OK; } /**********************************************************************/ int ibDev _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])) { int dev; char res[10]; int minor, pad, sad, timo, eot, eos; if( argc != 7 ) { Tcl_SetResult(interp, "Error: dev ", TCL_STATIC); return TCL_ERROR; } minor = strtol(argv[1], NULL, 0); pad = strtol(argv[2], NULL, 0); sad = strtol(argv[3], NULL, 0); timo = strtol(argv[4], NULL, 0); eot = strtol(argv[5], NULL, 0); eos = strtol(argv[6], NULL, 0); if(( dev = ibdev(minor, pad, sad, timo, eot, eos)) < 0) { ib_CreateVerboseError(interp,"ibdev"); return TCL_ERROR; } sprintf(res, "%4d", dev); Tcl_SetResult( interp, res, TCL_VOLATILE ); return TCL_OK; } /**********************************************************************/ int ibFind _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])) { int dev; char res[10]; if( argc != 2 ) { Tcl_SetResult(interp, "Error: find ", TCL_STATIC); return TCL_ERROR; } if(( dev = ibfind(argv[1])) < 0 ) { ib_CreateVerboseError(interp,"ibfind"); return TCL_ERROR; } sprintf(res, "%4d", dev); Tcl_SetResult( interp, res, TCL_VOLATILE ); return TCL_OK; } /**********************************************************************/ int ibSre _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc != 3 ){ Tcl_SetResult(interp, "Error: ibsre ", TCL_STATIC); return TCL_ERROR; } if( ibsre( atoi( argv[1]) , atoi( argv[2] )) & ERR ){ ib_CreateVerboseError(interp,"ibsre"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibSic _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc != 2 ){ Tcl_SetResult(interp, "Error: sic ", TCL_STATIC); return TCL_ERROR; } if( ibsic( atoi( argv[1])) & ERR ){ ib_CreateVerboseError(interp,"ibsic"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibClr _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc != 2 ){ Tcl_SetResult(interp, "Error: clear ", TCL_STATIC); return TCL_ERROR; } if( ibclr( atoi( argv[1])) & ERR ){ ib_CreateVerboseError(interp,"ibclr"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibOnl _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc != 3 ){ Tcl_SetResult(interp, "Error: onl ", TCL_STATIC); return TCL_ERROR; } if( ibonl( atoi( argv[1]),atoi(argv[2])) & ERR ){ ib_CreateVerboseError(interp,"ibonl"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibWait _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ int mask=0; register int i; if( argc < 3 ){ Tcl_SetResult(interp, "Error: wait ", TCL_STATIC); return TCL_ERROR; } for( i=2; i ", TCL_STATIC); return TCL_ERROR; } if( ibonl( atoi( argv[1]),0 ) & ERR ){ ib_CreateVerboseError(interp,"ibclose"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibRsp _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ char spb; char spr[5]; if( argc < 2){ Tcl_SetResult(interp, "Error: rsp ", TCL_STATIC); return TCL_ERROR; } if( ibrsp( atoi( argv[1]), &spb ) & ERR ){ ib_CreateVerboseError(interp,"ibrsp"); return TCL_ERROR; } sprintf(spr,"%3d",spb); /* convert serial response to integer string */ Tcl_AppendResult(interp,spr,(char *)NULL); return TCL_OK; } /**********************************************************************/ int ibTrg _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc < 2){ Tcl_SetResult(interp, "Error: trg ", TCL_STATIC); return TCL_ERROR; } if( ibtrg( atoi( argv[1]) ) & ERR ){ ib_CreateVerboseError(interp,"ibtrg"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ int ibRsv _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc,const char*argv[])){ if( argc < 2){ Tcl_SetResult(interp, "Error: rsv ", TCL_STATIC); return TCL_ERROR; } if( ibrsv( atoi( argv[1]) , (char) atoi( argv[2] ) ) & ERR ){ ib_CreateVerboseError(interp,"ibrsv"); return TCL_ERROR; } return TCL_OK; } /**********************************************************************/ static char errbuf[80]; void ib_CreateVerboseError(Tcl_Interp *interp,char *entry ){ strcpy(errbuf,entry); strcat(errbuf,": \nIBSTAT = <"); if ( ibsta & ERR ) strcat(errbuf," ERR"); if ( ibsta & TIMO ) strcat(errbuf," | TIMO"); if ( ibsta & END ) strcat(errbuf," | END"); if ( ibsta & SRQI ) strcat(errbuf," | SRQI"); if ( ibsta & RQS ) strcat(errbuf," | RQS"); if ( ibsta & CMPL ) strcat(errbuf," | CMPL"); /*if ( ibsta & LOK ) strcat(errbuf," | LOK");*/ /*if ( ibsta & REM ) strcat(errbuf," | REM");*/ if ( ibsta & CIC ) strcat(errbuf," | CIC"); if ( ibsta & ATN ) strcat(errbuf," | ATM"); if ( ibsta & TACS ) strcat(errbuf," | TACS"); if ( ibsta & LACS ) strcat(errbuf," | LACS"); /*if ( ibsta & DTAS ) strcat(errbuf," | DATS");*/ /*if ( ibsta & DCAS ) strcat(errbuf," | DCTS");*/ strcat(errbuf,"> \nIBERR = "); if ( iberr == EDVR) strcat(errbuf," EDVR "); if ( iberr == ECIC) strcat(errbuf," ECIC "); if ( iberr == ENOL) strcat(errbuf," ENOL "); if ( iberr == EADR) strcat(errbuf," EADR "); if ( iberr == EARG) strcat(errbuf," ECIC "); if ( iberr == ESAC) strcat(errbuf," ESAC "); if ( iberr == EABO) strcat(errbuf," EABO "); if ( iberr == ENEB) strcat(errbuf," ENEB "); if ( iberr == EOIP) strcat(errbuf," EOIP "); if ( iberr == ECAP) strcat(errbuf," ECAP "); if ( iberr == EFSO) strcat(errbuf," EFSO "); if ( iberr == EBUS) strcat(errbuf," EBUS "); if ( iberr == ESTB) strcat(errbuf," ESTB "); if ( iberr == ESRQ) strcat(errbuf," ESRQ "); if ( iberr == ETAB) strcat(errbuf," ETAB "); Tcl_AppendResult(interp, errbuf , (char *) NULL ); } /**********************************************************************/ int gpibCmd _ANSI_ARGS_(( ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[] )) { if(argc < 2) { Tcl_SetResult(interp,"Error: unspecified gpib command",TCL_STATIC); return TCL_ERROR; } if( !strcmp(argv[1],"dev")){ return ibDev( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"find")){ return ibFind( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"read")){ return ibRead( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"write")){ return ibWrite( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"online")){ return ibOnl( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"clear")){ return ibClr( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"ren")){ return ibSre( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"sic")){ return ibSic( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"cmd")){ return ibCmd( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"wait")){ return ibWait( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"close")){ return ibClose( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"rsp")){ return ibRsp( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"rsv")){ return ibRsv( clientData, interp, argc-1,argv+1 ); } if( !strcmp(argv[1],"trg")){ return ibTrg( clientData, interp, argc-1,argv+1 ); } Tcl_SetResult(interp,"Error: unrecognized gpib command",TCL_STATIC); return TCL_ERROR; } lib/000077500000000000000000000000001507046215500116315ustar00rootroot00000000000000lib/Makefile.am000066400000000000000000000036401507046215500136700ustar00rootroot00000000000000# lib/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = . gpib_config lib_LTLIBRARIES = libgpib.la noinst_HEADERS = ibConf.h ib_internal.h BUILT_SOURCES = ibConfLex.c ibConfLex.h ibConfYacc.c ibConfYacc.h ibVers.h MAINTAINERCLEANFILES = ibConfLex.c ibConfLex.h ibConfYacc.c ibConfYacc.h ibVers.h EXTRA_DIST = ibConfLex.l ibConfYacc.y gpib_version_script libgpib_la_SOURCES = \ ../include/gpib/ib.h ib_internal.h ibConf.h ibP.h parse.h \ ibCac.c ibClr.c ibCmd.c ibEos.c ibEot.c \ ibFind.c ibLines.c ibOnl.c ibPad.c ibRd.c ibRpp.c ibRsp.c ibRsv.c \ ibSad.c ibSic.c ibSpb.c ibSre.c ibTmo.c ibTrg.c ibWait.c ibWrt.c \ ibGts.c ibBoard.c ibutil.c globals.c ibask.c ibppc.c \ ibLoc.c ibDma.c ibdev.c ibbna.c async.c ibconfig.c ibFindLstn.c \ ibEvent.c local_lockout.c self_test.c pass_control.c ibstop.c \ ibConfLex.c ibConfLex.h ibConfYacc.c ibConfYacc.h ibVers.c ibVers.h libgpib_la_CFLAGS = $(LIBGPIB_CFLAGS) -DDEFAULT_CONFIG_FILE="\"$(sysconfdir)/gpib.conf\"" libgpib_la_LDFLAGS = -version-info @GPIB_SO_VERSION@ -Wl,--version-script=$(srcdir)/gpib_version_script -lpthread $(srcdir)/ibConfLex.c $(srcdir)/ibConfLex.h: $(srcdir)/ibConfLex.l $(LEX) -DYY_NO_INPUT $< $(srcdir)/ibConfYacc.c $(srcdir)/ibConfYacc.h: $(srcdir)/ibConfYacc.y $(YACC) -Wno-yacc -d -p gpib_yy -o $(srcdir)/ibConfYacc.c $< $(srcdir)/ibVers.h: if git status >/dev/null 2>&1 ; then \ echo "#define GPIB_SCM_VERSION $(VERSION) [`git show --oneline -s | cut -d ' ' -f 1`]" >$(srcdir)/ibVers.h ;\ else \ echo "#define GPIB_SCM_VERSION $(VERSION)" >$(srcdir)/ibVers.h ;\ fi # pkg-config pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libgpib.pc lib/async.c000066400000000000000000000130011507046215500131050ustar00rootroot00000000000000/*************************************************************************** lib/async.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include #include static void* do_aio(void *varg); struct gpib_aio_arg { int ud; ibConf_t *conf; int gpib_aio_type; int condition_flag; unsigned int usec_timeout; }; void init_async_op(struct async_operation *async) { pthread_mutex_init(&async->lock, NULL); pthread_mutex_init(&async->join_lock, NULL); pthread_cond_init(&async->condition, NULL); async->buffer = NULL; async->buffer_length = 0; async->iberr = 0; async->ibsta = 0; async->ibcntl = 0; async->in_progress = 0; async->abort = 0; } static void cleanup_aio(void *varg) { struct gpib_aio_arg arg = *((struct gpib_aio_arg*) varg); ibBoard_t *board = interfaceBoard(arg.conf); ibstatus(arg.conf, 0, 0, CMPL); // set CMPL flag int retval = unlock_board_mutex(board); assert(retval == 0); } int gpib_aio_launch(int ud, ibConf_t *conf, int gpib_aio_type, void *buffer, long cnt) { int retval; struct gpib_aio_arg *arg; pthread_attr_t attributes; arg = malloc(sizeof(*arg)); if (arg == NULL) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } arg->ud = ud; arg->conf = conf; arg->gpib_aio_type = gpib_aio_type; arg->condition_flag = 0; arg->usec_timeout = conf->settings.usec_timeout; // Copy timeout pthread_mutex_lock(&conf->async.lock); if (conf->async.in_progress) { pthread_mutex_unlock(&conf->async.lock); setIberr(EOIP); return -1; } conf->async.ibsta = 0; conf->async.ibcntl = 0; conf->async.iberr = 0; conf->async.buffer = buffer; conf->async.buffer_length = cnt; conf->async.abort = 0; conf->async.aio_type = gpib_aio_type; /* used in my_ibcmd to suppress setting CMPL */ pthread_attr_init(&attributes); pthread_attr_setstacksize(&attributes, 0x10000); retval = pthread_create(&conf->async.thread, &attributes, do_aio, arg); pthread_attr_destroy(&attributes); conf->async.in_progress = (retval == 0); while (arg->condition_flag == 0) pthread_cond_wait(&conf->async.condition, &conf->async.lock); pthread_mutex_unlock(&conf->async.lock); free(arg); arg = NULL; if (retval) { setIberr(EDVR); setIbcnt(retval); return -1; } return 0; } static void* do_aio(void *varg) { size_t count; struct gpib_aio_arg * const arg_p = (struct gpib_aio_arg*) varg; struct gpib_aio_arg arg; ibConf_t *conf; ibBoard_t *board; unsigned int usec_timeout; int retval; arg = *arg_p; conf = arg.conf; usec_timeout = arg.usec_timeout; board = interfaceBoard(conf); retval = lock_board_mutex(board); if (retval == 0) ibstatus(conf, 0, CMPL, 0); // clear CMPL flag pthread_mutex_lock(&conf->async.lock); arg_p->condition_flag = 1; pthread_cond_broadcast(&conf->async.condition); pthread_mutex_unlock(&conf->async.lock); // don't use arg_p after this point, it may be // deallocated by the thread which launched this one. if (retval < 0) return NULL; pthread_cleanup_push(cleanup_aio, &arg); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); switch(arg.gpib_aio_type) { case GPIB_AIO_COMMAND: count = retval = my_ibcmd(conf, usec_timeout, conf->async.buffer, conf->async.buffer_length); break; case GPIB_AIO_READ: retval = my_ibrd(conf, usec_timeout, conf->async.buffer, conf->async.buffer_length, &count); break; case GPIB_AIO_WRITE: retval = my_ibwrt(conf, usec_timeout, conf->async.buffer, conf->async.buffer_length, &count); break; default: retval = -1; fprintf(stderr, "libgpib: bug! in %s\n", __FUNCTION__); break; } pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&conf->async.lock); if (retval < 0) { if (ThreadIberr() != EDVR) conf->async.ibcntl = count; else conf->async.ibcntl = ThreadIbcntl(); conf->async.iberr = ThreadIberr(); conf->async.ibsta = CMPL | ERR; } else { conf->async.ibcntl = count; conf->async.iberr = 0; conf->async.ibsta = CMPL; if (conf->end) conf->async.ibsta |= END; if (conf->timed_out) conf->async.ibsta |= TIMO; } pthread_mutex_unlock(&conf->async.lock); pthread_cleanup_pop(1); return NULL; } int gpib_aio_join(struct async_operation *async) { int retval; pthread_mutex_lock(&async->join_lock); retval = pthread_join(async->thread, NULL); pthread_mutex_unlock(&async->join_lock); switch(retval) { case 0: setAsyncIbsta(async->ibsta); setAsyncIberr(async->iberr); setAsyncIbcnt(async->ibcntl); break; case ESRCH: /* thread has already been joined */ retval = 0; break; default: fprintf(stderr, "libgpib: pthread_join() returned %i in %s\n", retval, __FUNCTION__); setIberr(EDVR); setIbcnt(retval); break; } return retval; } lib/globals.c000066400000000000000000000155641507046215500134330ustar00rootroot00000000000000/*************************************************************************** lib/globals.c ------------------- begin : Oct 2002 copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include volatile int iberr = 0; volatile int ibsta = 0; volatile int ibcnt = 0; volatile long ibcntl = 0; static pthread_key_t ibsta_key; static pthread_key_t iberr_key; static pthread_key_t ibcntl_key; static pthread_key_t async_ibsta_key; static pthread_key_t async_iberr_key; static pthread_key_t async_ibcntl_key; static pthread_once_t global_keys_once = PTHREAD_ONCE_INIT; static void global_keys_alloc() { int retval; retval = pthread_key_create(&ibsta_key, free); if (retval) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); retval = pthread_key_create(&iberr_key, free); if (retval ) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); retval = pthread_key_create(&ibcntl_key, free); if (retval) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); retval = pthread_key_create(&async_ibsta_key, free); if (retval) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); retval = pthread_key_create(&async_iberr_key, free); if (retval) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); retval = pthread_key_create(&async_ibcntl_key, free); if (retval) fprintf(stderr, "libgpib: failed to allocate TSD key!\n"); } void globals_alloc(void) { int *ibsta_p, *iberr_p, *ibcntl_p; int *async_ibsta_p, *async_iberr_p, *async_ibcntl_p; pthread_once(&global_keys_once, global_keys_alloc); if (pthread_getspecific(ibsta_key) == NULL) { ibsta_p = malloc(sizeof(int)); if (ibsta_p == NULL) fprintf(stderr, "libgpib: failed to allocate ibsta!\n"); iberr_p = malloc(sizeof(int)); if (iberr_p == NULL) fprintf(stderr, "libgpib: failed to allocate iberr!\n"); ibcntl_p = malloc(sizeof(long)); if (ibcntl_p == NULL) fprintf(stderr, "libgpib: failed to allocate ibcntl!\n"); async_ibsta_p = malloc(sizeof(int)); if (async_ibsta_p == NULL) fprintf(stderr, "libgpib: failed to allocate async_ibsta!\n"); async_iberr_p = malloc(sizeof(int)); if (async_iberr_p == NULL) fprintf(stderr, "libgpib: failed to allocate async_iberr!\n"); async_ibcntl_p = malloc(sizeof(long)); if (async_ibcntl_p == NULL) fprintf(stderr, "libgpib: failed to allocate async_ibcntl!\n"); *ibsta_p = 0; *iberr_p = 0; *ibcntl_p = 0; *async_ibsta_p = 0; *async_iberr_p = 0; *async_ibcntl_p = 0; pthread_setspecific(ibsta_key, ibsta_p); pthread_setspecific(iberr_key, iberr_p); pthread_setspecific(ibcntl_key, ibcntl_p); pthread_setspecific(async_ibsta_key, async_ibsta_p); pthread_setspecific(async_iberr_key, async_iberr_p); pthread_setspecific(async_ibcntl_key, async_ibcntl_p); } } void setIbsta(int status) { int *thread_ibsta; globals_alloc(); thread_ibsta = pthread_getspecific(ibsta_key); if (thread_ibsta == NULL) { fprintf(stderr, "libgpib: failed to set ibsta TSD\n"); return; } *thread_ibsta = status; } void setIberr(int error) { int *thread_iberr; globals_alloc(); thread_iberr = pthread_getspecific(iberr_key); if (thread_iberr == NULL) { fprintf(stderr, "libgpib: failed to set iberr TSD\n"); return; } *thread_iberr = error; } void setIbcnt(long count) { int *thread_ibcntl; globals_alloc(); thread_ibcntl = pthread_getspecific(ibcntl_key); if (thread_ibcntl == NULL) { fprintf(stderr, "libgpib: failed to set ibcntl TSD\n"); return; } *thread_ibcntl = count; } void setAsyncIbsta(int status) { int *async_thread_ibsta; globals_alloc(); async_thread_ibsta = pthread_getspecific(async_ibsta_key); if (async_thread_ibsta == NULL) { fprintf(stderr, "libgpib: failed to set async_ibsta TSD\n"); return; } *async_thread_ibsta = status; } void setAsyncIberr(int error) { int *async_thread_iberr; globals_alloc(); async_thread_iberr = pthread_getspecific(async_iberr_key); if (async_thread_iberr == NULL) { fprintf(stderr, "libgpib: failed to set async_iberr TSD\n"); return; } *async_thread_iberr = error; } void setAsyncIbcnt(long count) { int *async_thread_ibcntl; globals_alloc(); async_thread_ibcntl = pthread_getspecific(async_ibcntl_key); if (async_thread_ibcntl == NULL) { fprintf(stderr, "libgpib: failed to set async_ibcntl TSD\n"); return; } *async_thread_ibcntl = count; } int ThreadIbsta(void) { int *thread_ibsta; globals_alloc(); thread_ibsta = pthread_getspecific(ibsta_key); if (thread_ibsta == NULL) { fprintf(stderr, "libgpib: failed to get ibsta TSD\n"); return -1; } return *thread_ibsta; } int ThreadIberr(void) { int *thread_iberr; globals_alloc(); thread_iberr = pthread_getspecific(iberr_key); if (thread_iberr == NULL) { fprintf(stderr, "libgpib: failed to get iberr TSD\n"); return -1; } return *thread_iberr; } int ThreadIbcnt(void) { return ThreadIbcntl(); } long ThreadIbcntl(void) { int *thread_ibcntl; globals_alloc(); thread_ibcntl = pthread_getspecific(ibcntl_key); if (thread_ibcntl == NULL) { fprintf(stderr, "libgpib: failed to get ibcntl TSD\n"); return -1; } return *thread_ibcntl; } int AsyncIbsta(void) { int *async_thread_ibsta; globals_alloc(); async_thread_ibsta = pthread_getspecific(async_ibsta_key); if (async_thread_ibsta == NULL) { fprintf(stderr, "libgpib: failed to get async_ibsta TSD\n"); return -1; } return *async_thread_ibsta; } int AsyncIberr(void) { int *async_thread_iberr; globals_alloc(); async_thread_iberr = pthread_getspecific(async_iberr_key); if (async_thread_iberr == NULL) { fprintf(stderr, "libgpib: failed to get async_iberr TSD\n"); return -1; } return *async_thread_iberr; } int AsyncIbcnt(void) { return AsyncIbcntl(); } long AsyncIbcntl(void) { int *async_thread_ibcntl; globals_alloc(); async_thread_ibcntl = pthread_getspecific(async_ibcntl_key); if (async_thread_ibcntl == NULL) { fprintf(stderr, "libgpib: failed to get async_ibcntl TSD\n"); return -1; } return *async_thread_ibcntl; } void sync_globals(void) { ibsta = ThreadIbsta(); iberr = ThreadIberr(); ibcntl = ThreadIbcntl(); ibcnt = ibcntl; } lib/gpib_config/000077500000000000000000000000001507046215500140775ustar00rootroot00000000000000lib/gpib_config/Makefile.am000066400000000000000000000011231507046215500161300ustar00rootroot00000000000000# gpib_config/Makefile.am # copyright (C) 2003 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. sbin_PROGRAMS = gpib_config gpib_config_SOURCES = gpib_config.c gpib_config_CFLAGS = $(LIBGPIB_CFLAGS) -I$(top_srcdir)/lib -DDEFAULT_CONFIG_FILE="\"$(sysconfdir)/gpib.conf\"" gpib_config_LDADD = $(LIBGPIB_LDFLAGS) -lpthread lib/gpib_config/gpib_config.c000066400000000000000000000373101507046215500165150ustar00rootroot00000000000000/*************************************************************************** gpib_config.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include "ib_internal.h" typedef struct { char *config_file; char *device_file; unsigned int minor; char *board_type; int irq; unsigned long iobase; int dma; int pci_bus; int pci_slot; int pad; int sad; int assert_ifc; int assert_remote_enable; int offline; int is_system_controller; void *init_data; int init_data_length; char *sysfs_device_path; } parsed_options_t; static void help(void) { printf("gpib_config [options] - configures a GPIB interface board\n"); printf("\t-t, --board-type BOARD_TYPE\n" "\t\tSet board type to BOARD_TYPE.\n"); printf("\t-c, --device-file FILE_PATH\n" "\t\tSpecify character device file path for the board.\n" "\t\tThis can be used as an alternative to the --minor option.\n"); printf("\t-d, --dma NUM\n" "\t\tSpecify isa dma channel NUM for boards without plug-and-play cabability.\n"); printf("\t-I, --init-data FILE_PATH\n" "\t\tSpecify file containing binary initialization data (firmware) for board.\n"); printf("\t--[no-]ifc\n" "\t\tPerform (or not) interface clear after bringing board online. Default is --ifc.\n"); printf("\t-b, --iobase NUM\n" "\t\tSet io base address to NUM for boards without plug-and-play cabability.\n"); printf("\t-i, --irq NUM\n" "\t\tSpecify irq line NUM for boards without plug-and-play cabability.\n"); printf("\t-f, --file FILE_PATH\n" "\t\tSpecify file path for configuration file. The values in the configuration\n" "\t\tfile will be used as defaults for unspecified options. The default configuration\n" "\t\tfile is %s\n", DEFAULT_CONFIG_FILE); printf("\t-h, --help\n" "\t\tPrint this help and exit.\n"); printf("\t-m, --minor NUM\n" "\t\tConfigure gpib device file with minor number NUM (default 0).\n" "\t\tAlternatively, the device file may be specified with the --device-file option.\n"); printf("\t-o, --offline\n" "\t\tUnconfigure an already configured board, don't bring board online.\n"); printf("\t-p, --pad NUM\n" "\t\tSpecify primary gpib address. NUM should be in the range 0 through 30.\n"); printf("\t-u, --pci-bus NUM\n" "\t\tSpecify pci bus NUM to select a specific pci board.\n" "\t\tIf used, you must also specify the pci slot with --pci-slot.\n"); printf("\t-l, --pci-slot NUM\n" "\t\tSpecify pci slot NUM to select a specific pci board.\n" "\t\tIf used, you must also specify the pci bus with --pci-bus.\n"); printf("\t-s, --sad NUM\n" "\t\tSpecify secondary gpib address. NUM should be 0 (disabled) or in the range\n" "\t\t96 through 126 (0x60 through 0x7e hexadecimal).\n"); printf("\t--[no-]sre\n" "\t\tAssert (or not) remote enable line after bringing board online. Default is --sre.\n"); printf("\t-a, --sysfs-device-path DEVPATH\n" "\t\tSelect a specific board to attach by its sysfs device path.\n"); printf("\t--[no-]system-controller\n" "\t\tConfigure board as system controller (or not).\n"); printf("\t-v, --version\n" "\t\tPrint version of linux-gpib library and exit.\n"); } static int load_init_data(parsed_options_t *settings, const char *file_path) { int retval; FILE *init_file = fopen(file_path, "r"); if (init_file) { struct stat file_status; if (fstat(fileno(init_file), &file_status) == 0) { settings->init_data = malloc(file_status.st_size); if (settings->init_data) { settings->init_data_length = fread(settings->init_data, 1, file_status.st_size, init_file); if (settings->init_data_length == file_status.st_size) retval = 0; else { settings->init_data_length = 0; free(settings->init_data); settings->init_data = NULL; fprintf(stderr, "fread() returned short read\n"); retval = -EIO; } } else { fprintf(stderr, "malloc() failed.\n"); perror(__FUNCTION__); retval = -errno; } } else { fprintf(stderr, "fstat() failed on file \'%s\'.\n", file_path); perror(__FUNCTION__); retval = -errno; } } else { fprintf(stderr, "Failed to open file \'%s\' for reading.\n", file_path); perror(__FUNCTION__); retval = -errno; } fclose(init_file); return retval; } static int parse_options(int argc, char *argv[], parsed_options_t *settings) { int c, index; int retval; char *version; struct option options[] = { { "iobase", required_argument, NULL, 'b' }, { "device-file", required_argument, NULL, 'c' }, { "sysfs-device-path", required_argument, NULL, 'a' }, { "dma", required_argument, NULL, 'd' }, { "file", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "init-data", required_argument, NULL, 'I' }, { "irq", required_argument, NULL, 'i' }, { "pci-slot", required_argument, NULL, 'l' }, { "minor", required_argument, NULL, 'm' }, { "offline", no_argument, NULL, 'o' }, { "pad", required_argument, NULL, 'p' }, { "sad", required_argument, NULL, 's' }, { "board-type", required_argument, NULL, 't' }, { "pci-bus", required_argument, NULL, 'u' }, { "version", no_argument, NULL, 'v' }, { "no-ifc", no_argument, &settings->assert_ifc, 0 }, { "ifc", no_argument, &settings->assert_ifc, 1 }, { "no-sre", no_argument, &settings->assert_remote_enable, 0 }, { "sre", no_argument, &settings->assert_remote_enable, 1 }, { "no-system-controller", no_argument, &settings->is_system_controller, 0 }, { "system-controller", no_argument, &settings->is_system_controller, 1 }, { 0 }, }; memset(settings, 0, sizeof(parsed_options_t)); settings->irq = -1; settings->iobase = (unsigned long)-1; settings->dma = -1; settings->pci_bus = -1; settings->pci_slot = -1; settings->pad = -1; settings->sad = -1; settings->assert_ifc = 1; settings->assert_remote_enable = 1; settings->is_system_controller = -1; while (1) { c = getopt_long(argc, argv, "a:b:c:d:e:f:hi:I:l:m:op:s:t:u:v", options, &index); if (c == -1) break; switch(c) { case 0: break; case 'a': free(settings->sysfs_device_path); settings->sysfs_device_path = strdup(optarg); break; case 'b': settings->iobase = strtol(optarg, NULL, 0); break; case 'c' : free(settings->config_file); settings->device_file = strdup(optarg); break; case 'd': settings->dma = strtol(optarg, NULL, 0); break; case 'f': free(settings->config_file); settings->config_file = strdup(optarg); break; case 'h': help(); exit(0); break; case 'I': retval = load_init_data(settings, optarg); if (retval < 0) return retval; break; case 'i': settings->irq = strtol(optarg, NULL, 0); break; case 'l': settings->pci_slot = strtol(optarg, NULL, 0); break; case 'm': settings->minor = strtol(optarg, NULL, 0); break; case 'o': settings->offline = 1; break; case 'p': settings->pad = strtol(optarg, NULL, 0); break; case 's': settings->sad = strtol(optarg, NULL, 0); break; case 't': free(settings->board_type); settings->board_type = strdup(optarg); break; case 'u': settings->pci_bus = strtol(optarg, NULL, 0); break; case 'v': ibvers(&version); printf("linux-gpib version = %s\n",version); exit(0); break; default: help(); exit(1); } } if (settings->device_file) { struct stat file_stats; if (stat(settings->device_file, &file_stats) < 0) { fprintf(stderr, "Failed to get file information on file \"%s\".\n", settings->device_file); perror(__FUNCTION__); return -errno; } if (S_ISCHR(file_stats.st_mode) == 0) { fprintf(stderr, "The device file \"%s\" is not a character device.\n", settings->device_file); return -EINVAL; } settings->minor = minor(file_stats.st_rdev); } else { if (asprintf(&settings->device_file , "/dev/gpib%i", settings->minor) < 0) return -ENOMEM; } return 0; } static int configure_sysfs_device_path(int fileno, const char *sysfs_device_path) { struct gpib_select_device_path_ioctl devpath_selection; int retval; if (sysfs_device_path != NULL) { if (strlen(sysfs_device_path) >= sizeof(devpath_selection.device_path)) { fprintf(stderr, "device path too long.\n"); return -EINVAL; } strncpy(devpath_selection.device_path, sysfs_device_path, sizeof(devpath_selection.device_path)); } else { memset(devpath_selection.device_path, 0, sizeof(devpath_selection.device_path)); } retval = ioctl(fileno, IBSELECT_DEVICE_PATH, &devpath_selection); if (retval < 0) { /* If the user didn't request any device path, EINVAL error is probably just * due to using an older kernel module that doesn't support this ioctl. So * only error out if a path was specified. */ if (errno != EINVAL || strlen(devpath_selection.device_path) > 0) { fprintf(stderr, "failed to configure device path \"%s\"\n", devpath_selection.device_path); return retval; } } return 0; } static int configure_board(int fileno, const parsed_options_t *options) { struct gpib_board_type_ioctl boardtype; struct gpib_select_pci_ioctl pci_selection; struct gpib_pad_ioctl pad_cmd; struct gpib_sad_ioctl sad_cmd; struct gpib_online_ioctl online_cmd; int retval; online_cmd.online = 0; online_cmd.init_data_ptr = 0; online_cmd.init_data_length = 0; retval = ioctl(fileno, IBONL, &online_cmd); if (retval < 0) { fprintf(stderr, "failed to bring board offline\n"); return retval; } if (options->offline != 0) return 0; strncpy(boardtype.name, options->board_type, sizeof(boardtype.name) - 1); retval = ioctl(fileno, CFCBOARDTYPE, &boardtype); if (retval < 0) { fprintf(stderr, "failed to configure boardtype: %s\n", boardtype.name); return retval; } retval = ioctl(fileno, CFCBASE, &options->iobase); if (retval < 0) { fprintf(stderr, "failed to configure base address\n"); return retval; } retval = ioctl(fileno, CFCIRQ, &options->irq); if (retval < 0) { fprintf(stderr, "failed to configure irq\n"); return retval; } retval = ioctl(fileno, CFCDMA, &options->dma); if (retval < 0) { fprintf(stderr, "failed to configure dma channel\n"); return retval; } pad_cmd.handle = 0; pad_cmd.pad = options->pad; retval = ioctl(fileno, IBPAD, &pad_cmd); if (retval < 0) { fprintf(stderr, "failed to configure pad\n"); return retval; } sad_cmd.handle = 0; sad_cmd.sad = options->sad; retval = ioctl(fileno, IBSAD, &sad_cmd); if (retval < 0) { fprintf(stderr, "failed to configure sad\n"); return retval; } pci_selection.pci_bus = options->pci_bus; pci_selection.pci_slot = options->pci_slot; retval = ioctl(fileno, IBSELECT_PCI, &pci_selection); if (retval < 0) { fprintf(stderr, "failed to configure pci bus\n"); return retval; } configure_sysfs_device_path(fileno, options->sysfs_device_path); online_cmd.online = 1; assert(sizeof(options->init_data) <= sizeof(online_cmd.init_data_ptr)); online_cmd.init_data_ptr = (uintptr_t)options->init_data; online_cmd.init_data_length = options->init_data_length; retval = ioctl(fileno, IBONL, &online_cmd); if (retval < 0) { fprintf(stderr, "failed to bring board online\n"); return retval; } retval = ibconfig(options->minor, IbcSRE, options->assert_remote_enable); if (retval < 0) { fprintf(stderr, "ibconfig IbcSRE %d failed\n", options->assert_remote_enable); } retval = ibrsc(options->minor, options->is_system_controller); if (retval & ERR) { fprintf(stderr, "failed to request/release system control\n"); return -1; } if (options->is_system_controller) { if (options->assert_ifc) { retval = ibsic(options->minor); if (retval & ERR) { fprintf(stderr, "failed to assert interface clear\n"); return -1; } } } return 0; } int main(int argc, char *argv[]) { ibConf_t configs[FIND_CONFIGS_LENGTH]; ibBoard_t boards[GPIB_MAX_NUM_BOARDS]; char *filename, *envptr; int retval; parsed_options_t options; ibBoard_t *board; ibConf_t *conf = NULL; int i; retval = parse_options(argc, argv, &options); if (retval < 0) { fprintf(stderr, "failed to parse command line options."); return retval; }; envptr = getenv("IB_CONFIG"); if (options.config_file) filename = options.config_file; else if (envptr) filename = envptr; else filename = DEFAULT_CONFIG_FILE; if (options.minor >= GPIB_MAX_NUM_BOARDS) { fprintf(stderr, "minor number %i out of range\n", options.minor); return -1; } retval = parse_gpib_conf(filename, configs, FIND_CONFIGS_LENGTH, boards, GPIB_MAX_NUM_BOARDS, options.minor); if (retval < 0) { // Message printed in parser // fprintf(stderr, "failed to parse config file %s\n", filename); return retval; } for (i = 0;i < FIND_CONFIGS_LENGTH;i++) { if (configs[i].is_interface == 0) continue; if (configs[i].settings.board != options.minor) continue; conf = &configs[i]; break; } if (i == FIND_CONFIGS_LENGTH) { fprintf(stderr, "Could not find config for minor %d\n", options.minor); return -1; } board = &boards[options.minor]; if (options.board_type == NULL) { options.board_type = strdup(board->board_type); if (options.board_type == NULL) return -ENOMEM; } if ((strlen(options.board_type) == 0) && !options.offline) { fprintf(stderr, "No board type configured for minor %d\n", options.minor); return -1; } if (options.irq < 0) options.irq = board->irq; if (options.iobase == (unsigned long)-1) options.iobase = board->base; if (options.dma < 0) options.dma = board->dma; if (options.pci_bus < 0) options.pci_bus = board->pci_bus; if (options.pci_slot < 0) options.pci_slot = board->pci_slot; if (options.pad < 0) options.pad = conf->settings.pad; if (!options.offline && (options.pad < 0 || options.pad > 30)) { fprintf(stderr, "Invalid or no pad %d configured for minor %d\n", options.pad, options.minor); return -1; } if (options.sad == -1) { // not specified options.sad = conf->settings.sad; } else { if (options.sad != 0 && options.sad < 96 || options.sad > 127) { fprintf(stderr, "Invalid sad %d configured for minor %d\n", options.sad, options.minor); return -1; } if (options.sad == 0) options.sad = -1; else options.sad -= sad_offset; } if (options.is_system_controller < 0) options.is_system_controller = board->is_system_controller; board->fileno = open(options.device_file, O_RDWR); if (board->fileno < 0) { fprintf(stderr, "failed to open device file '%s'\n", options.device_file); perror(__FUNCTION__); return board->fileno; } if (options.sysfs_device_path == NULL) { if (strlen(board->sysfs_device_path) > 0) { options.sysfs_device_path = strdup(board->sysfs_device_path); if (options.sysfs_device_path == NULL) return -ENOMEM; } } retval = configure_board(board->fileno, &options); if (retval < 0) { fprintf(stderr, "failed to configure board\n"); perror(__FUNCTION__); return retval; } close(board->fileno); free(options.init_data); free(options.device_file); free(options.config_file); free(options.board_type); return 0; } lib/gpib_version_script000066400000000000000000000017731507046215500156360ustar00rootroot00000000000000 GPIB_DUMMY_VERSION { global: AllSPoll; AllSpoll; AsyncIbsta; AsyncIberr; AsyncIbcnt; AsyncIbcntl; DevClear; DevClearList; EnableLocal; EnableRemote; FindLstn; FindRQS; PassControl; PPoll; PPollConfig; PPollUnconfig; RcvRespMsg; ReadStatusByte; Receive; ReceiveSetup; ResetSys; Send; SendCmds; SendDataBytes; SendIFC; SendList; SendLLO; SendSetup; SetRWLS; TestSRQ; TestSys; ThreadIbsta; ThreadIberr; ThreadIbcnt; ThreadIbcntl; Trigger; TriggerList; WaitSRQ; ibask; ibbna; ibcac; ibclr; ibcmd; ibcmda; ibcnt; ibcntl; ibconfig; ibdev; ibdma; ibeos; ibeot; iberr; ibevent; ibfind; ibgts; ibist; iblines; ibln; ibloc; ibonl; ibpad; ibpct; ibppc; ibrd; ibrda; ibrdf; ibrpp; ibrsc; ibrsp; ibrsv; ibrsv2; ibsad; ibsic; ibspb; ibsre; ibsta; ibstop; ibtmo; ibtrg; ibvers; ibwait; ibwrt; ibwrta; ibwrtf; gpib_error_string; parse_gpib_conf; local: *; }; lib/ibBoard.c000066400000000000000000000077411507046215500133500ustar00rootroot00000000000000/*************************************************************************** lib/ibBoard.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include "ib_internal.h" #include #include #include #include #include #include #include #include #include ibBoard_t ibBoard[ GPIB_MAX_NUM_BOARDS ]; void init_ibboard(ibBoard_t *board) { strcpy(board->board_type, ""); board->base = 0; board->irq = 0; board->dma = 0; board->pci_bus = -1; board->pci_slot = -1; board->fileno = -1; strcpy(board->device, ""); board->open_count = 0; board->is_system_controller = 0; board->use_event_queue = 0; board->autospoll = 0; strcpy(board->sysfs_device_path, ""); strcpy(board->serial_number, ""); board->set_ren_on_sc = 1; } int configure_autospoll(ibConf_t *conf, int enable) { short spoll_enable = enable != 0; int retval = 0; ibBoard_t *board = interfaceBoard(conf); if ((spoll_enable && !board->autospoll) || (!spoll_enable && board->autospoll)) { retval = ioctl(interfaceBoard(conf)->fileno, IBAUTOSPOLL, &spoll_enable); if (retval) fprintf(stderr, "libgpib: autospoll ioctl returned error %i\n", retval); else board->autospoll = enable != 0; } return retval; } int ibBoardOpen(ibBoard_t *board, int error_msg_disable) { int fd; int flags = 0; if (board->fileno >= 0) return 0; if ((fd = open(board->device, O_RDWR | flags)) < 0) { setIberr(EDVR); setIbcnt(errno); if (!error_msg_disable) { fprintf(stderr, "libgpib: ibBoardOpen failed to open device file %s\n", board->device); perror("libgpib"); } return -1; } board->fileno = fd; board->open_count++; return 0; } int ibBoardClose(ibBoard_t *board) { if (board->open_count == 0) { fprintf(stderr, "libgpib: bug! board->open_count is zero on close\n"); return -1; } board->open_count--; if (board->open_count > 0) return 0; if (board->fileno >= 0) { close(board->fileno); board->fileno = -1; } return 0; } int InternalResetSys(ibConf_t *conf, const Addr4882_t addressList[]) { ibBoard_t *board; int retval; board = interfaceBoard(conf); if (addressListIsValid(addressList) == 0) { setIberr(EARG); return -1; } if (conf->is_interface == 0) { setIberr(EDVR); return -1; } retval = is_system_controller(board); if (retval <= 0) { if (retval == 0) setIberr(ESAC); return -1; } retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } retval = remote_enable(board, 1); if (retval < 0) return retval; retval = internal_ibsic(conf); if (retval < 0) return retval; retval = InternalDevClearList(conf, NULL); if (retval < 0) return retval; retval = InternalSendList(conf, addressList, "*RST", 4, NLend); if (retval < 0) return retval; return 0; } void ResetSys(int boardID, const Addr4882_t addressList[]) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (conf == NULL) { exit_library(boardID, 1); return; } retval = InternalResetSys(conf, addressList); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } lib/ibCac.c000066400000000000000000000033551507046215500130040ustar00rootroot00000000000000/*************************************************************************** lib/ibCac.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int ibcac(int ud, int synchronous) { ibConf_t *conf; ibBoard_t *board; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); if (conf->is_interface == 0) { setIberr(EARG); return exit_library(ud, 1); } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return exit_library(ud, 1); } retval = ioctl(board->fileno, IBCAC, &synchronous); // if synchronous failed, fall back to asynchronous if (retval < 0 && synchronous ) { synchronous = 0; retval = ioctl(board->fileno, IBCAC, &synchronous); } if (retval < 0) { switch (errno) { default: setIberr(EDVR); break; } return exit_library(ud, 1); } return exit_library(ud, 0); } lib/ibClr.c000066400000000000000000000054161507046215500130360ustar00rootroot00000000000000/*************************************************************************** lib/ibClr.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int ibclr(int ud) { uint8_t cmd[ 16 ]; ibConf_t *conf; ssize_t count; int i; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); if (conf->is_interface) { setIberr(EARG); return exit_library(ud, 1); } i = send_setup_string(conf, cmd); cmd[i++] = SDC; //XXX detect no listeners (EBUS) error count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); if (count != i) return exit_library(ud, 1); return exit_library(ud, 0); } int InternalDevClearList(ibConf_t *conf, const Addr4882_t addressList[]) { int i; ibBoard_t *board; uint8_t *cmd; int count; int retval; if (addressListIsValid(addressList) == 0) return -1; if (conf->is_interface == 0) { setIberr(EDVR); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } cmd = malloc(16 + 2 * numAddresses(addressList)); if (cmd == NULL) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } i = 0; if (numAddresses(addressList)) { i += create_send_setup(board, addressList, cmd); cmd[i++] = SDC; } else { cmd[ i++ ] = DCL; } //XXX detect no listeners (EBUS) error count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (count != i) return -1; return 0; } void DevClearList(int boardID, const Addr4882_t addressList[]) { int retval; ibConf_t *conf; conf = enter_library(boardID); if (conf == NULL) { exit_library(boardID, 1); return; } retval = InternalDevClearList(conf, addressList); if (retval < 0) exit_library(boardID, 1); exit_library(boardID, 0); } void DevClear(int boardID, Addr4882_t address) { Addr4882_t addressList[2]; addressList[0] = address; addressList[1] = NOADDR; DevClearList(boardID, addressList); } lib/ibCmd.c000066400000000000000000000140241507046215500130140ustar00rootroot00000000000000/*************************************************************************** lib/ibCmd.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include #include #include #include int ibcmd(int ud, const void *cmd_buffer, long cnt) { ibConf_t *conf; ssize_t count; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); // check that ud is an interface board if (conf->is_interface == 0) { setIberr(EARG); return exit_library(ud, 1); } count = my_ibcmd(conf, conf->settings.usec_timeout, cmd_buffer, cnt); if (count < 0) return exit_library(ud, 1); if (count != cnt) return exit_library(ud, 1); return exit_library(ud, 0); } int ibcmda(int ud, const void *cmd_buffer, long cnt) { ibConf_t *conf; ibBoard_t *board; int retval; conf = general_enter_library(ud, 1, 0); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); // check that ud is an interface board if (conf->is_interface == 0) { setIberr(EARG); return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } retval = gpib_aio_launch(ud, conf, GPIB_AIO_COMMAND, (void*)cmd_buffer, cnt); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } ssize_t my_ibcmd(ibConf_t *conf, unsigned int usec_timeout, const uint8_t *buffer, size_t count) { struct gpib_read_write_ioctl cmd; int retval; ibBoard_t *board; board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } assert(sizeof(buffer) <= sizeof(cmd.buffer_ptr)); cmd.buffer_ptr = (uintptr_t)buffer; cmd.requested_transfer_count = count; cmd.completed_transfer_count = 0; cmd.handle = conf->handle; /* set the suppress setting CMPL flag if an asyc read or write is in progress */ cmd.end = (conf->async.in_progress && (conf->async.aio_type == GPIB_AIO_READ || conf->async.aio_type == GPIB_AIO_WRITE)); set_timeout(board, usec_timeout); retval = ioctl(board->fileno, IBCMD, &cmd); if (retval < 0) { switch(errno) { case ETIMEDOUT: conf->timed_out = 1; setIberr(EBUS); break; case ENOTCONN: setIberr(ENOL); break; case EINTR: setIberr(EABO); break; default: setIberr(EDVR); setIbcnt(errno); break; } return -1; } return cmd.completed_transfer_count; } unsigned int create_send_setup(const ibBoard_t *board, const Addr4882_t addressList[], uint8_t *cmdString) { unsigned int i, j; unsigned int board_pad; int board_sad; if (addressList == NULL) { fprintf(stderr, "libgpib: bug! addressList NULL in create_send_setup()\n"); return 0; } if (addressListIsValid(addressList) == 0) { fprintf(stderr, "libgpib: bug! bad address list\n"); return 0; } i = 0; /* controller's talk address */ if (query_pad(board, &board_pad) < 0) return 0; cmdString[i++] = MTA(board_pad); if (query_sad(board, &board_sad) < 0) return 0; if (board_sad >= 0) cmdString[i++] = MSA(board_sad); cmdString[ i++ ] = UNL; for (j = 0; j < numAddresses(addressList); j++) { unsigned int pad; int sad; pad = extractPAD(addressList[ j ]); sad = extractSAD(addressList[ j ]); cmdString[ i++ ] = MLA(pad); if (sad >= 0) cmdString[ i++ ] = MSA(sad); } return i; } unsigned int send_setup_string(const ibConf_t *conf, uint8_t *cmdString) { ibBoard_t *board; Addr4882_t addressList[ 2 ]; board = interfaceBoard(conf); addressList[ 0 ] = packAddress(conf->settings.pad, conf->settings.sad); addressList[ 1 ] = NOADDR; return create_send_setup(board, addressList, cmdString); } int send_setup(ibConf_t *conf, unsigned int usec_timeout) { uint8_t cmdString[8]; int retval; retval = send_setup_string(conf, cmdString); if (my_ibcmd(conf, usec_timeout, cmdString, retval) < 0) return -1; return 0; } int InternalSendSetup(ibConf_t *conf, const Addr4882_t addressList[]) { int i; ibBoard_t *board; uint8_t *cmd; int count; int retval; if (addressListIsValid(addressList) == 0 || numAddresses(addressList) == 0) { setIberr(EARG); return -1; } if (conf->is_interface == 0) { setIberr(EDVR); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } cmd = malloc(16 + 2 * numAddresses(addressList)); if (cmd == NULL) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } i = create_send_setup(board, addressList, cmd); //XXX detect no listeners (EBUS) error count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (count != i) return -1; return 0; } void SendSetup(int boardID, const Addr4882_t addressList[]) { int retval; ibConf_t *conf; conf = enter_library(boardID); if (conf == NULL) { exit_library(boardID, 1); return; } retval = InternalSendSetup(conf, addressList); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } void SendCmds(int boardID, const void *buffer, long count) { ibcmd(boardID, buffer, count); } lib/ibConf.h000066400000000000000000000107131507046215500132040ustar00rootroot00000000000000/*************************************************************************** lib/ibConf.h ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _IBCONF_H #define _IBCONF_H #include #include #include /* meaning for flags */ #define CN_SDCL (1<<1) /* Send DCL on init */ #define CN_SLLO (1<<2) /* Send LLO on init */ #define CN_NETWORK (1<<3) /* is a network device */ #define CN_AUTOPOLL (1<<4) /* Auto serial poll devices */ #define CN_EXCLUSIVE (1<<5) /* Exclusive use only */ /*---------------------------------------------------------------------- */ struct async_operation { pthread_t thread; /* thread used for asynchronous io operations */ pthread_mutex_t lock; pthread_mutex_t join_lock; pthread_cond_t condition; uint8_t *buffer; volatile long buffer_length; volatile int iberr; volatile int ibsta; volatile long ibcntl; volatile short in_progress; volatile short aio_type; /* The type of aio in progress */ volatile short abort; }; typedef struct { int pad; /* device primary address */ int sad; /* device secodnary address (negative disables) */ int board; /* board index */ unsigned int usec_timeout; unsigned int spoll_usec_timeout; unsigned int ppoll_usec_timeout; char eos; /* eos character */ int eos_flags; int ppoll_config; /* current parallel poll configuration */ unsigned send_eoi : 1; /* assert EOI at end of writes */ unsigned local_lockout : 1; /* send local lockout when device is brought online */ unsigned readdr : 1; /* useless, exists for compatibility only at present */ unsigned send_unt_unl : 1; /* flag to send untalk unlisten after ibrd/ibwrt */ }descriptor_settings_t; typedef struct ibConfStruct { int handle; char name[100]; /* name of the device (for ibfind()) */ descriptor_settings_t defaults; /* initial settings stored so ibonl() can restore them */ descriptor_settings_t settings; /* various software settings for this descriptor */ char init_string[100]; /* initialization string (optional) */ int flags; /* some flags, deprecated */ struct async_operation async; /* used by asynchronous operations ibcmda(), ibrda(), etc. */ unsigned end : 1; /* EOI asserted or EOS received at end of IO operation */ unsigned is_interface : 1; /* is interface board */ unsigned board_is_open : 1; unsigned has_lock : 1; unsigned timed_out : 1; /* io operation timed out */ unsigned error_msg_disable : 1; /* flag to disable error messages in ibfind */ } ibConf_t; /*---------------------------------------------------------------------- */ typedef struct ibBoardStruct { char board_type[100]; /* name (model) of interface board */ unsigned long base; /* base configuration */ unsigned int irq; unsigned int dma; int pci_bus; int pci_slot; int fileno; /* device file descriptor */ unsigned int open_count; /* reference count */ unsigned is_system_controller : 1; /* board is busmaster or not */ unsigned use_event_queue : 1; /* use event queue, or DTAS/DCAS */ unsigned autospoll : 1; /* do auto serial polling */ char device[0x1000]; /* name of device file ( /dev/gpib0, etc.) */ char sysfs_device_path[0x1000]; /* sysfs device path, which may be used to select specific piece of hardware */ char serial_number[0x1000]; /* serial number, which may be used to select specific piece of hardware */ unsigned set_ren_on_sc : 1; /* enable REN when becoming system controlle */ } ibBoard_t; #endif /* _IBCONF_H */ lib/ibConfLex.l000066400000000000000000000105031507046215500136560ustar00rootroot00000000000000%option noyywrap %option nounput %option yylineno %option outfile="ibConfLex.c" header-file="ibConfLex.h" %option prefix="gpib_yy" %option reentrant %{ #define YYPARSE_PARAM parse_arg #include "ibConfYacc.h" #include "ib_internal.h" #include %} %x COMMENT %x STRING %% %{ %} \n "/*" { BEGIN(COMMENT); } [^*\n]* "*"+[^*/i\n]* "*"+"/" BEGIN(INITIAL); "//".*\n \" { BEGIN(STRING); } [^\"]*\" { if(strlen(gpib_yyget_text(yyscanner)) > 0) gpib_yyget_text(yyscanner)[strlen(gpib_yyget_text(yyscanner)) - 1] = 0; gpib_lvalp->sval = gpib_yyget_text(yyscanner); BEGIN(INITIAL); return ( T_STRING ); } interface { return (T_INTERFACE);} base { return (T_BASE);} irq { return (T_IRQ);} dma { return (T_DMA);} pci_bus { return (T_PCI_BUS);} pci_slot { return (T_PCI_SLOT);} device { return(T_DEVICE);} name { return (T_NAME);} board_type { return (T_BOARD_TYPE);} minor { return (T_MINOR);} sysfs_device_path { return (T_SYSFS_DEVICE_PATH);} serial_number { return (T_SERIAL_NUMBER);} pad { return(T_PAD);} sad { return(T_SAD);} eos { return(T_EOSBYTE);} timeout | timo { return(T_TIMO);} set-reos { return T_REOS;} set-bin { return T_BIN; } set-xeos { return T_XEOS; } set-eot { return T_EOT; } init-string { printf( "init-string deprecated\n" ); return T_INIT_S; } init-flags { printf( "init-flags deprecated\n" ); return T_INIT_F; } set-clear { printf( "set-clear deprecated\n" ); return T_DCL; } LLO { return T_LLO; } DCL { return T_DCL; } EXCL { return T_EXCL;} controller | master { return T_MASTER; } autopoll { return T_AUTOPOLL; } yes { gpib_lvalp->bval=1; return(T_BOOL);} no { gpib_lvalp->bval=0; return(T_BOOL);} none { gpib_lvalp->ival=0 ; return(T_TIVAL);} 10us { gpib_lvalp->ival=10; return(T_TIVAL);} 30us { gpib_lvalp->ival=30; return(T_TIVAL);} 100us { gpib_lvalp->ival=100; return(T_TIVAL);} 300us { gpib_lvalp->ival=300; return(T_TIVAL);} 1ms { gpib_lvalp->ival=1000; return(T_TIVAL);} 3ms { gpib_lvalp->ival=3000; return(T_TIVAL);} 10ms { gpib_lvalp->ival=10000; return(T_TIVAL);} 30ms { gpib_lvalp->ival=30000; return(T_TIVAL);} 100ms { gpib_lvalp->ival=100000; return(T_TIVAL);} 300ms { gpib_lvalp->ival=300000; return(T_TIVAL);} 1s { gpib_lvalp->ival=1000000; return(T_TIVAL);} 3s { gpib_lvalp->ival=3000000; return(T_TIVAL);} 10s { gpib_lvalp->ival=1000000; return(T_TIVAL);} 30s { gpib_lvalp->ival=30000000; return(T_TIVAL);} 100s { gpib_lvalp->ival=100000000; return(T_TIVAL);} 300s { gpib_lvalp->ival=300000000; return(T_TIVAL);} 1000s { gpib_lvalp->ival=1000000000; return(T_TIVAL);} TNONE { gpib_lvalp->ival=TNONE ; return(T_NUMBER);} T10us { gpib_lvalp->ival=T10us; return(T_NUMBER);} T30us { gpib_lvalp->ival=T30us; return(T_NUMBER);} T100us { gpib_lvalp->ival=T100us; return(T_NUMBER);} T300us { gpib_lvalp->ival=T300us; return(T_NUMBER);} T1ms { gpib_lvalp->ival=T1ms; return(T_NUMBER);} T3ms { gpib_lvalp->ival=T3ms; return(T_NUMBER);} T10ms { gpib_lvalp->ival=T10ms; return(T_NUMBER);} T30ms { gpib_lvalp->ival=T30ms; return(T_NUMBER);} T100ms { gpib_lvalp->ival=T100ms; return(T_NUMBER);} T300ms { gpib_lvalp->ival=T300ms; return(T_NUMBER);} T1s { gpib_lvalp->ival=T1s; return(T_NUMBER);} T3s { gpib_lvalp->ival=T3s; return(T_NUMBER);} T10s { gpib_lvalp->ival=T10s; return(T_NUMBER);} T30s { gpib_lvalp->ival=T30s; return(T_NUMBER);} T100s { gpib_lvalp->ival=T100s; return(T_NUMBER);} T300s { gpib_lvalp->ival=T300s; return(T_NUMBER);} T1000s { gpib_lvalp->ival=T1000s; return(T_NUMBER);} 0[xX][0-9a-fA-F]+ { gpib_lvalp->ival = strtol(gpib_yyget_text(yyscanner), NULL, 0); return( T_NUMBER ); } (00)?[0-9]+ { gpib_lvalp->ival = strtol(gpib_yyget_text(yyscanner), NULL, 0 ); return( T_NUMBER ); } [ \t] [a-zA-Z0-9_\-]+ { gpib_lvalp->sval = gpib_yyget_text(yyscanner); /* printf("bare string <%s> should be enclosed in double-quotes\n", gpib_yytext); */ return (T_STRING); } . { return( gpib_yyget_text(yyscanner)[0] ); } %% lib/ibConfYacc.y000066400000000000000000000275501507046215500140340ustar00rootroot00000000000000%{ #include #include "ib_internal.h" #undef EXTERN #include "ibP.h" #include #include #include "ibConfYacc.h" #include "ibConfLex.h" #define YYERROR_VERBOSE void yyerror(const YYLTYPE *a, void *b, void *c, const char *s) { fprintf(stderr, "%s\n", s); } YY_DECL; typedef struct { yyscan_t yyscanner; ibConf_t *configs; unsigned int configs_length; unsigned int config_index; ibBoard_t *boards; unsigned int boards_length; int board_index; int *device_line_numbers; const char *config_file; }gpib_yyparse_private_t; static inline gpib_yyparse_private_t* priv(gpib_yyparse_private_t *parse_arg) { return parse_arg; } static inline ibConf_t* current_config(gpib_yyparse_private_t *parse_arg) { return &parse_arg->configs[ parse_arg->config_index ]; } static inline ibBoard_t* current_board(gpib_yyparse_private_t *parse_arg) { if (parse_arg->board_index < 0) return NULL; return &parse_arg->boards[ parse_arg->board_index ]; } void init_gpib_yyparse_private(gpib_yyparse_private_t *priv) { priv->yyscanner = 0; priv->configs = NULL; priv->configs_length = 0; priv->config_index = 0; priv->boards = NULL; priv->boards_length = 0; priv->board_index = -1; priv->device_line_numbers = NULL; priv->config_file = NULL; } static int find_board_config(gpib_yyparse_private_t *priv, int board_index) { int i; for(i = 0; i < priv->configs_length && priv->configs[ i ].defaults.board >= 0; i++) { if (priv->configs[ i ].defaults.board == board_index && priv->configs[ i ].is_interface) return i; } return -1; } int parse_gpib_conf(const char *filename, ibConf_t *configs, unsigned int configs_length, ibBoard_t *boards, unsigned int boards_length, int minor) { FILE *infile; int retval = 0; int i,j; gpib_yyparse_private_t priv; int device_line_nos[configs_length]; if ((infile = fopen(filename, "r")) == NULL) { fprintf(stderr, "failed to open configuration file %s\n", filename); setIberr(EDVR); setIbcnt(errno); return -1; } init_gpib_yyparse_private(&priv); priv.configs = configs; priv.configs_length = configs_length; priv.boards = boards; priv.boards_length = boards_length; priv.device_line_numbers = device_line_nos; priv.config_file = filename; for (i=0;i < priv.configs_length;i++) { init_ibconf(&priv.configs[i]); priv.device_line_numbers[i] = 0; } for (i=0;i < priv.boards_length;i++) init_ibboard(&priv.boards[i]); gpib_yylex_init(&priv.yyscanner); gpib_yyrestart(infile, priv.yyscanner); if (gpib_yyparse(&priv, priv.yyscanner)) goto gpib_parse_fail; gpib_yylex_destroy(priv.yyscanner); fclose(infile); if (retval == 0) { for (i=0;i= 0 && find_board_config(&priv,minor) < 0) { // No entry for minor in config file // make one so that udev scripts need not depend on config file i = priv.config_index; priv.configs[i].defaults.board = minor; priv.configs[i].is_interface = 1; snprintf(priv.boards[minor].device, sizeof(priv.boards[minor].device), "/dev/gpib%i", minor); priv.configs[i].settings = priv.configs[i].defaults; } } return retval; gpib_parse_fail: fprintf(stderr, "libgpib: failed to parse configuration file %s\n", filename); return -1; } static void gpib_conf_warn_missing_equals() { fprintf(stderr, "WARNING: omitting \"=\" before a boolean value in gpib config file is deprecated.\n"); } %} %locations %define api.pure full %parse-param {void *parse_arg} %parse-param {void* yyscanner} %lex-param {void* yyscanner} %union { int ival; char *sval; char bval; char cval; } %token T_INTERFACE T_DEVICE T_NAME T_MINOR T_BASE T_IRQ T_DMA %token T_PAD T_SAD T_TIMO T_EOSBYTE T_BOARD_TYPE T_PCI_BUS T_PCI_SLOT %token T_REOS T_BIN T_INIT_S T_DCL T_XEOS T_EOT %token T_MASTER T_LLO T_EXCL T_INIT_F T_AUTOPOLL %token T_SYSFS_DEVICE_PATH T_SERIAL_NUMBER %token T_NUMBER T_STRING T_BOOL T_TIVAL %type T_NUMBER %type T_TIVAL %type T_STRING %type T_BOOL %% input: /* empty */ | device input | interface input | error { fprintf(stderr, "input error on line %i of %s\n", gpib_yyget_lineno(priv(parse_arg)->yyscanner), priv(parse_arg)->config_file); YYABORT; } ; interface: T_INTERFACE '{' minor parameter '}' { current_config(parse_arg)->is_interface = 1; if (++(priv(parse_arg)->config_index) >= priv(parse_arg)->configs_length) { fprintf(stderr, "too many devices in config file\n"); YYERROR; } } ; minor : T_MINOR '=' T_NUMBER { int bi = $3; if (bi >= 0 && bi < priv(parse_arg)->boards_length) { priv(parse_arg)->board_index = bi; if (strlen(current_board(parse_arg)->device) != 0) { fprintf(stderr, "Duplicate interface minor %d\n", bi); YYERROR; } current_config(parse_arg)->defaults.board = bi; snprintf(current_board(parse_arg)->device, sizeof(current_board(parse_arg)->device), "/dev/gpib%i", bi); } else { fprintf(stderr, "Invalid minor %d\n", bi); YYERROR; } } ; parameter: /* empty */ | statement parameter | error { fprintf(stderr, "parameter error on line %i of %s\n",gpib_yyget_lineno(priv(parse_arg)->yyscanner)-1, priv(parse_arg)->config_file); YYABORT; } ; statement: T_PAD '=' T_NUMBER { int pad = $3; if (pad < 0 || pad > gpib_addr_max) { fprintf(stderr, "Invalid pad %d on line %i in %s\n", pad, gpib_yyget_lineno(priv(parse_arg)->yyscanner), priv(parse_arg)->config_file); YYABORT; } current_config(parse_arg)->defaults.pad = pad; } | T_SAD '=' T_NUMBER { int sad = $3; if (!sad) sad = -1; else sad -= sad_offset; if (sad < -1 || sad > gpib_sad_max) { fprintf(stderr,"Invalid sad %d on line %i in %s\n", $3, gpib_yyget_lineno(priv(parse_arg)->yyscanner), priv(parse_arg)->config_file); YYABORT; } current_config(parse_arg)->defaults.sad = sad; } | T_EOSBYTE '=' T_NUMBER { current_config(parse_arg)->defaults.eos = $3;} | T_REOS T_BOOL { gpib_conf_warn_missing_equals(); current_config(parse_arg)->defaults.eos_flags |= $2 * REOS;} | T_BIN T_BOOL { gpib_conf_warn_missing_equals(); current_config(parse_arg)->defaults.eos_flags |= $2 * BIN;} | T_REOS '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * REOS;} | T_XEOS '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * XEOS;} | T_BIN '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * BIN;} | T_EOT '=' T_BOOL { current_config(parse_arg)->defaults.send_eoi = $3;} | T_TIMO '=' T_TIVAL { current_config(parse_arg)->defaults.usec_timeout = $3; } | T_TIMO '=' T_NUMBER { current_config(parse_arg)->defaults.usec_timeout = timeout_to_usec($3); } | T_BASE '=' T_NUMBER { current_board(parse_arg)->base = $3; } | T_IRQ '=' T_NUMBER { current_board(parse_arg)->irq = $3; } | T_DMA '=' T_NUMBER { current_board(parse_arg)->dma = $3; } | T_PCI_BUS '=' T_NUMBER { current_board(parse_arg)->pci_bus = $3; } | T_PCI_SLOT '=' T_NUMBER { current_board(parse_arg)->pci_slot = $3; } | T_MASTER T_BOOL { gpib_conf_warn_missing_equals(); current_board(parse_arg)->is_system_controller = $2; } | T_MASTER '=' T_BOOL { current_board(parse_arg)->is_system_controller = $3; } | T_BOARD_TYPE '=' T_STRING { strncpy(current_board(parse_arg)->board_type, $3, sizeof(current_board(parse_arg)->board_type)-1); } | T_NAME '=' T_STRING { strncpy(current_config(parse_arg)->name, $3, sizeof(current_config(parse_arg)->name)-1); } | T_SYSFS_DEVICE_PATH '=' T_STRING { strncpy(current_board(parse_arg)->sysfs_device_path, $3, sizeof(current_board(parse_arg)->sysfs_device_path)-1); } | T_SERIAL_NUMBER '=' T_STRING { strncpy(current_board(parse_arg)->serial_number, $3, sizeof(current_board(parse_arg)->serial_number-1)); } ; device: T_DEVICE '{' option '}' { current_config(parse_arg)->is_interface = 0; priv(parse_arg)->device_line_numbers[priv(parse_arg)->config_index] = gpib_yyget_lineno(priv(parse_arg)->yyscanner); if (++(priv(parse_arg)->config_index) >= priv(parse_arg)->configs_length) { fprintf(stderr, "too many devices in config file\n"); YYERROR; } } ; option: /* empty */ | assign option | error { int mline = gpib_yyget_lineno(priv(parse_arg)->yyscanner); fprintf(stderr, "option error on line %i of config file\n", mline); YYABORT; } ; assign: T_PAD '=' T_NUMBER { int pad = $3; if (pad < 0 || pad > gpib_addr_max) { fprintf(stderr, "Invalid pad %d on line %i in %s\n", pad, gpib_yyget_lineno(priv(parse_arg)->yyscanner), priv(parse_arg)->config_file); YYABORT; } current_config(parse_arg)->defaults.pad = pad; } | T_SAD '=' T_NUMBER { int sad = $3; if (!sad) sad = -1; else sad -= sad_offset; if (sad < -1 || sad > gpib_sad_max) { fprintf(stderr, "Invalid sad %d on line %i in %s\n", $3, gpib_yyget_lineno(priv(parse_arg)->yyscanner), priv(parse_arg)->config_file); YYABORT; } current_config(parse_arg)->defaults.sad = sad; } | T_INIT_S '=' T_STRING { strncpy(current_config(parse_arg)->init_string,$3,60); } | T_EOSBYTE '=' T_NUMBER { current_config(parse_arg)->defaults.eos = $3; } | T_REOS T_BOOL { gpib_conf_warn_missing_equals(); current_config(parse_arg)->defaults.eos_flags |= $2 * REOS;} | T_REOS '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * REOS;} | T_XEOS '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * XEOS;} | T_BIN T_BOOL { gpib_conf_warn_missing_equals(); current_config(parse_arg)->defaults.eos_flags |= $2 * BIN; } | T_BIN '=' T_BOOL { current_config(parse_arg)->defaults.eos_flags |= $3 * BIN; } | T_EOT '=' T_BOOL { current_config(parse_arg)->defaults.send_eoi = $3;} | T_AUTOPOLL { current_config(parse_arg)->flags |= CN_AUTOPOLL; } | T_INIT_F '=' flags | T_NAME '=' T_STRING { strncpy(current_config(parse_arg)->name,$3, sizeof(current_config(parse_arg)->name));} | T_MINOR '=' T_NUMBER { current_config(parse_arg)->defaults.board = $3;} | T_TIMO '=' T_TIVAL { current_config(parse_arg)->defaults.usec_timeout = $3; } | T_TIMO '=' T_NUMBER { current_config(parse_arg)->defaults.usec_timeout = timeout_to_usec($3); } ; flags: /* empty */ | ',' flags | oneflag flags ; oneflag: T_LLO { current_config(parse_arg)->flags |= CN_SLLO; } | T_DCL { current_config(parse_arg)->flags |= CN_SDCL; } | T_EXCL { current_config(parse_arg)->flags |= CN_EXCLUSIVE; } ; %% lib/ibDma.c000066400000000000000000000023101507046215500130050ustar00rootroot00000000000000/*************************************************************************** lib/ibDma.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int ibdma(int ud, int v) { ibConf_t *conf; conf = enter_library(ud); if (!conf) return exit_library( ud, 1 ); fprintf( stderr, "libgpib: ibdma() unimplemented!\n" ); return exit_library( ud, 0 ); } /* ibdma */ lib/ibEos.c000066400000000000000000000042301507046215500130350ustar00rootroot00000000000000/*************************************************************************** lib/ibEos.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int ibeos(int ud, int v) { ibConf_t *conf; conf = general_enter_library(ud, 1, 0); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); conf->settings.eos = v & 0xff; conf->settings.eos_flags = v & 0xff00; return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } int iblcleos(const ibConf_t *conf) { int use_eos, compare8; use_eos = conf->settings.eos_flags & REOS; compare8 = conf->settings.eos_flags & BIN; return config_read_eos(interfaceBoard(conf), use_eos, conf->settings.eos, compare8) ; } int config_read_eos(ibBoard_t *board, int use_eos_char, int eos_char, int compare_8_bits) { struct gpib_eos_ioctl eos_cmd; int retval; eos_cmd.eos_flags = 0; if (use_eos_char) eos_cmd.eos_flags |= REOS; if (compare_8_bits) eos_cmd.eos_flags |= BIN; eos_cmd.eos = 0; if (use_eos_char) { eos_cmd.eos = eos_char; eos_cmd.eos &= 0xff; if (eos_cmd.eos != eos_char) { setIberr(EARG); fprintf(stderr, "libgpib: eos char more than 8 bits?\n"); return -1; } } retval = ioctl(board->fileno, IBEOS, &eos_cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); fprintf(stderr, "libgpib: IBEOS ioctl failed\n"); } return retval; } lib/ibEot.c000066400000000000000000000026201507046215500130370ustar00rootroot00000000000000/*************************************************************************** lib/ibEot.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include void internal_ibeot(ibConf_t *conf, int send_eoi) { if(send_eoi) conf->settings.send_eoi = 1; else conf->settings.send_eoi = 0; } int ibeot(int ud, int send_eoi) { ibConf_t *conf; conf = general_enter_library( ud, 1, 0 ); if (!conf) return general_exit_library( ud, 1, 0, 0, 0, 0, 1 ); internal_ibeot( conf, send_eoi ); return general_exit_library( ud, 0, 0, 0, 0, 0, 1 ); } lib/ibError.c000066400000000000000000000104451507046215500134050ustar00rootroot00000000000000/*************************************************************************** lib/ibError.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include #include #include char *routptr[]= { "ibrd", "ibwrt", "ibcmd", "ibwait", "ibrpp", "ibonl", "ibsic", "ibsre", "ibgts", "ibcac", "ibpoke", "iblines", "ibpad", "ibsad", "ibtmo", "ibeot", "ibeos", "ibrsv", /*17*/ "dvtrg", "dvclr", "dvrsp", "dvrd", "dvwrt", /*22*/ "cfcbase", "cfcirq", "cfcdma", /*25*/ "unknown" }; char *ibVerbCode(int code) { if (code >=0 && code <=17) return routptr[code]; else if (code >=100 && code <=104) return routptr[18+(code-100)]; else if (code >=200 && code <=202) return routptr[23+(code-200)]; else return routptr[26]; } void ibPutMsg (char *format,...) { va_list ap; time_t tm; char strtime[60]; va_start(ap,format); time(&tm); strftime(strtime,59,"%c",gmtime(&tm)); fprintf(stderr,"\n gpib-message :[%s] ",strtime); vfprintf(stderr, format, ap); va_end(ap); } void ibPutErrlog(int ud,char *routine) { time_t tm; char strtime[60]; if (ibsta & ERR) { time(&tm); strftime(strtime,59,"%c",gmtime(&tm)); if (ud>=0) fprintf(stderr, "\n %-15s:[%s](%s)< ",routine,strtime, ibConfigs[ud]->name); else fprintf(stderr, "\n %-15s:[%s](-)< " ,routine,strtime); if (ibsta & ERR) fprintf(stderr," ERR"); if (ibsta & TIMO) fprintf(stderr," TIMO"); if (ibsta & END) fprintf(stderr," END"); if (ibsta & SRQI) fprintf(stderr," SRQI"); /*if (ibsta & RQS) fprintf(stderr," RQS");*/ if (ibsta & CMPL) fprintf(stderr," CMPL"); /*if (ibsta & LOK) fprintf(stderr," LOK");*/ /*if (ibsta & REM) fprintf(stderr," REM");*/ if (ibsta & CIC) fprintf(stderr," CIC"); if (ibsta & ATN) fprintf(stderr," ATN"); if (ibsta & TACS) fprintf(stderr," TACS"); if (ibsta & LACS) fprintf(stderr," LACS"); /*if (ibsta & DTAS) fprintf(stderr," DATS");*/ /*if (ibsta & DCAS) fprintf(stderr," DCTS");*/ fprintf(stderr,"> "); if (iberr == EDVR) fprintf(stderr," EDVR \n"); if (iberr == ECIC) fprintf(stderr," ECIC \n"); if (iberr == ENOL) fprintf(stderr," ENOL \n"); if (iberr == EADR) fprintf(stderr," EADR \n"); if (iberr == EARG) fprintf(stderr," ECIC \n"); if (iberr == ESAC) fprintf(stderr," ESAC \n"); if (iberr == EABO) fprintf(stderr," EABO \n"); if (iberr == ENEB) fprintf(stderr," ENEB \n"); if (iberr == EOIP) fprintf(stderr," EOIP \n"); if (iberr == ECAP) fprintf(stderr," ECAP \n"); if (iberr == EFSO) fprintf(stderr," EFSO \n"); if (iberr == EBUS) fprintf(stderr," EBUS \n"); if (iberr == ESTB) fprintf(stderr," ESTB \n"); if (iberr == ESRQ) fprintf(stderr," ESRQ \n"); if (iberr == ECNF) fprintf(stderr," ECNF \n"); if (iberr == ETAB) fprintf(stderr," ETAB \n"); if (iberr == EDVR && ibcnt != 0) { fprintf(stderr," -- errno=%d (%s)\n",ibcnt,strerror(ibcnt)); } } } lib/ibEvent.c000066400000000000000000000032551507046215500133760ustar00rootroot00000000000000/*************************************************************************** lib/ibEvent.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int ibevent(int ud, short *event) { ibConf_t *conf; ibBoard_t *board; int retval; short user_event; conf = general_enter_library(ud, 1, 1); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); if (conf->is_interface == 0) { setIberr(EARG); return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } board = interfaceBoard(conf); retval = ioctl(board->fileno, IBEVENT, &user_event); if (retval < 0) { switch(errno) { case EPIPE: setIberr(ETAB); break; default: setIberr(EDVR); setIbcnt(errno); break; } return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } *event = user_event; return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } lib/ibFind.c000066400000000000000000000037451507046215500132010ustar00rootroot00000000000000/*************************************************************************** lib/ibFind.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include int ibfind(const char *dev) { int index; int retval; int ud; ibConf_t *conf; int status; retval = ibParseConfigFile(-1); if (retval < 0) { if (errno) { setIbcnt(errno); setIberr(EDVR); } else { setIberr(ECNF); } setIbsta(ERR); sync_globals(); return -1; } if ((index = ibFindDevIndex(dev)) < 0) { /* find desired entry */ setIberr(EARG); setIbsta(ERR); sync_globals(); return -1; } conf = &ibFindConfigs[ index ]; if (getenv("IB_NO_ERROR")) conf->error_msg_disable = 1; ud = my_ibdev(*conf); if (ud < 0) { if (!conf->error_msg_disable) fprintf(stderr, "libgpib: ibfind failed to get descriptor\n"); return -1; } conf = general_enter_library(ud, 1, 0); if (conf->flags & CN_SDCL) { status = ibclr(ud); if (status & ERR) return -1; } if (strcmp(conf->init_string, "")) { status = ibwrt(ud, conf->init_string, strlen(conf->init_string)); if (status & ERR) return -1; } return ud; } lib/ibFindLstn.c000066400000000000000000000137611507046215500140410ustar00rootroot00000000000000/*************************************************************************** lib/ibFindLstn.c ------------------- copyright : (C) 2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #include /* Strictly speaking, addressing the controller as talker is * not part of the FindListener 488.2 protocol. However, doing * so helps with boards that cannot reliably read the state of * the NDAC line due to their transceivers. Such boards can * only read the state of NDAC (and NRFD and SRQ) when the * transceiver has the line configured as an input. Addressing * the board as talker insures NDAC (and NRFD) will be inputs * while the FindListener protocol is running. */ int address_board_as_talker(ibConf_t *conf) { uint8_t cmd[2]; int j; unsigned int board_pad; int board_sad; ibBoard_t *board; board = interfaceBoard(conf); j = 0; /* controller's talk address */ if (query_pad(board, &board_pad) < 0) return 0; cmd[j++] = MTA(board_pad); if (query_sad(board, &board_sad) < 0) return 0; if (board_sad >= 0) cmd[j++] = MSA(board_sad); return my_ibcmd(conf, conf->settings.usec_timeout, cmd, j); } int unlisten_untalk(ibConf_t *conf) { uint8_t cmd[2]; int j; j = 0; cmd[j++] = UNL; cmd[j++] = UNT; return my_ibcmd(conf, conf->settings.usec_timeout, cmd, j); } int listenerFound(ibConf_t *conf, const Addr4882_t addressList[]) { uint8_t *cmd; int i, j; short line_status; int retval; if (addressList == NULL) return 0; if (addressListIsValid(addressList) == 0) return -1; cmd = malloc(16 + 2 * numAddresses(addressList)); if (cmd == NULL) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } j = 0; cmd[j++] = UNL; for (i = 0; i < numAddresses(addressList); i++) { int pad, sad; pad = extractPAD(addressList[i]); sad = extractSAD(addressList[i]); cmd[j++] = MLA(pad); if (sad >= 0) cmd[j++] = MSA(sad); } retval = my_ibcmd(conf, conf->settings.usec_timeout, cmd, j); free(cmd); cmd = NULL; if (retval < 0) return retval; retval = internal_ibgts(conf, 0); if (retval < 0) return -1; usleep(1500); retval = internal_iblines(conf, &line_status); if (retval < 0) return retval; if (((line_status & ValidNRFD) && (line_status & BusNRFD)) || ((line_status & ValidNDAC) && (line_status & BusNDAC))) return 1; return 0; } int secondaryListenerFound(ibConf_t *conf, unsigned int pad) { Addr4882_t testAddress[32]; int j; for (j = 0; j <= gpib_addr_max; j++) testAddress[j] = packAddress(pad, j); testAddress[j] = NOADDR; return listenerFound(conf, testAddress); } void FindLstn(int boardID, const Addr4882_t padList[], Addr4882_t resultList[], int maxNumResults) { int i; ibConf_t *conf; int retval; int resultIndex; short line_status; conf = enter_library(boardID); if (conf == NULL) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } retval = internal_iblines(conf, &line_status); if (retval < 0) { exit_library(boardID, 1); return; } if ((line_status & ValidNDAC) == 0) { setIberr(ECAP); exit_library(boardID, 1); return; } retval = address_board_as_talker(conf); if (retval < 0) { exit_library(boardID, 1); return; } resultIndex = 0; for (i = 0; i < numAddresses(padList); i++) { Addr4882_t pad; Addr4882_t testAddress[2]; pad = GetPAD(padList[i]); testAddress[0] = pad; testAddress[1] = NOADDR; retval = listenerFound(conf, testAddress); if (retval < 0) { // XXX status/error settings exit_library(boardID, 1); return; } if (retval > 0) { if (resultIndex >= maxNumResults) { setIberr(ETAB); exit_library(boardID, 1); return; } resultList[resultIndex++] = testAddress[0]; setIbcnt(resultIndex); } else { retval = secondaryListenerFound(conf, pad); if (retval < 0) { exit_library(boardID, 1); return; } if (retval > 0) { int j; for (j = 0; j <= gpib_addr_max; j++) { testAddress[0] = packAddress(pad, j); testAddress[1] = NOADDR; retval = listenerFound(conf, testAddress); if (retval < 0) { exit_library(boardID, 1); return; } if (retval > 1) { if (resultIndex >= maxNumResults) { setIberr(ETAB); exit_library(boardID, 1); return; } resultList[resultIndex++] = testAddress[0]; setIbcnt(resultIndex); } } } } } retval = unlisten_untalk(conf); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } /* FindLstn */ int ibln(int ud, int pad, int sad, short *found_listener) { ibConf_t *conf; Addr4882_t addressList[2]; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = address_board_as_talker(conf); if (retval < 0) { return exit_library(ud, 1); } switch(sad) { case ALL_SAD: retval = secondaryListenerFound(conf, pad); break; case NO_SAD: default: addressList[0] = MakeAddr(pad, sad); addressList[1] = NOADDR; retval = listenerFound(conf, addressList); break; } if (retval < 0) return exit_library(ud, 1); *found_listener = retval; retval = unlisten_untalk(conf); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibGts.c000066400000000000000000000033711507046215500130510ustar00rootroot00000000000000/*************************************************************************** lib/ibGts.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibgts(ibConf_t *conf, int shadow_handshake) { ibBoard_t *board; int retval; board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } retval = ioctl(board->fileno, IBGTS, &shadow_handshake); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } return 0; } // incomplete XXX need to implement acceptor handshake stuff in drivers int ibgts(int ud, int v) { ibConf_t *conf; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); if (conf->is_interface == 0) { setIberr(EARG); return exit_library(ud, 1); } retval = internal_ibgts(conf, v); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibLines.c000066400000000000000000000044541507046215500133710ustar00rootroot00000000000000/*************************************************************************** lib/ibLines.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_iblines(ibConf_t *conf, short *line_status) { int retval; ibBoard_t *board; if (conf->is_interface == 0) { setIberr(EARG); return -1; } board = interfaceBoard(conf); retval = ioctl(board->fileno, IBLINES, line_status); if (retval < 0) { switch (errno) { default: setIbcnt(errno); setIberr(EDVR); break; } return -1; } return 0; } int iblines(int ud, short *line_status) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 1); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = internal_iblines(conf, line_status); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } void TestSRQ(int boardID, short *result) { short line_status; ibConf_t *conf; int retval; conf = general_enter_library(boardID, 1, 0); if (conf == NULL) { general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } retval = internal_iblines(conf, &line_status); if (retval < 0) { general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } if ((line_status & ValidSRQ) == 0) { setIberr(ECAP); general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } if (line_status & BusSRQ) *result = 1; else *result = 0; general_exit_library(boardID, 0, 0, 0, 0, 0, 1); } lib/ibLoc.c000066400000000000000000000057631507046215500130400ustar00rootroot00000000000000/*************************************************************************** lib/ibLoc.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include "ibP.h" #include int ibloc(int ud) { ibConf_t *conf; ibBoard_t *board; uint8_t cmd[32]; unsigned int i; ssize_t count; int retval; conf = general_enter_library(ud, 1, 0); if (conf == NULL) return exit_library(ud, 1); board = interfaceBoard(conf); if (conf->is_interface) { retval = ioctl(board->fileno, IBLOC); if (retval < 0) { fprintf(stderr, "IBLOC ioctl failed\n"); setIberr(EDVR); setIbcnt(errno); return exit_library(ud, 1); } } else { retval = conf_lock_board(conf); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); i = send_setup_string(conf, cmd); if (!i) { setIberr(EDVR); return exit_library(ud, 1); } cmd[i++] = GTL; count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); if (count != i) return exit_library(ud, 1); } return exit_library(ud, 0); } void EnableLocal(int boardID, const Addr4882_t addressList[]) { int i; ibConf_t *conf; ibBoard_t *board; uint8_t *cmd; int count; int retval; conf = enter_library(boardID); if (conf == NULL) { exit_library(boardID, 1); return; } if (addressListIsValid(addressList) == 0) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); exit_library(boardID, 1); return; } if (numAddresses(addressList) == 0) { retval = remote_enable(board, 0); if (retval < 0) exit_library(boardID, 1); else exit_library(boardID, 0); return; } cmd = malloc(16 + 2 * numAddresses(addressList)); if (cmd == NULL) { setIberr(EDVR); setIbcnt(ENOMEM); exit_library(boardID, 1); return; } i = create_send_setup(board, addressList, cmd); cmd[i++] = GTL; //XXX detect no listeners (EBUS) error count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (count != i) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } lib/ibOnl.c000066400000000000000000000067461507046215500130550ustar00rootroot00000000000000/*************************************************************************** lib/ibOnl.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int board_online(ibBoard_t *board, int online, ibConf_t *conf) { if (online) { if (ibBoardOpen(board, conf->error_msg_disable) < 0) return -1; } else { ibBoardClose(board); } return 0; } int conf_online(ibConf_t *conf, int online) { ibBoard_t *board; int retval; if ((online && conf->board_is_open) || (online == 0 && conf->board_is_open == 0)) return 0; board = interfaceBoard(conf); retval = board_online(board, online, conf); if (retval < 0) return retval; if (online) retval = open_gpib_handle(conf); else retval = close_gpib_handle(conf); if (retval < 0) return retval; conf->board_is_open = online != 0; return 0; } int reinit_descriptor(ibConf_t *conf) { int msad; int retval; retval = internal_ibpad(conf, conf->defaults.pad); if (retval < 0) return retval; msad = conf->defaults.sad; if (msad < 0) msad = 0; else msad = MSA(msad); retval = internal_ibsad(conf, msad); if (retval < 0) return retval; if (conf->is_interface == 0) { /* ibbna is device only */ retval = my_ibbna(conf, conf->defaults.board); if (retval < 0) return retval; } conf->settings.usec_timeout = conf->defaults.usec_timeout; conf->settings.spoll_usec_timeout = conf->defaults.usec_timeout; conf->settings.ppoll_usec_timeout = conf->defaults.usec_timeout; conf->settings.eos = conf->defaults.eos; conf->settings.eos_flags = conf->defaults.eos_flags; conf->settings.ppoll_config = conf->defaults.ppoll_config; internal_ibeot(conf, conf->defaults.send_eoi); conf->settings.local_lockout = conf->defaults.local_lockout; conf->settings.readdr = conf->defaults.readdr; return 0; } int ibonl(int ud, int onl) { ibConf_t *conf; int retval; int status; conf = general_enter_library(ud, 1, 1); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = internal_ibstop(conf); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = conf_lock_board(conf); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); if (onl) { retval = reinit_descriptor(conf); if (retval < 0) return exit_library(ud, 1); else return exit_library(ud, 0); } status = general_exit_library(ud, 0, 0, 0, 0, CMPL, 1); if (onl == 0) retval = close_gpib_handle(conf); else retval = 0; conf_unlock_board(conf); if (retval < 0) { fprintf(stderr, "libgpib: failed to mark device as closed!\n"); status |= ERR; setIbsta(status); sync_globals(); return status; } release_descriptor(ud); return status; } lib/ibP.h000066400000000000000000000025341507046215500125200ustar00rootroot00000000000000/*************************************************************************** lib/ibP.h ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _IBP_H #define _IBP_H #include "ibConf.h" /* Unit descriptor flag */ #define GPIB_CONFIGS_LENGTH 0x1000 #define FIND_CONFIGS_LENGTH 64 /* max number of devices we can read from config file */ extern ibBoard_t ibBoard[]; extern ibConf_t *ibConfigs[]; extern ibConf_t ibFindConfigs[]; #include #include static const int sad_offset = 0x60; #endif /* _IBP_H */ lib/ibPad.c000066400000000000000000000034441507046215500130210ustar00rootroot00000000000000/*************************************************************************** lib/ibPad.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibpad(ibConf_t *conf, unsigned int address) { ibBoard_t *board; struct gpib_pad_ioctl pad_cmd; int retval; board = interfaceBoard(conf); if (address > 30) { setIberr(EARG); fprintf(stderr, "libgpib: invalid gpib address\n"); return -1; } pad_cmd.handle = conf->handle; pad_cmd.pad = address; retval = ioctl(board->fileno, IBPAD, &pad_cmd); if (retval < 0) { fprintf(stderr, "libgpib: failed to change gpib primary address\n"); setIberr(EDVR); setIbcnt(errno); return retval; } conf->settings.pad = address; return 0; } int ibpad(int ud, int addr) { ibConf_t *conf; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = internal_ibpad(conf, addr); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibRd.c000066400000000000000000000174541507046215500126700ustar00rootroot00000000000000/*************************************************************************** lib/ibRd.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include "ib_internal.h" // sets up bus to receive data from device with address pad/sad int InternalReceiveSetup(ibConf_t *conf, unsigned int usec_timeout, Addr4882_t address) { ibBoard_t *board; uint8_t cmdString[8]; unsigned int i = 0; unsigned int pad, board_pad; int sad, board_sad; if (addressIsValid(address) == 0 || address == NOADDR) { setIberr(EARG); return -1; } board = interfaceBoard(conf); if (query_pad(board, &board_pad) < 0) return -1; if (query_sad(board, &board_sad) < 0) return -1; pad = extractPAD(address); sad = extractSAD(address); cmdString[ i++ ] = UNL; cmdString[ i++ ] = MLA(board_pad); /* controller's listen address */ if (board_sad >= 0) cmdString[ i++ ] = MSA(board_sad); cmdString[ i++ ] = MTA(pad); if (sad >= 0) cmdString[ i++ ] = MSA(sad); if (my_ibcmd(conf, usec_timeout, cmdString, i) < 0) { fprintf(stderr, "%s: command failed\n", __FUNCTION__); return -1; } return 0; } static int read_data(ibConf_t *conf, unsigned int usec_timeout, uint8_t *buffer, size_t count, size_t *bytes_read) { ibBoard_t *board; struct gpib_read_write_ioctl read_cmd; int retval; board = interfaceBoard(conf); assert(sizeof(buffer) <= sizeof(read_cmd.buffer_ptr)); read_cmd.buffer_ptr = (uintptr_t)buffer; read_cmd.requested_transfer_count = count; read_cmd.completed_transfer_count = 0; read_cmd.handle = conf->handle; read_cmd.end = 0; set_timeout(board, usec_timeout); conf->end = 0; retval = ioctl(board->fileno, IBRD, &read_cmd); if (retval < 0) { switch (errno) { case ETIMEDOUT: conf->timed_out = 1; setIberr(EABO); break; case EINTR: setIberr(EABO); break; default: setIberr(EDVR); setIbcnt(errno); break; } } if (read_cmd.end) conf->end = 1; *bytes_read = read_cmd.completed_transfer_count; return retval; } int my_ibrd(ibConf_t *conf, unsigned int usec_timeout, uint8_t *buffer, size_t count, size_t *bytes_read) { int retval; *bytes_read = 0; // set eos mode iblcleos(conf); if (conf->is_interface == 0) { // set up addressing if (InternalReceiveSetup(conf, usec_timeout, packAddress(conf->settings.pad, conf->settings.sad)) < 0) return -1; } retval = read_data(conf, usec_timeout, buffer, count, bytes_read); if (!conf->is_interface && conf->settings.send_unt_unl) retval = unlisten_untalk(conf); return retval; } int ibrd(int ud, void *rd, long cnt) { ibConf_t *conf; ssize_t retval; size_t bytes_read; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = my_ibrd(conf, conf->settings.usec_timeout, rd, cnt, &bytes_read); if (retval < 0) { if (ThreadIberr() != EDVR) setIbcnt(bytes_read); return exit_library(ud, 1); } else { setIbcnt(bytes_read); } return general_exit_library(ud, 0, 0, 0, DCAS, 0, 0); } int ibrda(int ud, void *buffer, long cnt) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 0); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = gpib_aio_launch(ud, conf, GPIB_AIO_READ, buffer, cnt); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } int ibrdf(int ud, const char *file_path) { ibConf_t *conf; int retval; uint8_t buffer[ 0x4000 ]; unsigned long byte_count; FILE *save_file; int error; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); save_file = fopen(file_path, "a"); if (save_file == NULL) { setIberr(EFSO); setIbcnt(errno); return exit_library(ud, 1); } if (conf->is_interface == 0) { // set up addressing if (InternalReceiveSetup(conf, conf->settings.usec_timeout, packAddress(conf->settings.pad, conf->settings.sad)) < 0) return exit_library(ud, 1); } // set eos mode iblcleos(conf); byte_count = error = 0; do { int fwrite_count; size_t bytes_read; retval = read_data(conf, conf->settings.usec_timeout, buffer, sizeof(buffer), &bytes_read); fwrite_count = fwrite(buffer, 1, bytes_read, save_file); if (fwrite_count != bytes_read) { setIberr(EFSO); setIbcnt(errno); error++; } byte_count += fwrite_count; if (retval < 0) { error++; break; } } while (conf->end == 0 && error == 0); if (!conf->is_interface && conf->settings.send_unt_unl) { retval = unlisten_untalk(conf); if (retval < 0) error++; } if (!error) setIbcnt(byte_count); if (fclose(save_file)) { setIberr(EFSO); setIbcnt(errno); return exit_library(ud, 1); } if (error) return exit_library(ud, error); return general_exit_library(ud, 0, 0, 0, DCAS, 0, 0); } int InternalRcvRespMsg(ibConf_t *conf, void *buffer, long count, int termination) { ibBoard_t *board; int retval; int use_eos; size_t bytes_read; if (conf->is_interface == 0) { setIberr(EARG); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } if (termination != (termination & 0xff) && termination != STOPend) { setIberr(EARG); return -1; } // XXX check for listener active state //XXX detect no listeners (EBUS) error use_eos = (termination != STOPend); retval = config_read_eos(board, use_eos, termination, 1); if (retval < 0) return retval; retval = read_data(conf, conf->settings.usec_timeout, buffer, count, &bytes_read); setIbcnt(bytes_read); if (retval < 0) return -1; return 0; } void RcvRespMsg(int boardID, void *buffer, long count, int termination) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalRcvRespMsg(conf, buffer, count, termination); if (retval < 0) { exit_library(boardID, 1); return; } general_exit_library(boardID, 0, 0, 0, DCAS, 0, 0); } void ReceiveSetup(int boardID, Addr4882_t address) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalReceiveSetup(conf, conf->settings.usec_timeout, address); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } int InternalReceive(ibConf_t *conf, Addr4882_t address, void *buffer, long count, int termination) { int retval; retval = InternalReceiveSetup(conf, conf->settings.usec_timeout, address); if (retval < 0) return retval; retval = InternalRcvRespMsg(conf, buffer, count, termination); if (retval < 0) return retval; return 0; } void Receive(int boardID, Addr4882_t address, void *buffer, long count, int termination) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalReceive(conf, address, buffer, count, termination); if (retval < 0) { exit_library(boardID, 1); return; } general_exit_library(boardID, 0, 0, 0, DCAS, 0, 0); } lib/ibRpp.c000066400000000000000000000043211507046215500130510ustar00rootroot00000000000000/*************************************************************************** lib/ibRpp.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibrpp(ibConf_t *conf, char *result) { uint8_t poll_byte; ibBoard_t *board; int retval; board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } set_timeout(board, conf->settings.ppoll_usec_timeout); retval = ioctl(board->fileno, IBRPP, &poll_byte); if (retval < 0) { switch (errno) { case ETIMEDOUT: conf->timed_out = 1; break; default: setIberr(EDVR); setIbcnt(errno); break; } return -1; } *result = poll_byte; return 0; } int ibrpp(int ud, char *ppr) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); retval = internal_ibrpp(conf, ppr); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } void PPoll(int boardID, short *result) { char byte_result; ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } retval = internal_ibrpp(conf, &byte_result); if (retval < 0) { exit_library(boardID, 1); return; } *result = byte_result & 0xff; exit_library(boardID, 0); } lib/ibRsp.c000066400000000000000000000122011507046215500130500ustar00rootroot00000000000000/*************************************************************************** lib/ibRsp.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" static int serial_poll(ibBoard_t *board, unsigned int pad, int sad, unsigned int usec_timeout, char *result) { struct gpib_serial_poll_ioctl poll_cmd; int retval; poll_cmd.pad = pad; poll_cmd.sad = sad; set_timeout(board, usec_timeout); retval = ioctl(board->fileno, IBRSP, &poll_cmd); if (retval < 0) { switch (errno) { case ETIMEDOUT: setIberr(EABO); break; case EPIPE: setIberr(ESTB); break; default: setIberr(EDVR); setIbcnt(errno); break; } return -1; } *result = poll_cmd.status_byte; return 0; } int ibrsp(int ud, char *spr) { ibConf_t *conf; ibBoard_t *board; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); if (conf->is_interface) { setIberr(EARG); return exit_library(ud, 1); } board = interfaceBoard(conf); retval = serial_poll(board, conf->settings.pad, conf->settings.sad, conf->settings.spoll_usec_timeout, spr); if (retval < 0) { if (errno == ETIMEDOUT) conf->timed_out = 1; return exit_library(ud, 1); } return exit_library(ud, 0); } void AllSPoll(int boardID, const Addr4882_t addressList[], short resultList[]) { int i; ibConf_t *conf; ibBoard_t *board; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (addressListIsValid(addressList) == 0) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); exit_library(boardID, 1); return; } // XXX could use slightly more efficient ALLSPOLL protocol retval = 0; for (i = 0; i < numAddresses(addressList); i++) { char result; retval = serial_poll(board, extractPAD(addressList[ i ]), extractSAD(addressList[ i ]), conf->settings.spoll_usec_timeout, &result); if (retval < 0) { if (errno == ETIMEDOUT) conf->timed_out = 1; break; } resultList[ i ] = result & 0xff; } setIbcnt(i); if (retval < 0) exit_library(boardID, 1); else exit_library(boardID, 0); } void AllSpoll(int boardID, const Addr4882_t addressList[], short resultList[]) { AllSPoll(boardID, addressList, resultList); } void FindRQS(int boardID, const Addr4882_t addressList[], short *result) { int i; ibConf_t *conf; ibBoard_t *board; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (addressListIsValid(addressList) == 0) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); exit_library(boardID, 1); return; } retval = 0; for (i = 0; i < numAddresses(addressList); i++) { char spoll_byte; retval = serial_poll(board, extractPAD(addressList[ i ]), extractSAD(addressList[ i ]), conf->settings.usec_timeout, &spoll_byte); if (retval < 0) { if (errno == ETIMEDOUT) conf->timed_out = 1; break; } if (spoll_byte & request_service_bit) { *result = spoll_byte & 0xff; break; } } setIbcnt(i); if (i == numAddresses(addressList)) { setIberr(ETAB); retval = -1; } if (retval < 0) exit_library(boardID, 1); else exit_library(boardID, 0); } void ReadStatusByte(int boardID, Addr4882_t address, short *result) { ibConf_t *conf; ibBoard_t *board; char byte_result; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (addressIsValid(address) == 0) { exit_library(boardID, 1); return; } if (conf->is_interface == 0) { setIberr(EDVR); exit_library(boardID, 1); return; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); exit_library(boardID, 1); return; } retval = serial_poll(board, extractPAD(address), extractSAD(address), conf->settings.spoll_usec_timeout, &byte_result); if (retval < 0) { if (errno == ETIMEDOUT) conf->timed_out = 1; exit_library(boardID, 1); return; } *result = byte_result & 0xff; exit_library(boardID, 0); } lib/ibRsv.c000066400000000000000000000046161507046215500130710ustar00rootroot00000000000000/*************************************************************************** lib/ibRsv.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibrsv2(ibConf_t *conf, int status_byte, int new_reason_for_service) { ibBoard_t *board; struct gpib_request_service2 cmd; int retval; const int MSS = status_byte & request_service_bit; if (!conf->is_interface) { setIberr(EARG); return -1; } if ((status_byte & 0xff) != status_byte) { setIberr(EARG); return -1; } board = interfaceBoard(conf); cmd.status_byte = status_byte; cmd.new_reason_for_service = new_reason_for_service; /* prefer using IBRSV if it is sufficient, since it is supported * by older versions of the kernel modules. */ if (MSS == 0 || (MSS && new_reason_for_service)) retval = ioctl(board->fileno, IBRSV, &cmd.status_byte); else retval = ioctl(board->fileno, IBRSV2, &cmd); if (retval < 0) { if (errno == EOPNOTSUPP) { setIberr(ECAP); } else { setIberr(EDVR); setIbcnt(errno); } return retval; } return 0; } /* FIXME: NI's version returns old status byte in iberr on success. * Why that is at all useful, I do not know. */ int ibrsv(int ud, int status_byte) { return ibrsv2(ud, status_byte, status_byte & request_service_bit); } int ibrsv2(int ud, int status_byte, int new_reason_for_service) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); retval = internal_ibrsv2(conf, status_byte, new_reason_for_service); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibSad.c000066400000000000000000000031361507046215500130220ustar00rootroot00000000000000/*************************************************************************** lib/ibSad.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibsad(ibConf_t *conf, int address) { ibBoard_t *board; struct gpib_sad_ioctl sad_cmd; int sad; int retval; board = interfaceBoard(conf); if (!address) sad = -1; else sad = address - sad_offset; if (sad < -1 || sad > gpib_sad_max) { setIberr(EARG); return -1; } sad_cmd.handle = conf->handle; sad_cmd.sad = sad; retval = ioctl(board->fileno, IBSAD, &sad_cmd); if (retval < 0) { fprintf(stderr, "libgpib: failed to change gpib secondary address\n"); setIberr(EDVR); setIbcnt(errno); return retval; } conf->settings.sad = sad; return 0; } int ibsad(int ud, int v) { ibConf_t *conf; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = internal_ibsad(conf, v); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibSic.c000066400000000000000000000056071507046215500130360ustar00rootroot00000000000000/*************************************************************************** lib/ibSic.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int assert_ifc(ibBoard_t *board, unsigned int usec_duration) { int retval; retval = ioctl(board->fileno, IBSIC, &usec_duration); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); } return retval; } int internal_ibsic(ibConf_t *conf) { ibBoard_t *board; int retval; if (conf->is_interface == 0) { setIberr(EARG); return -1; } board = interfaceBoard(conf); retval = is_system_controller(board); if (retval <= 0) { if (retval == 0) setIberr(ESAC); return -1; } return assert_ifc(board, 100); } int ibsic(int ud) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); retval = internal_ibsic(conf); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } void SendIFC(int boardID) { ibsic(boardID); } int request_system_control(ibBoard_t *board, int request_control) { int rsc_cmd; int retval; rsc_cmd = request_control != 0; retval = ioctl(board->fileno, IBRSC, &rsc_cmd); if (retval < 0) { fprintf(stderr, "libgpib: IBRSC ioctl failed\n"); setIberr(EDVR); setIbcnt(errno); return retval; } board->is_system_controller = request_control != 0; if (request_control && board->set_ren_on_sc) { retval = remote_enable(board, 1); if (retval < 0) { fprintf(stderr, "libgpib: IBRSC remote enable failed\n"); setIberr(EDVR); setIbcnt(errno); return retval; } } return 0; } int internal_ibrsc(ibConf_t *conf, int request_control) { int retval; if (conf->is_interface == 0) { setIberr(EARG); return -1; } retval = request_system_control(interfaceBoard(conf), request_control); if (retval < 0) return retval; return 0; } int ibrsc(int ud, int request_control) { ibConf_t *conf; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = internal_ibrsc(conf, request_control); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibSpb.c000066400000000000000000000034471507046215500130440ustar00rootroot00000000000000/*************************************************************************** lib/ibSpb.c ------------------- copyright : (C) 2017 by Dave Penkler email : dpenkler@gmail.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int internal_ibspb(ibConf_t *conf, short *sp_bytes) { int retval; ibBoard_t *board; struct gpib_spoll_bytes_ioctl spb; if (conf->is_interface) { setIberr(EARG); return -1; } board = interfaceBoard(conf); spb.pad = conf->settings.pad; spb.sad = conf->settings.sad; retval = ioctl(board->fileno, IBSPOLL_BYTES, &spb); if (retval < 0) { switch (errno) { default: setIbcnt(errno); setIberr(EDVR); break; } return -1; } *sp_bytes = spb.num_bytes; return 0; } int ibspb(int ud, short *sp_bytes) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 1); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = internal_ibspb(conf, sp_bytes); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } lib/ibSre.c000066400000000000000000000061461507046215500130500ustar00rootroot00000000000000/*************************************************************************** lib/ibSre.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int remote_enable(const ibBoard_t *board, int enable) { int retval; retval = is_system_controller(board); if (retval <= 0) { if (retval == 0) setIberr(ESAC); return -1; } retval = ioctl(board->fileno, IBSRE, &enable); if (retval < 0) { // XXX other error types? setIberr(EDVR); setIbcnt(errno); return retval; } return 0; } int internal_ibsre(ibConf_t *conf, int v) { ibBoard_t *board; int retval; board = interfaceBoard(conf); if (!conf->is_interface) { setIberr(EARG); return -1; } retval = remote_enable(board, v); if (retval < 0) return retval; return 0; } int ibsre(int ud, int v) { ibConf_t *conf; int retval; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); retval = internal_ibsre(conf, v); if (retval < 0) { fprintf(stderr, "libgpib: ibsre error\n"); return exit_library(ud, 1); } //XXX supposed to set iberr to old REN setting return exit_library(ud, 0); } int InternalEnableRemote(ibConf_t *conf, const Addr4882_t addressList[]) { int i; ibBoard_t *board; uint8_t *cmd; int count; int retval; if (addressListIsValid(addressList) == 0) return -1; if (conf->is_interface == 0) { setIberr(EDVR); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } retval = remote_enable(board, 1); if (retval < 0) return -1; if (numAddresses(addressList) == 0) return 0; cmd = malloc(16 + 2 * numAddresses(addressList)); if (!cmd){ setIberr(EDVR); setIbcnt(ENOMEM); return -1; } i = create_send_setup(board, addressList, cmd); //XXX detect no listeners (EBUS) error count = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (count != i) return -1; return 0; } void EnableRemote(int boardID, const Addr4882_t addressList[]) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalEnableRemote(conf, addressList); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } lib/ibTmo.c000066400000000000000000000071321507046215500130520ustar00rootroot00000000000000/*************************************************************************** lib/ibTmo.c ------------------- copyright : (C) 2001,2002,2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include static const int default_ppoll_usec_timeout = 2; unsigned int timeout_to_usec(enum gpib_timeout timeout) { switch (timeout) { default: case TNONE: return 0; break; case T10us: return 10; break; case T30us: return 30; break; case T100us: return 100; break; case T300us: return 300; break; case T1ms: return 1000; break; case T3ms: return 3000; break; case T10ms: return 10000; break; case T30ms: return 30000; break; case T100ms: return 100000; break; case T300ms: return 300000; break; case T1s: return 1000000; break; case T3s: return 3000000; break; case T10s: return 10000000; break; case T30s: return 30000000; break; case T100s: return 100000000; break; case T300s: return 300000000; break; case T1000s: return 1000000000; break; } return 0; } unsigned int ppoll_timeout_to_usec(unsigned int timeout) { if (timeout == 0) return default_ppoll_usec_timeout; else return timeout_to_usec(timeout); } unsigned int usec_to_timeout(unsigned int usec) { if (usec == 0) return TNONE; else if (usec <= 10) return T10us; else if (usec <= 30) return T30us; else if (usec <= 100) return T100us; else if (usec <= 300) return T300us; else if (usec <= 1000) return T1ms; else if (usec <= 3000) return T3ms; else if (usec <= 10000) return T10ms; else if (usec <= 30000) return T30ms; else if (usec <= 100000) return T100ms; else if (usec <= 300000) return T300ms; else if (usec <= 1000000) return T1s; else if (usec <= 3000000) return T3s; else if (usec <= 10000000) return T10s; else if (usec <= 30000000) return T30s; else if (usec <= 100000000) return T100s; else if (usec <= 300000000) return T300s; else if (usec <= 1000000000) return T1000s; return TNONE; } unsigned int usec_to_ppoll_timeout(unsigned int usec) { if (usec <= default_ppoll_usec_timeout) return 0; else return usec_to_timeout(usec); } int internal_ibtmo(ibConf_t *conf, int timeout) { if (timeout < TNONE || timeout > T1000s) { setIberr(EARG); return -1; } conf->settings.usec_timeout = timeout_to_usec(timeout); return 0; } int ibtmo(int ud, int v) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 0); if (conf == NULL) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = internal_ibtmo(conf, v); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } int set_timeout(const ibBoard_t *board, unsigned int usec_timeout) { return ioctl(board->fileno, IBTMO, &usec_timeout); } lib/ibTrg.c000066400000000000000000000050221507046215500130430ustar00rootroot00000000000000/*************************************************************************** lib/ibTrg.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int my_trigger(ibConf_t *conf, const Addr4882_t addressList[]) { int i, retval; uint8_t *cmd; if (addressListIsValid(addressList) == 0) { setIberr(EARG); return -1; } cmd = malloc(16 + 2 * numAddresses(addressList)); if (!cmd) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } i = create_send_setup(interfaceBoard(conf), addressList, cmd); cmd[ i++ ] = GET; retval = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (retval != i) return -1; return 0; } int ibtrg(int ud) { ibConf_t *conf; int retval; Addr4882_t addressList[ 2 ]; conf = enter_library(ud); if (conf == NULL) return exit_library(ud, 1); if (conf->is_interface) { setIberr(EARG); return exit_library(ud, 1); } addressList[ 0 ] = packAddress(conf->settings.pad, conf->settings.sad); addressList[ 1 ] = NOADDR; retval = my_trigger(conf, addressList); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } void TriggerList(int boardID, const Addr4882_t addressList[]) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (!conf->is_interface) { setIberr(EDVR); exit_library(boardID, 1); return; } retval = my_trigger(conf, addressList); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } void Trigger(int boardID, Addr4882_t address) { Addr4882_t addressList[ 2 ]; addressList[ 0 ] = address; addressList[ 1 ] = NOADDR; TriggerList(boardID, addressList); } lib/ibVers.c000066400000000000000000000017711507046215500132350ustar00rootroot00000000000000/*************************************************************************** lib/ibVers.c ------------ ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ibVers.h" #define xstr(s) str(s) #define str(s) #s static char *my_version = xstr(GPIB_SCM_VERSION); void ibvers( char **vers ) { *vers = my_version; } lib/ibWait.c000066400000000000000000000124271507046215500132220ustar00rootroot00000000000000/*************************************************************************** lib/ibWait.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include static const int device_wait_mask = TIMO | END | CMPL | RQS; static const int board_wait_mask = TIMO | END | CMPL | SPOLL | EVENT | LOK | REM | CIC | ATN | TACS | LACS | DTAS | DCAS | SRQI; void fixup_status_bits(const ibConf_t *conf, int *status) { if (!conf->is_interface) { *status &= device_wait_mask; } else { *status &= board_wait_mask; if (interfaceBoard(conf)->use_event_queue) { *status &= ~DTAS & ~DCAS; } else { *status &= ~EVENT; } } } int my_wait(ibConf_t *conf, int wait_mask, int clear_mask, int set_mask, int *status) { ibBoard_t *board; int retval; struct gpib_wait_ioctl cmd; board = interfaceBoard(conf); if ((!conf->is_interface) && (retval = is_cic(board)) != 1) { if (retval == 0) setIberr(ECIC); return -1; } cmd.handle = conf->handle; cmd.usec_timeout = conf->settings.usec_timeout; cmd.wait_mask = wait_mask; cmd.clear_mask = clear_mask; cmd.set_mask = set_mask; cmd.ibsta = 0; fixup_status_bits(conf, &cmd.wait_mask); if (!conf->is_interface) { cmd.pad = conf->settings.pad; cmd.sad = conf->settings.sad; } else { cmd.pad = NOADDR; cmd.sad = NOADDR; //XXX additionally, clear wait mask depending on event queue enabled, etc */ } if (wait_mask != cmd.wait_mask) { setIberr(EARG); return -1; } retval = ioctl(board->fileno, IBWAIT, &cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } fixup_status_bits(conf, &cmd.ibsta); if (conf->end) //XXX cmd.ibsta |= END; setIbsta(cmd.ibsta); *status = cmd.ibsta; return 0; } int ibwait(int ud, int mask) { ibConf_t *conf; int retval; int status; int clear_mask; int error = 0; conf = general_enter_library(ud, 1, 0); if (!conf) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); /** check for invalid mask bits */ if (!conf->is_interface) { if ((mask & device_wait_mask) != mask) { fprintf(stderr, "Invalid wait mask for device descriptor, valid wait bits are 0x%x\n", device_wait_mask); setIberr(EARG); return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } } else { if ((mask & board_wait_mask) != mask) { fprintf(stderr, "Invalid wait mask for board descriptor, valid wait bits are 0x%x\n", board_wait_mask); setIberr(EARG); return general_exit_library(ud, 1, 0, 0, 0, 0, 1); } } clear_mask = mask & (DTAS | DCAS | SPOLL); retval = my_wait(conf, mask, clear_mask, 0, &status); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); /* We will only try to resync with async io if the user explicitly asked to wait on CMPL. That way, they won't be confused by possible errors associated with the async io on random ibwait calls. If CMPL was specified in the wait mask, then any running async io will be joined and the library status variables will be updated with the results from the most recent async io operation completed on this descriptor. If errors occur both on this ibwait itself and on the most recent async io, then reporting errors from the ibwait takes precedence. */ if (mask & CMPL) { if (status & CMPL) { if (conf->async.in_progress) { if (gpib_aio_join(&conf->async)) { error++; general_exit_library(ud, error, 0, 1, 0, 0, 1); } else { conf->async.in_progress = 0; } } pthread_mutex_lock(&conf->async.lock); if (conf->async.ibsta & CMPL) { setIbcnt(conf->async.ibcntl); setIberr(conf->async.iberr); if (conf->async.ibsta & ERR) error++; } pthread_mutex_unlock(&conf->async.lock); } if (error) { status |= ERR; setIbsta(status); } } general_exit_library(ud, error, 0, 1, 0, 0, 1); return status; } void WaitSRQ(int boardID, short *result) { ibConf_t *conf; int retval; int wait_mask; int status; conf = general_enter_library(boardID, 1, 0); if (!conf) { general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } if (!conf->is_interface) { setIberr(EDVR); general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } wait_mask = SRQI | TIMO; retval = my_wait(conf, wait_mask, 0, 0, &status); if (retval < 0) { general_exit_library(boardID, 1, 0, 0, 0, 0, 1); return; } // XXX need better query of service request state, new ioctl? // should play nice with autopolling if (ThreadIbsta() & SRQI) *result = 1; else *result = 0; general_exit_library(boardID, 0, 0, 0, 0, 0, 1); } lib/ibWrt.c000066400000000000000000000215641507046215500130740ustar00rootroot00000000000000/*************************************************************************** lib/ibWrt.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include "ib_internal.h" #include #include #include #include #include #include #include int find_eos(const uint8_t *buffer, size_t length, int eos, int eos_flags) { unsigned int i; unsigned int compare_mask; if (eos_flags & BIN) compare_mask = 0xff; else compare_mask = 0x7f; for(i = 0; i < length; i++) { if ((buffer[i] & compare_mask) == (eos & compare_mask)) return i; } return -1; } int send_data(ibConf_t *conf, unsigned int usec_timeout, const void *buffer, size_t count, int send_eoi, size_t *bytes_written) { ibBoard_t *board; struct gpib_read_write_ioctl write_cmd; int retval; board = interfaceBoard(conf); set_timeout(board, usec_timeout); assert(sizeof(buffer) <= sizeof(write_cmd.buffer_ptr)); write_cmd.buffer_ptr = (uintptr_t)buffer; write_cmd.requested_transfer_count = count; write_cmd.completed_transfer_count = 0; write_cmd.end = send_eoi; write_cmd.handle = conf->handle; retval = ioctl(board->fileno, IBWRT, &write_cmd); if (retval < 0) { switch (errno) { case ETIMEDOUT: conf->timed_out = 1; setIberr(EABO); break; case EINTR: setIberr(EABO); break; case ECOMM: setIberr(ENOL); break; case EFAULT: //fall-through default: setIberr(EDVR); setIbcnt(errno); break; } } *bytes_written = write_cmd.completed_transfer_count; conf->end = send_eoi && (*bytes_written == count); if (retval < 0) return retval; return 0; } int send_data_smart_eoi(ibConf_t *conf, unsigned int usec_timeout, const void *buffer, size_t count, int force_eoi, size_t *bytes_written) { int eoi_on_eos; int eos_found = 0; int send_eoi; unsigned long block_size; int retval; eoi_on_eos = conf->settings.eos_flags & XEOS; block_size = count; if (eoi_on_eos) { retval = find_eos(buffer, count, conf->settings.eos, conf->settings.eos_flags); if (retval < 0) { eos_found = 0; } else { block_size = retval; eos_found = 1; } } send_eoi = force_eoi || (eoi_on_eos && eos_found); if (send_data(conf, usec_timeout, buffer, block_size, send_eoi, bytes_written) < 0) return -1; return 0; } int my_ibwrt(ibConf_t *conf, unsigned int usec_timeout, const uint8_t *buffer, size_t count, size_t *bytes_written) { ibBoard_t *board; size_t block_size; int retval; *bytes_written = 0; board = interfaceBoard(conf); set_timeout(board, usec_timeout); if (!conf->is_interface) { // set up addressing if (send_setup(conf, usec_timeout) < 0) return -1; } while (count) { retval = send_data_smart_eoi(conf, usec_timeout, buffer, count, conf->settings.send_eoi, &block_size); *bytes_written += block_size; if (retval < 0) break; count -= block_size; buffer += block_size; } if (!conf->is_interface && conf->settings.send_unt_unl) { retval = unlisten_untalk(conf); } return retval; } int ibwrt(int ud, const void *rd, long cnt) { ibConf_t *conf; size_t count; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); conf->end = 0; retval = my_ibwrt(conf, conf->settings.usec_timeout, rd, cnt, &count); if (retval < 0) { if (ThreadIberr() != EDVR) setIbcnt(count); return exit_library(ud, 1); } setIbcnt(count); return general_exit_library(ud, 0, 0, 0, DCAS, 0, 0); } int ibwrta(int ud, const void *buffer, long cnt) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 0); if (!conf) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = gpib_aio_launch(ud, conf, GPIB_AIO_WRITE, (void*)buffer, cnt); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, 0, 0, 0, 0, 0, 1); } int my_ibwrtf(ibConf_t *conf, const char *file_path, size_t *bytes_written) { ibBoard_t *board; long count; size_t block_size; int retval; FILE *data_file; struct stat file_stats; uint8_t buffer[ 0x4000 ]; *bytes_written = 0; board = interfaceBoard(conf); data_file = fopen(file_path, "r"); if (!data_file) { setIberr(EFSO); setIbcnt(errno); return -1; } retval = fstat(fileno(data_file), &file_stats); if (retval < 0) { setIberr(EFSO); setIbcnt(errno); return -1; } count = file_stats.st_size; if (!conf->is_interface) { // set up addressing if (send_setup(conf, conf->settings.usec_timeout) < 0) return -1; } set_timeout(board, conf->settings.usec_timeout); while (count) { size_t fread_count; int send_eoi; size_t buffer_offset = 0; fread_count = fread(buffer, 1, sizeof(buffer), data_file); if (!fread_count) { setIberr(EFSO); setIbcnt(errno); retval = -1; break; } while (buffer_offset < fread_count) { send_eoi = conf->settings.send_eoi && (count == fread_count - buffer_offset); retval = send_data_smart_eoi(conf, conf->settings.usec_timeout, buffer + buffer_offset, fread_count - buffer_offset, send_eoi, &block_size); count -= block_size; buffer_offset += block_size; *bytes_written += block_size; if (retval < 0) { count = 0; break; } } } if (!conf->is_interface && conf->settings.send_unt_unl) retval = unlisten_untalk(conf); return retval; } int ibwrtf(int ud, const char *file_path) { ibConf_t *conf; size_t count; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); conf->end = 0; retval = my_ibwrtf(conf, file_path, &count); if (retval < 0) { if (ThreadIberr() != EDVR) setIbcnt(count); return exit_library(ud, 1); } setIbcnt(count); return general_exit_library(ud, 0, 0, 0, DCAS, 0, 0); } int InternalSendDataBytes(ibConf_t *conf, const void *buffer, size_t count, int eotmode) { int retval; size_t num_bytes; size_t bytes_written = 0; if (!conf->is_interface) { setIberr(EARG); return -1; } switch (eotmode) { case DABend: case NLend: case NULLend: break; default: setIberr(EARG); return -1; break; } retval = send_data(conf, conf->settings.usec_timeout, buffer, count, eotmode == DABend, &num_bytes); bytes_written += num_bytes; if (retval < 0) { setIbcnt(bytes_written); return retval; } if (eotmode == NLend) { retval = send_data(conf, conf->settings.usec_timeout, "\n", 1, 1, &num_bytes); bytes_written += num_bytes; if (retval < 0) { setIbcnt(bytes_written); return retval; } } setIbcnt(bytes_written); return 0; } void SendDataBytes(int boardID, const void *buffer, long count, int eotmode) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalSendDataBytes(conf, buffer, count, eotmode); if (retval < 0) { exit_library(boardID, 1); return; } general_exit_library(boardID, 0, 0, 0, DCAS, 0, 0); } int InternalSendList(ibConf_t *conf, const Addr4882_t addressList[], const void *buffer, long count, int eotmode) { ibBoard_t *board; int retval; if (!addressListIsValid(addressList) || !numAddresses(addressList)) { setIberr(EARG); return -1; } if (!conf->is_interface) { setIberr(EARG); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } retval = InternalSendSetup(conf, addressList); if (retval < 0) return retval; retval = InternalSendDataBytes(conf, buffer, count, eotmode); if (retval < 0) return retval; return 0; } void SendList(int boardID, const Addr4882_t addressList[], const void *buffer, long count, int eotmode) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalSendList(conf, addressList, buffer, count, eotmode); if (retval < 0) { exit_library(boardID, 1); return; } general_exit_library(boardID, 0, 0, 0, DCAS, 0, 0); } void Send(int boardID, Addr4882_t address, const void *buffer, long count, int eotmode) { Addr4882_t addressList[ 2 ]; addressList[ 0 ] = address; addressList[ 1 ] = NOADDR; SendList(boardID, addressList, buffer, count, eotmode); } lib/ib_internal.h000066400000000000000000000146321507046215500142760ustar00rootroot00000000000000/*************************************************************************** lib/ib_internal.h ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _IB_INTERNAL_H #define _IB_INTERNAL_H #include "gpib/ib.h" #include "ibP.h" #include "gpib/gpib_ioctl.h" #include #include #include #include "ibConf.h" enum internal_gpib_addr { SAD_DISABLED = -1, ADDR_INVALID = -2 }; int my_wait(ibConf_t *conf, int wait_mask, int clear_mask, int set_mask, int *status); void init_async_op(struct async_operation *async); int ibBoardOpen(ibBoard_t *board, int error_msg_disable); int ibBoardClose(ibBoard_t *board); int ibGetNrBoards(void); int iblcleos(const ibConf_t *conf); void ibPutMsg (char *format,...); void ibPutErrlog(int ud,char *routine); int ibParseConfigFile(int ud); int insert_descriptor(ibConf_t conf, int ud); int ibFindDevIndex(const char *name); ssize_t my_ibcmd(ibConf_t *conf, unsigned int usec_timout, const uint8_t *buffer, size_t length); int my_ibrd(ibConf_t *conf, unsigned int usec_timeout, uint8_t *buffer, size_t count, size_t *bytes_read); int my_ibwrt(ibConf_t *conf, unsigned int usec_timeout, const uint8_t *buffer, size_t count, size_t *bytes_written); unsigned int send_setup_string(const ibConf_t *conf, uint8_t *cmdString); unsigned int create_send_setup(const ibBoard_t *board, const Addr4882_t addressList[], uint8_t *cmdString); int send_setup(ibConf_t *conf, unsigned int usec_timeout); int unlisten_untalk(ibConf_t *conf); void init_ibconf(ibConf_t *conf); void init_ibboard(ibBoard_t *board); int my_ibdev(ibConf_t new_conf); int my_ibbna(ibConf_t *conf, unsigned int new_board_index); unsigned int timeout_to_usec(enum gpib_timeout timeout); unsigned int ppoll_timeout_to_usec(unsigned int timeout); unsigned int usec_to_ppoll_timeout(unsigned int usec); int set_timeout(const ibBoard_t *board, unsigned int usec_timeout); int close_gpib_handle(ibConf_t *conf); int open_gpib_handle(ibConf_t *conf); int lock_board_mutex(ibBoard_t *board); int unlock_board_mutex(ibBoard_t *board); int conf_lock_board(ibConf_t *conf); void conf_unlock_board(ibConf_t *conf); int release_descriptor(int ud); int ibstatus(ibConf_t *conf, int error, int clear_mask, int set_mask); int exit_library(int ud, int error); int general_exit_library(int ud, int error, int no_sync_globals, int no_update_ibsta, int status_clear_mask, int status_set_mask, int no_unlock_board); ibConf_t * enter_library(int ud); ibConf_t * general_enter_library(int ud, int no_lock_board, int ignore_eoip); void setIbsta(int status); void setIberr(int error); void setIbcnt(long count); void setAsyncIbsta(int status); void setAsyncIberr(int error); void setAsyncIbcnt(long count); unsigned int usec_to_timeout(unsigned int usec); int query_ppc(const ibBoard_t *board); int query_local_ppoll_mode(const ibBoard_t *board); int query_ist(const ibBoard_t *board); int query_pad(const ibBoard_t *board, unsigned int *pad); int query_sad(const ibBoard_t *board, int *sad); int conf_online(ibConf_t *conf, int online); int configure_autospoll(ibConf_t *conf, int enable); int extractPAD(Addr4882_t address); int extractSAD(Addr4882_t address); Addr4882_t packAddress(unsigned int pad, int sad); int addressIsValid(Addr4882_t address); int addressListIsValid(const Addr4882_t addressList[]); unsigned int numAddresses(const Addr4882_t addressList[]); int remote_enable(const ibBoard_t *board, int enable); int config_read_eos(ibBoard_t *board, int use_eos_char, int eos_char, int compare_8_bits); void sync_globals(void); int is_system_controller(const ibBoard_t *board); int is_cic(const ibBoard_t *board); int assert_ifc(ibBoard_t *board, unsigned int usec); int request_system_control(ibBoard_t *board, int request_control); int internal_ibpad(ibConf_t *conf, unsigned int address); int internal_ibsad(ibConf_t *conf, int address); int internal_ibtmo(ibConf_t *conf, int timeout); void internal_ibeot(ibConf_t *conf, int send_eoi); int internal_ibist(ibConf_t *conf, int ist); int internal_ibppc(ibConf_t *conf, int v); int internal_ibsre(ibConf_t *conf, int v); int internal_ibrsv2(ibConf_t *conf, int status_byte, int new_reason_for_service); int internal_iblines(ibConf_t *conf, short *line_status); int internal_ibgts(ibConf_t *conf, int shadow_handshake); int internal_ibrsc(ibConf_t *conf, int request_control); int internal_ibsic(ibConf_t *conf); int internal_ibstop(ibConf_t *conf); int InternalDevClearList(ibConf_t *conf, const Addr4882_t addressList[]); int InternalReceiveSetup(ibConf_t *conf, unsigned int usec_timeout, Addr4882_t address); int InternalSendSetup(ibConf_t *conf, const Addr4882_t addressList[]); int InternalSendList(ibConf_t *conf, const Addr4882_t addressList[], const void *buffer, long count, int eotmode); int InternalEnableRemote(ibConf_t *conf, const Addr4882_t addressList[]); int InternalReceive(ibConf_t *conf, Addr4882_t address, void *buffer, long count, int termination); static __inline__ ibBoard_t* interfaceBoard(const ibConf_t *conf) { assert(conf->settings.board >= 0 && conf->settings.board < GPIB_MAX_NUM_BOARDS); return &ibBoard[ conf->settings.board ]; } #include int parse_gpib_conf(const char *filename, ibConf_t *configs, unsigned int configs_length, ibBoard_t *boards, unsigned int boards_length, int minor); #define YY_DECL int gpib_yylex(YYSTYPE *gpib_lvalp, YYLTYPE *gpib_llocp, yyscan_t yyscanner) /* support for async io (ibrda() ibwrta(), etc.) */ enum gpib_aio_varieties { GPIB_AIO_COMMAND, GPIB_AIO_READ, GPIB_AIO_WRITE, }; int gpib_aio_launch(int ud, ibConf_t *conf, int gpib_aio_type, void *buffer, long cnt); int gpib_aio_join(struct async_operation *async); #endif /* _IB_INTERNAL_H */ lib/ibask.c000066400000000000000000000205751507046215500130770ustar00rootroot00000000000000/*************************************************************************** lib/ibask.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int query_ist(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return info.ist; } int query_ppc(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return info.parallel_poll_configuration; } int query_local_ppoll_mode(const ibBoard_t *board) { int retval; short local_mode; retval = ioctl(board->fileno, IBPP2_GET, &local_mode); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return local_mode; } int query_autopoll(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return info.autopolling; } int query_board_t1_delay(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } if (info.t1_delay == 0) { fprintf(stderr, "%s: bug! we don't know what the T1 delay is because it has never been set.\n", __FUNCTION__); return -EIO; } else if (info.t1_delay < 500) return T1_DELAY_350ns; else if (info.t1_delay < 2000) return T1_DELAY_500ns; return T1_DELAY_2000ns; } int query_board_rsv(const ibBoard_t *board) { int retval; int status; retval = ioctl(board->fileno, IBQUERY_BOARD_RSV, &status); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return status; } int query_pad(const ibBoard_t *board, unsigned int *pad) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } *pad = info.pad; return 0; } int query_sad(const ibBoard_t *board, int *sad) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } *sad = info.sad; return 0; } int query_no_7_bit_eos(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } return info.no_7_bit_eos; } int ibask(int ud, int option, int *value) { ibConf_t *conf; ibBoard_t *board; unsigned int pad; int sad; int retval; conf = general_enter_library(ud, 0, 0); if (!conf) return exit_library(ud, 1); board = interfaceBoard(conf); switch (option) { case IbaPAD: if (conf->is_interface) { retval = query_pad(board, &pad); if (retval < 0) return exit_library(ud, 1); conf->settings.pad = pad; } *value = conf->settings.pad; return exit_library(ud, 0); break; case IbaSAD: if (conf->is_interface) { retval = query_sad(board, &sad); if (retval < 0) return exit_library(ud, 1); conf->settings.sad = sad; } if (conf->settings.sad < 0) *value = 0; else *value = MSA(conf->settings.sad); return exit_library(ud, 0); break; case IbaTMO: *value = usec_to_timeout(conf->settings.usec_timeout); return exit_library(ud, 0); break; case IbaEOT: *value = conf->settings.send_eoi; return exit_library(ud, 0); break; case IbaEOSrd: *value = conf->settings.eos_flags & REOS; return exit_library(ud, 0); break; case IbaEOSwrt: *value = conf->settings.eos_flags & XEOS; return exit_library(ud, 0); break; case IbaEOScmp: *value = conf->settings.eos_flags & BIN; return exit_library(ud, 0); break; case IbaEOSchar: *value = conf->settings.eos; return exit_library(ud, 0); break; case IbaBNA: *value = conf->settings.board; return exit_library(ud, 0); break; case IbaReadAdjust: /* XXX I guess I could implement byte swapping stuff, * it's pretty stupid though */ *value = 0; return exit_library(ud, 0); break; case IbaWriteAdjust: /* XXX I guess I could implement byte swapping stuff, * it's pretty stupid though */ *value = 0; return exit_library(ud, 0); break; case IbaEndBitIsNormal: /* XXX no support for setting END status on EOI only yet */ *value = 1; return exit_library(ud, 0); break; default: break; } if (conf->is_interface) { switch (option) { case IbaPPC: retval = query_ppc(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case IbaAUTOPOLL: retval = query_autopoll(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case IbaCICPROT: // XXX we don't support pass control protocol yet *value = 0; return exit_library(ud, 0); break; case IbaIRQ: // XXX we don't support interrupt-less operation yet *value = 0; return exit_library(ud, 0); break; case IbaSC: retval = is_system_controller(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case IbaSRE: *value = board->set_ren_on_sc; return exit_library(ud, 0); break; case IbaPP2: retval = query_local_ppoll_mode(board); if (retval < 0) { return exit_library(ud, 1); } else { *value = retval; return exit_library(ud, 0); } break; case IbaTIMING: retval = query_board_t1_delay(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case IbaDMA: // XXX bogus, but pretty unimportant *value = board->dma; return exit_library(ud, 0); break; case IbaEventQueue: *value = board->use_event_queue; return exit_library(ud, 0); break; case IbaSPollBit: *value = 1; return exit_library(ud, 0); break; case IbaSendLLO: *value = conf->settings.local_lockout; return exit_library(ud, 0); break; case IbaPPollTime: *value = usec_to_ppoll_timeout(conf->settings.ppoll_usec_timeout); return exit_library(ud, 0); break; case IbaHSCableLength: /* HS transfer not supported and may never * be as it is not part of GPIB standard */ *value = 0; return exit_library(ud, 0); break; case IbaIst: retval = query_ist(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case IbaRsv: retval = query_board_rsv(board); if (retval < 0) return exit_library(ud, 1); *value = retval; return exit_library(ud, 0); break; case Iba7BitEOS: retval = query_no_7_bit_eos(board); if (retval < 0) return exit_library(ud, 1); *value = !retval; return exit_library(ud, 0); break; default: break; } } else { switch (option) { case IbaREADDR: *value = conf->settings.readdr; return exit_library(ud, 0); break; case IbaSPollTime: *value = usec_to_timeout(conf->settings.spoll_usec_timeout); return exit_library(ud, 0); break; case IbaUnAddr: *value = conf->settings.send_unt_unl; return exit_library(ud, 0); break; default: break; } } setIberr(EARG); return exit_library(ud, 1); } lib/ibbna.c000066400000000000000000000042471507046215500130570ustar00rootroot00000000000000/*************************************************************************** lib/ibbna.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int my_ibbna(ibConf_t *conf, unsigned int new_board_index) { ibConf_t *board_conf; int retval; int old_board_index; if (conf->is_interface) { setIberr(EARG); return -1; } retval = close_gpib_handle(conf); if (retval < 0) { setIberr(EDVR); return -1; } board_conf = &ibFindConfigs[new_board_index]; if (board_conf->is_interface == 0) { setIberr(EARG); return -1; } retval = is_cic(interfaceBoard(board_conf)); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } old_board_index = conf->settings.board; conf->settings.board = board_conf->settings.board; if (ibBoardOpen(interfaceBoard(conf), conf->error_msg_disable) < 0) { setIberr(EDVR); return -1; } retval = open_gpib_handle(conf); if(retval < 0) { setIberr(EDVR); return -1; } setIberr(old_board_index); return 0; } int ibbna(int ud, char *board_name) { ibConf_t *conf; int retval; int find_index; conf = enter_library(ud); if(!conf) return exit_library(ud, 1); if((find_index = ibFindDevIndex(board_name)) < 0) { setIberr(EARG); return exit_library(ud, 1); } retval = my_ibbna(conf, find_index); if(retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibconfig.c000066400000000000000000000215551507046215500135650ustar00rootroot00000000000000/*************************************************************************** lib/ibconfig.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" static int set_spoll_timeout(ibConf_t *conf, int timeout) { if (timeout < TNONE || timeout > T1000s) { setIberr(EARG); return -1; } conf->settings.spoll_usec_timeout = timeout_to_usec(timeout); return 0; } static int set_ppoll_timeout(ibConf_t *conf, int timeout) { if (timeout < TNONE || timeout > T1000s) { setIberr(EARG); return -1; } conf->settings.ppoll_usec_timeout = ppoll_timeout_to_usec(timeout); return 0; } static int set_t1_delay(ibBoard_t *board, int delay) { unsigned int nano_sec; int retval; switch (delay) { case T1_DELAY_2000ns: nano_sec = 2000; break; case T1_DELAY_500ns: nano_sec = 500; break; case T1_DELAY_350ns: nano_sec = 350; break; default: fprintf(stderr, "libgpib: invalid T1 delay selection\n"); setIberr(EARG); return -1; break; } retval = ioctl(board->fileno, IB_T1_DELAY, &nano_sec); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } return 0; } static int set_local_parallel_poll_mode(ibBoard_t *board, int local) { int retval; short local_mode; local_mode = local != 0; retval = ioctl(board->fileno, IBPP2_SET, &local_mode); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } return 0; } /* Send CFE and CFGn to enable noninterlocked handshaking */ static int set_cable_length (ibConf_t *conf, int num_meters) { int retval; uint8_t cmd[2]; size_t length=0; if (num_meters < 0 || num_meters > 15) { setIberr (EARG); return -1; } cmd [length++] = CFE; if (num_meters) cmd [length++] = CFGn(num_meters); retval = my_ibcmd (conf, conf->settings.usec_timeout, cmd, length); if (retval != length) return -1; return 0; } int ibconfig(int ud, int option, int value) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); switch (option) { case IbcPAD: retval = internal_ibpad(conf, value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcSAD: retval = internal_ibsad(conf, value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcTMO: retval = internal_ibtmo(conf, value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcEOT: internal_ibeot(conf, value); return exit_library(ud, 0); break; case IbcEOSrd: if (value) conf->settings.eos_flags |= REOS; else conf->settings.eos_flags &= ~REOS; return exit_library(ud, 0); break; case IbcEOSwrt: if (value) conf->settings.eos_flags |= XEOS; else conf->settings.eos_flags &= ~XEOS; return exit_library(ud, 0); break; case IbcEOScmp: if (value) conf->settings.eos_flags |= BIN; else conf->settings.eos_flags &= ~BIN; return exit_library(ud, 0); break; case IbcEOSchar: if ((value & 0xff) != value) { setIberr(EARG); return exit_library(ud, 1); } conf->settings.eos = value; return exit_library(ud, 0); break; case IbcReadAdjust: // XXX if (value) { fprintf(stderr, "libgpib: byte swapping on reads not implemented\n"); setIberr(ECAP); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcWriteAdjust: // XXX if (value) { fprintf(stderr, "libgpib: byte swapping on writes not implemented\n"); setIberr(ECAP); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcEndBitIsNormal: if (value) { return exit_library(ud, 0); } else { fprintf(stderr, "libgpib: no support for END on EOI only yet \n"); setIberr(ECAP); return exit_library(ud, 1); } break; default: break; } if (conf->is_interface) { switch (option) { case IbcPPC: retval = internal_ibppc(conf, value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcAUTOPOLL: retval = configure_autospoll(conf, value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcCICPROT: // XXX if (value) { fprintf(stderr, "libgpib: pass control protocol not supported\n"); setIberr(ECAP); return exit_library(ud, 1); }else return exit_library(ud, 0); break; case IbcIRQ: // XXX if (value == 0) { fprintf(stderr, "libgpib: disabling interrupts not supported\n"); setIberr(ECAP); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcSC: retval = internal_ibrsc(conf, value); if (retval < 0) return exit_library(ud, 1); else return exit_library(ud, 0); break; case IbcSRE: if (value) interfaceBoard(conf)->set_ren_on_sc = 1; else interfaceBoard(conf)->set_ren_on_sc = 0; return exit_library(ud, 0); break; case IbcPP2: retval = set_local_parallel_poll_mode(interfaceBoard(conf), value); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcTIMING: if (set_t1_delay(interfaceBoard(conf), value) < 0) return exit_library(ud, 1); return exit_library(ud, 0); break; case IbcDMA: // XXX if (value) { return exit_library(ud, 0); } else { fprintf(stderr, "libgpib: disabling DMA not supported\n"); setIberr(ECAP); return exit_library(ud, 1); } break; case IbcEventQueue: if (value) { interfaceBoard(conf)->use_event_queue = 1; } else { interfaceBoard(conf)->use_event_queue = 0; } return exit_library(ud, 0); break; case IbcSPollBit: /* fprintf(stderr, "libgpib: SPOLL bit support not implemented\n"); setIberr(ECAP);*/ /* we currently have some support for SPOLL in the nec7210 driver, which is always enabled. It can only detect the occurance of a serial poll if the board was requesting service when the poll occurred. */ return exit_library(ud, 0); break; case IbcSendLLO: // XXX if (value) { fprintf(stderr, "libgpib: sending local lockout on device open not implemented\n"); setIberr(ECAP); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcPPollTime: retval = set_ppoll_timeout(conf, value); if (retval < 0) { setIberr(EARG); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcHSCableLength: if (set_cable_length (conf, value) < 0) { return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcIst: retval = internal_ibist(conf, value); if (retval < 0) return exit_library(ud, 1); else return exit_library(ud, 0); break; case IbcRsv: retval = internal_ibrsv2(conf, value, value & request_service_bit); if (retval < 0) return exit_library(ud, 1); else return exit_library(ud, 0); break; default: break; } } else { switch (option) { case IbcREADDR: /* We always re-address. To support only * readdressing when necessary would require * making the driver keep track of current addressing * state. Maybe someday, but low priority. */ if (value) conf->settings.readdr = 1; else conf->settings.readdr = 0; return exit_library(ud, 0); break; case IbcSPollTime: retval = set_spoll_timeout(conf, value); if (retval < 0) { setIberr(EARG); return exit_library(ud, 1); } else { return exit_library(ud, 0); } break; case IbcUnAddr: if (value) conf->settings.send_unt_unl = 1; else conf->settings.send_unt_unl = 0; return exit_library(ud, 0); break; case IbcBNA: retval = my_ibbna(conf, value); if (retval < 0) return exit_library(ud, 1); else return exit_library(ud, 0); break; default: break; } } setIberr(EARG); return exit_library(ud, 1); } lib/ibdev.c000066400000000000000000000104101507046215500130620ustar00rootroot00000000000000/*************************************************************************** ibdev.c ------------------- begin : Tues Feb 12 2002 copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include #if 0 static int is_device_addr(int minor, int pad, int sad) { ibBoard_t *board; unsigned int board_pad; int board_sad; board = &ibBoard[ minor ]; if (query_pad(board, &board_pad) < 0) { fprintf(stderr, "failed to query pad\n"); return -1; } if (query_sad(board, &board_sad) < 0) { fprintf(stderr, "failed to query sad\n"); return -1; } if (gpib_address_equal(board_pad, board_sad, pad, sad) == 0) { return 1; } return 0; } #endif int ibdev(int minor, int pad, int sad, int timo, int eot, int eosmode) { int retval,ud; ibConf_t new_conf; int no_show_error = getenv("IB_NO_ERROR") ? 1 : 0; ibBoard_t *board; unsigned board_pad; int my_sad, board_sad; if (minor < 0 || minor >= GPIB_MAX_NUM_BOARDS) { if (!no_show_error) fprintf(stderr,"ibdev: invalid minor%d\n", minor); setIberr(EARG); sync_globals(); return -1; } retval = ibParseConfigFile(minor); if (retval < 0) { if (errno) { setIberr(EDVR); setIbcnt(errno); } else { setIberr(ECNF); } setIbsta(ERR); sync_globals(); return -1; } /* Check for valid address arguments */ if (pad < 0 || pad > gpib_addr_max) { if (!no_show_error) fprintf(stderr,"ibdev: invalid pad %d, expected 0 <= pad <= 30\n", pad); setIberr(EARG); sync_globals(); return -1; } if (!sad) /* 0 means no address */ my_sad = -1; else my_sad = sad - sad_offset; if (my_sad < -1 || my_sad > gpib_sad_max) { if (!no_show_error) fprintf(stderr,"ibdev: invalid sad 0x%02x, expected 0, or 0x60 <= sad <= 0x7f\n", sad); setIberr(EARG); sync_globals(); return -1; } init_ibconf(&new_conf); new_conf.settings.pad = pad; new_conf.settings.sad = my_sad; /* device address */ new_conf.settings.board = minor; /* board number */ new_conf.settings.eos = eosmode & 0xff; /* local eos modes */ new_conf.settings.eos_flags = eosmode & 0xff00; new_conf.settings.usec_timeout = timeout_to_usec(timo); if (eot) new_conf.settings.send_eoi = 1; else new_conf.settings.send_eoi = 0; new_conf.defaults = new_conf.settings; new_conf.is_interface = 0; new_conf.error_msg_disable = no_show_error; ud = my_ibdev(new_conf); if (ud < 0) return -1; // check for address conflicts with board addresses board = interfaceBoard(&new_conf); if (query_pad(board, &board_pad) < 0) { goto ibdev_err; } if (query_sad(board, &board_sad) < 0) { goto ibdev_err; } if (board_pad == pad) { fprintf(stderr,"ibdev: address conflict with board pad\n"); setIberr(EARG); goto ibdev_err; } return ud; ibdev_err: retval = close_gpib_handle(&new_conf); if (retval < 0) { if (!no_show_error) fprintf(stderr, "ibdev: cleanup failed\n"); sync_globals(); return -1; } release_descriptor(ud); sync_globals(); return -1; } int my_ibdev(ibConf_t new_conf) { int ud; ibConf_t *conf; ud = insert_descriptor(new_conf, -1); if (ud < 0) { if (!new_conf.error_msg_disable) fprintf(stderr, "libgpib: ibdev failed to get descriptor\n"); setIbsta(ERR); return -1; } conf = enter_library(ud); if (!conf) { exit_library(ud, 1); release_descriptor(ud); return -1; } // XXX do local lockout if appropriate exit_library(ud, 0); return ud; } lib/ibppc.c000066400000000000000000000127141507046215500130770ustar00rootroot00000000000000/*************************************************************************** lib/ibppc.c ------------------- begin : Oct 2002 copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int ppoll_configure_device(ibConf_t *conf, const Addr4882_t addressList[], int ppc_configuration) { uint8_t *cmd; int i; int retval; retval = is_cic(interfaceBoard(conf)); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } cmd = malloc(16 + 2 * numAddresses(addressList)); if (!cmd) { setIberr(EDVR); setIbcnt(ENOMEM); return -1; } i = create_send_setup(interfaceBoard(conf), addressList, cmd); cmd[i++] = PPC; cmd[i++] = ppc_configuration; retval = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i); free(cmd); cmd = NULL; if (retval < 0) return -1; return 0; } int device_ppc(ibConf_t *conf, int ppc_configuration) { Addr4882_t addressList[2]; addressList[0] = packAddress(conf->settings.pad, conf->settings.sad); addressList [1] = NOADDR; return ppoll_configure_device(conf, addressList, ppc_configuration); } int board_ppc(ibConf_t *conf, int ppc_configuration) { ibBoard_t *board; int retval; struct gpib_ppoll_config_ioctl cmd; board = interfaceBoard(conf); // check if we are in local ppoll configuration mode retval = query_local_ppoll_mode(board); if (retval < 0) return retval; if (retval == 0) { setIberr(ECAP); return -1; } retval = query_ppc(board); if (retval < 0) return retval; conf->settings.ppoll_config = retval; // store old value cmd.config = ppc_configuration; cmd.set_ist = 0; cmd.clear_ist = 0; retval = ioctl(board->fileno, IBPPC, &cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } return 0; } int internal_ibppc(ibConf_t *conf, int v) { static const int ppc_mask = 0xe0; int retval; if (v && (v & ppc_mask) != PPE) { fprintf(stderr, "libgpib: illegal parallel poll configuration\n"); setIberr(EARG); return -1; } if (!v || (v & PPC_DISABLE)) v = PPD; if (conf->is_interface) { retval = board_ppc(conf, v); if (retval < 0) return retval; } else { retval = device_ppc(conf, v); if (retval < 0) return retval; } setIberr(conf->settings.ppoll_config); conf->settings.ppoll_config = v; return 0; } int ibppc(int ud, int v) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); retval = internal_ibppc(conf, v); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } void PPollConfig(int boardID, Addr4882_t address, int dataLine, int lineSense) { ibConf_t *conf; int retval; int ppoll_config; Addr4882_t addressList[2]; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (!conf->is_interface) { setIberr(EDVR); exit_library(boardID, 1); return; } if (dataLine < 1 || dataLine > 8 || !addressIsValid(address) || address == NOADDR) { setIberr(EARG); exit_library(boardID, 1); return; } ppoll_config = PPE_byte(dataLine, lineSense); addressList[0] = address; addressList[1]= NOADDR; retval = ppoll_configure_device(conf, addressList, ppoll_config); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } void PPollUnconfig(int boardID, const Addr4882_t addressList[]) { ibConf_t *conf; uint8_t cmd; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (!conf->is_interface) { setIberr(EDVR); exit_library(boardID, 1); return; } if (!addressListIsValid(addressList)) { setIberr(EARG); exit_library(boardID, 1); return; } if (numAddresses(addressList)) { retval = ppoll_configure_device(conf, addressList, PPD); } else { cmd = PPU; retval = my_ibcmd(conf, conf->settings.usec_timeout, &cmd, 1); } if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } int internal_ibist(ibConf_t *conf, int ist) { int retval; struct gpib_ppoll_config_ioctl cmd; if (!conf->is_interface) { setIberr(EARG); return -1; } retval = query_ist(interfaceBoard(conf)); if (retval < 0) return retval; setIberr(retval); // set iberr to old ist value cmd.config = 0; cmd.set_ist = 0; cmd.clear_ist = 0; if (ist) cmd.set_ist = 1; else cmd.clear_ist = 1; retval = ioctl(interfaceBoard(conf)->fileno, IBPPC, &cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return -1; } return 0; } int ibist(int ud, int ist) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); retval = internal_ibist(conf, ist); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } lib/ibstop.c000066400000000000000000000036451507046215500133050ustar00rootroot00000000000000/*************************************************************************** lib/ibstop.c ------------------- copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int internal_ibstop(ibConf_t *conf) { int retval; pthread_mutex_lock(&conf->async.lock); if (!conf->async.in_progress) { pthread_mutex_unlock(&conf->async.lock); return 0; } retval = pthread_cancel(conf->async.thread); if (retval) { pthread_mutex_unlock(&conf->async.lock); return 0; } pthread_mutex_unlock(&conf->async.lock); retval = gpib_aio_join(&conf->async); if (retval) return -1; pthread_mutex_lock(&conf->async.lock); conf->async.in_progress = 0; pthread_mutex_unlock(&conf->async.lock); setIberr(conf->async.iberr); setIbcnt(conf->async.ibcntl); return 0; } int ibstop(int ud) { ibConf_t *conf; int retval; conf = general_enter_library(ud, 1, 1); if (!conf) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); retval = internal_ibstop(conf); if (retval < 0) return general_exit_library(ud, 1, 0, 0, 0, 0, 1); return general_exit_library(ud, conf->async.ibsta & ERR, 0, 0, 0, 0, 1); } lib/ibutil.c000066400000000000000000000331141507046215500132670ustar00rootroot00000000000000/*************************************************************************** lib/ibutil.c ------------------- copyright : (C) 2001,2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #define _GNU_SOURCE #include "ib_internal.h" #include #include #include #include #include #include "parse.h" ibConf_t *ibConfigs[GPIB_CONFIGS_LENGTH] = {NULL}; ibConf_t ibFindConfigs[FIND_CONFIGS_LENGTH]; int insert_descriptor(ibConf_t p, int ud) { int i; if (ud < 0) { for (i = GPIB_MAX_NUM_BOARDS; i < GPIB_CONFIGS_LENGTH; i++) { if (ibConfigs[ i ] == NULL) break; } if (i == GPIB_CONFIGS_LENGTH) { fprintf(stderr, "libgpib: out of room in ibConfigs[]\n"); setIberr(ETAB); return -1; } ud = i; } else { if (ud >= GPIB_CONFIGS_LENGTH) { fprintf(stderr, "libgpib: bug! tried to allocate past end if ibConfigs array\n"); setIberr(EDVR); setIbcnt(EINVAL); return -1; } if (ibConfigs[ud]) { fprintf(stderr, "libgpib: bug! tried to allocate board descriptor twice\n"); setIberr(EDVR); setIbcnt(EINVAL); return -1; } } ibConfigs[ud] = malloc(sizeof(ibConf_t)); if (ibConfigs[ud] == NULL) { fprintf(stderr, "libgpib: out of memory\n"); setIberr(EDVR); setIbcnt(ENOMEM); return -1; } /* put entry to the table */ *ibConfigs[ud] = p; return ud; } int release_descriptor(int ud) { if (ud >= GPIB_MAX_NUM_BOARDS && ud < GPIB_CONFIGS_LENGTH && ibConfigs[ud]) { // need to take more care to clean up before freeing XXX free(ibConfigs[ud]); ibConfigs[ud] = NULL; return 0; } return -1; } int setup_global_board_descriptors(void) { int i; int retval = 0; for (i = 0; i < FIND_CONFIGS_LENGTH; i++) { if (ibFindConfigs[i].is_interface && ibFindConfigs[i].settings.board >= 0 && ibFindConfigs[i].settings.board < GPIB_MAX_NUM_BOARDS) { if (insert_descriptor(ibFindConfigs[i], ibFindConfigs[i].settings.board) < 0) retval = -1; } } /* boards use handle 0 */ for (i = 0; i < GPIB_MAX_NUM_BOARDS; i++) if (ibConfigs[i]) ibConfigs[i]->handle = 0; return retval; } static pthread_mutex_t config_lock = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; static void gpib_atfork_prepare(void) { int i; for (i = 0; i < GPIB_CONFIGS_LENGTH; i++) if (ibConfigs[i]) { pthread_mutex_lock(&ibConfigs[i]->async.lock); pthread_mutex_lock(&ibConfigs[i]->async.join_lock); } pthread_mutex_lock(&config_lock); } static void gpib_atfork_parent(void) { int i; pthread_mutex_unlock(&config_lock); for (i = 0; i < GPIB_CONFIGS_LENGTH; i++) if (ibConfigs[i]) { pthread_mutex_unlock(&ibConfigs[i]->async.join_lock); pthread_mutex_unlock(&ibConfigs[i]->async.lock); } } static void gpib_atfork_child(void) { int i; pthread_mutex_init(&config_lock, NULL); for (i = 0; i < GPIB_CONFIGS_LENGTH; i++) if (ibConfigs[i]) { pthread_mutex_init(&ibConfigs[i]->async.join_lock, NULL); pthread_mutex_init(&ibConfigs[i]->async.lock, NULL); } } int ibParseConfigFile(int minor) { int retval = 0; static volatile int config_parsed = 0; static volatile int config_error = 0; char *filename, *envptr; ibBoard_t *board; ibConf_t *conf; struct gpib_board_info_ioctl info; pthread_mutex_lock(&config_lock); if (config_parsed) { pthread_mutex_unlock(&config_lock); return config_error; } envptr = getenv("IB_CONFIG"); if (envptr) filename = envptr; else filename = DEFAULT_CONFIG_FILE; retval = parse_gpib_conf(filename, ibFindConfigs, FIND_CONFIGS_LENGTH, ibBoard, GPIB_MAX_NUM_BOARDS ,minor); if (retval < 0) { setIberr(ECNF); pthread_mutex_unlock(&config_lock); return retval; } retval = setup_global_board_descriptors(); if (minor < 0) /* called from ibfind so interface entry must be present */ goto done; /* check whether parse_gpib_config created an interface entry and if so update the details set by gpib_config from driver */ conf = ibConfigs[minor]; if (conf->settings.pad == -1) { if (conf->settings.board != minor) { fprintf(stderr,"Inconsistent config detected board %d != minor %d\n", conf->settings.board, minor); setIberr(ECNF); retval = -1; goto done; } board = interfaceBoard(conf); retval = ibBoardOpen(board, 1); if (retval < 0) goto done; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); goto done; } ibBoardClose(board); conf->defaults.pad = info.pad; conf->defaults.sad = info.sad; conf->settings = conf->defaults; board->is_system_controller = info.is_system_controller; // fprintf(stderr, "updated config pad %d, sad %d, sc %d\n", // info.pad, info.sad, info.is_system_controller); } done: config_parsed = 1; config_error = retval; /* be extra safe about dealing with forks */ pthread_atfork(gpib_atfork_prepare, gpib_atfork_parent, gpib_atfork_child); pthread_mutex_unlock(&config_lock); return retval; } int ibFindDevIndex(const char *name) { int i; if (strcmp("", name) == 0) return -1; for (i = 0; i < FIND_CONFIGS_LENGTH; i++) { if (!strcmp(ibFindConfigs[i].name, name)) return i; } return -1; } static int ibCheckDescriptor(int ud) { if (ud < 0 || ud >= GPIB_CONFIGS_LENGTH || ibConfigs[ud] == NULL) { fprintf(stderr, "libgpib: invalid descriptor\n"); setIberr(EARG); return -1; } return 0; } void init_descriptor_settings(descriptor_settings_t *settings) { settings->pad = -1; settings->sad = -1; settings->board = -1; settings->usec_timeout = 3000000; settings->spoll_usec_timeout = 1000000; settings->ppoll_usec_timeout = 2; settings->eos = 0; settings->eos_flags = 0; settings->ppoll_config = 0; settings->send_eoi = 1; settings->local_lockout = 0; settings->readdr = 0; settings->send_unt_unl = 0; } void init_ibconf(ibConf_t *conf) { conf->handle = -1; memset(conf->name, 0, sizeof(conf->name)); init_descriptor_settings(&conf->defaults); init_descriptor_settings(&conf->settings); memset(conf->init_string, 0, sizeof(conf->init_string)); conf->flags = 0; init_async_op(&conf->async); conf->end = 0; conf->is_interface = 0; conf->board_is_open = 0; conf->has_lock = 0; conf->timed_out = 0; conf->error_msg_disable = 0; } int open_gpib_handle(ibConf_t *conf) { struct gpib_open_dev_ioctl open_cmd; int retval; ibBoard_t *board; if (conf->handle >= 0) return 0; board = interfaceBoard(conf); open_cmd.handle = 0; open_cmd.pad = conf->settings.pad; open_cmd.sad = conf->settings.sad; open_cmd.is_board = conf->is_interface; retval = ioctl(board->fileno, IBOPENDEV, &open_cmd); if (retval < 0) { if (!conf->error_msg_disable) fprintf(stderr, "libgpib: IBOPENDEV ioctl failed\n"); setIberr(EDVR); setIbcnt(errno); return retval; } conf->handle = open_cmd.handle; return 0; } int close_gpib_handle(ibConf_t *conf) { struct gpib_close_dev_ioctl close_cmd; int retval; ibBoard_t *board; if (conf->handle < 0) return 0; board = interfaceBoard(conf); close_cmd.handle = conf->handle; retval = ioctl(board->fileno, IBCLOSEDEV, &close_cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); return retval; } conf->handle = -1; return 0; } int lock_board_mutex(ibBoard_t *board) { static const int lock = 1; int retval; retval = ioctl(board->fileno, IBMUTEX, &lock); if (retval < 0) { fprintf(stderr, "libgpib: error locking board mutex!\n"); setIberr(EDVR); setIbcnt(errno); } return retval; } int unlock_board_mutex(ibBoard_t *board) { static const int unlock = 0; int retval; retval = ioctl(board->fileno, IBMUTEX, &unlock); if (retval < 0) { fprintf(stderr, "libgpib: error unlocking board mutex!\n"); setIberr(EDVR); setIbcnt(errno); } return retval; } int conf_lock_board(ibConf_t *conf) { ibBoard_t *board; int retval; board = interfaceBoard(conf); assert(conf->has_lock == 0); retval = lock_board_mutex(board); if (retval < 0) return retval; conf->has_lock = 1; return retval; } void conf_unlock_board(ibConf_t *conf) { ibBoard_t *board; int retval; board = interfaceBoard(conf); assert(conf->has_lock); conf->has_lock = 0; retval = unlock_board_mutex(board); assert(retval == 0); } ibConf_t * enter_library(int ud) { return general_enter_library(ud, 0, 0); } ibConf_t * general_enter_library(int ud, int no_lock_board, int ignore_eoip) { ibConf_t *conf; int retval; retval = ibParseConfigFile(ud); if (retval < 0) return NULL; setIberr(0); setIbcnt(0); if (ibCheckDescriptor(ud) < 0) return NULL; conf = ibConfigs[ud]; retval = conf_online(conf, 1); if (retval < 0) return NULL; conf->timed_out = 0; if (no_lock_board == 0) { if (ignore_eoip == 0) { pthread_mutex_lock(&conf->async.lock); if (conf->async.in_progress) { pthread_mutex_unlock(&conf->async.lock); setIberr(EOIP); return NULL; } pthread_mutex_unlock(&conf->async.lock); } retval = conf_lock_board(conf); if (retval < 0) return NULL; } return conf; } int ibstatus(ibConf_t *conf, int error, int clear_mask, int set_mask) { int status = 0; int retval; if (!error) { retval = my_wait(conf, 0, clear_mask, set_mask, &status); if (retval < 0) error = 1; } if (error) status |= ERR; if (conf->timed_out) status |= TIMO; if (conf->end) status |= END; setIbsta(status); return status; } int exit_library(int ud, int error) { return general_exit_library(ud, error, 0, 0, 0, 0, 0); } int general_exit_library(int ud, int error, int no_sync_globals, int no_update_ibsta, int status_clear_mask, int status_set_mask, int no_unlock_board) { ibConf_t *conf = ibConfigs[ ud ]; int status; if (ibCheckDescriptor(ud) < 0) { setIbsta(ERR); if (no_sync_globals == 0) sync_globals(); return ERR; } if (no_update_ibsta) status = ThreadIbsta(); else status = ibstatus(conf, error, status_clear_mask, status_set_mask); if (no_unlock_board == 0 && conf->has_lock) conf_unlock_board(conf); if (no_sync_globals == 0) sync_globals(); return status; } int extractPAD(Addr4882_t address) { int pad = address & 0xff; if (address == NOADDR) return ADDR_INVALID; if (pad < 0 || pad > gpib_addr_max) return ADDR_INVALID; return pad; } int extractSAD(Addr4882_t address) { int sad = (address >> 8) & 0xff; if (address == NOADDR) return ADDR_INVALID; if (sad == NO_SAD) return SAD_DISABLED; if ((sad & 0x60) == 0) return ADDR_INVALID; sad &= ~0x60; if (sad < 0 || sad > gpib_sad_max) return ADDR_INVALID; return sad; } Addr4882_t packAddress(unsigned int pad, int sad) { Addr4882_t address; address = 0; address |= pad & 0xff; if (sad >= 0) address |= ((sad | sad_offset) << 8) & 0xff00; return address; } int addressIsValid(Addr4882_t address) { if (address == NOADDR) return 1; if (extractPAD(address) == ADDR_INVALID || extractSAD(address) == ADDR_INVALID) { setIberr(EARG); return 0; } return 1; } int addressListIsValid(const Addr4882_t addressList[]) { int i; if (addressList == NULL) return 1; for (i = 0; addressList[i] != NOADDR; i++) { if (!addressIsValid(addressList[i])) { setIbcnt(i); return 0; } } return 1; } unsigned int numAddresses(const Addr4882_t addressList[]) { unsigned int count; if (addressList == NULL) return 0; count = 0; while (addressList[ count ] != NOADDR) count++; return count; } int is_cic(const ibBoard_t *board) { int retval; struct gpib_wait_ioctl cmd; cmd.usec_timeout = 0; cmd.wait_mask = 0; cmd.clear_mask = 0; cmd.set_mask = 0; cmd.pad = NOADDR; cmd.sad = NOADDR; cmd.handle = 0; cmd.ibsta = 0; retval = ioctl(board->fileno, IBWAIT, &cmd); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); // fprintf(stderr, "libgpib: error in is_cic()!\n"); return -1; } if (cmd.ibsta & CIC) return 1; return 0; } int is_system_controller(const ibBoard_t *board) { int retval; struct gpib_board_info_ioctl info; retval = ioctl(board->fileno, IBBOARD_INFO, &info); if (retval < 0) { setIberr(EDVR); setIbcnt(errno); // fprintf(stderr, "libgpib: error in is_system_controller()!\n"); return -1; } return info.is_system_controller; } const char* gpib_error_string(int error) { static const char* error_descriptions[] = { "EDVR 0: OS error", "ECIC 1: Board not controller in charge", "ENOL 2: No listeners", "EADR 3: Improper addressing", "EARG 4: Bad argument", "ESAC 5: Board not system controller", "EABO 6: Operation aborted", "ENEB 7: Non-existant board", "EDMA 8: DMA error", "libgpib: Unknown error code 9", "EOIP 10: IO operation in progress", "ECAP 11: Capability does not exist", "EFSO 12: File system error", "libgpib: Unknown error code 13", "EBUS 14: Bus error", "ESTB 15: Lost status byte", "ESRQ 16: Stuck service request", "ECNF 17: Configuration file error", "libgpib: Unknown error code 18", "libgpib: Unknown error code 19", "ETAB 20: Table problem", }; static const int max_error_code = ETAB; if (error < 0 || error > max_error_code) return "libgpib: Unknown error code"; return error_descriptions[error]; } lib/libgpib.pc.in000066400000000000000000000004521507046215500141730ustar00rootroot00000000000000######### pc.in ######## prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libgpib Description: Linux-GPIB the IEEE-488 card support package and measurement suite for LINUX Version: @VERSION@ Requires: Libs: -lgpib Cflags: -I${includedir} lib/local_lockout.c000066400000000000000000000037251507046215500146360ustar00rootroot00000000000000/*************************************************************************** lib/local_lockout.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" static int local_lockout(ibConf_t *conf, const Addr4882_t addressList[]) { uint8_t cmd; int retval; retval = InternalEnableRemote(conf, addressList); if (retval < 0) return retval; cmd = LLO; retval = my_ibcmd(conf, conf->settings.usec_timeout, &cmd, 1); if(retval < 0) return retval; return 0; } void SendLLO(int boardID) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = local_lockout(conf, NULL); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } void SetRWLS(int boardID, const Addr4882_t addressList[]) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (!numAddresses(addressList)) { setIberr(EARG); exit_library(boardID, 1); return; } retval = local_lockout(conf, addressList); if(retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } lib/parse.h000066400000000000000000000001111507046215500131050ustar00rootroot00000000000000#include "ibConfYacc.h" extern unsigned int findIndex; extern int bdid; lib/pass_control.c000066400000000000000000000042331507046215500145050ustar00rootroot00000000000000/*************************************************************************** lib/pass_control.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" int my_pass_control(ibConf_t *conf, unsigned int pad, int sad) { uint8_t cmd; int retval; int i; i = InternalReceiveSetup(conf, conf->settings.usec_timeout, packAddress(pad, sad)); cmd = TCT; retval = my_ibcmd(conf, conf->settings.usec_timeout, &cmd, i); if (retval < 0) return retval; retval = internal_ibgts(conf, 0); return 0; } int ibpct(int ud) { ibConf_t *conf; int retval; conf = enter_library(ud); if (!conf) return exit_library(ud, 1); if (conf->is_interface) { setIberr(EARG); return exit_library(ud, 1); } retval = my_pass_control(conf, conf->settings.pad, conf->settings.sad); if (retval < 0) return exit_library(ud, 1); return exit_library(ud, 0); } void PassControl(int boardID, Addr4882_t address) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } if (!addressIsValid(address)) { exit_library(boardID, 1); return; } if (!conf->is_interface) { setIberr(EARG); exit_library(boardID, 1); return; } retval = my_pass_control(conf, extractPAD(address), extractSAD(address)); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } lib/self_test.c000066400000000000000000000044321507046215500137700ustar00rootroot00000000000000/*************************************************************************** lib/self_test.c ------------------- copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ib_internal.h" #include int InternalTestSys(ibConf_t *conf, const Addr4882_t addressList[], short resultList[]) { unsigned int failure_count = 0; ibBoard_t *board; int retval; int i; if (!conf->is_interface) { setIberr(EDVR); return -1; } board = interfaceBoard(conf); retval = is_cic(board); if (retval <= 0) { if (retval == 0) setIberr(ECIC); return -1; } if (!addressListIsValid(addressList)) { setIberr(EARG); return -1; } if (!numAddresses(addressList)) { setIberr(EARG); return -1; } retval = InternalSendList(conf, addressList, "*TST?", 4, NLend); if (retval < 0) return retval; for (i = 0; i < numAddresses(addressList); i++) { char reply[16]; retval = InternalReceive(conf, addressList[i], reply, sizeof(reply) - 1, STOPend); if (retval < 0) return -1; reply[ThreadIbcnt()] = 0; resultList[ i ] = strtol(reply, NULL, 0); if (resultList[i]) failure_count++; } setIbcnt(failure_count); return 0; } void TestSys(int boardID, const Addr4882_t addressList[], short resultList[]) { ibConf_t *conf; int retval; conf = enter_library(boardID); if (!conf) { exit_library(boardID, 1); return; } retval = InternalTestSys(conf, addressList, resultList); if (retval < 0) { exit_library(boardID, 1); return; } exit_library(boardID, 0); } m4/000077500000000000000000000000001507046215500114035ustar00rootroot00000000000000m4/am-check-python-headers.m4000066400000000000000000000020171507046215500162450ustar00rootroot00000000000000dnl a macro to check for ability to create python extensions dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE]) dnl function also defines PYTHON_INCLUDES AC_DEFUN([AM_CHECK_PYTHON_HEADERS], [AC_REQUIRE([AM_PATH_PYTHON]) AC_MSG_CHECKING(for headers required to compile python extensions) dnl deduce PYTHON_INCLUDES py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"` py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"` PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION} -I${py_prefix}/include/python${PYTHON_VERSION}m" if test "$py_prefix" != "$py_exec_prefix"; then PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION} -I${py_prefix}/include/python${PYTHON_VERSION}m" fi AC_SUBST(PYTHON_INCLUDES) dnl check if the headers exist: save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include ]])],[dnl AC_MSG_RESULT(found) $1],[dnl AC_MSG_RESULT(not found) $2]) CPPFLAGS="$save_CPPFLAGS" ]) m4/ax_define_dir.m4000066400000000000000000000032521507046215500144270ustar00rootroot00000000000000# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_define_dir.html # =========================================================================== # # SYNOPSIS # # AX_DEFINE_DIR(VARNAME, DIR [, DESCRIPTION]) # # DESCRIPTION # # This macro sets VARNAME to the expansion of the DIR variable, taking # care of fixing up ${prefix} and such. # # VARNAME is then offered as both an output variable and a C preprocessor # symbol. # # Example: # # AX_DEFINE_DIR([DATADIR], [datadir], [Where data are placed to.]) # # LICENSE # # Copyright (c) 2008 Stepan Kasal # Copyright (c) 2008 Andreas Schwab # Copyright (c) 2008 Guido U. Draheim # Copyright (c) 2008 Alexandre Oliva # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 6 AU_ALIAS([AC_DEFINE_DIR], [AX_DEFINE_DIR]) AC_DEFUN([AX_DEFINE_DIR], [ prefix_NONE= exec_prefix_NONE= test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn dnl refers to ${prefix}. Thus we have to use `eval' twice. eval ax_define_dir="\"[$]$2\"" eval ax_define_dir="\"$ax_define_dir\"" AC_SUBST($1, "$ax_define_dir") AC_DEFINE_UNQUOTED($1, "$ax_define_dir", [$3]) test "$prefix_NONE" && prefix=NONE test "$exec_prefix_NONE" && exec_prefix=NONE ]) m4/tcl.m4000066400000000000000000003020701507046215500124310ustar00rootroot00000000000000#------------------------------------------------------------------------ # SC_PATH_TCLCONFIG -- # # Locate the tclConfig.sh file and perform a sanity check on # the Tcl compile flags # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --with-tcl=... # # Defines the following vars: # TCL_BIN_DIR Full path to the directory containing # the tclConfig.sh file #------------------------------------------------------------------------ AC_DEFUN([SC_PATH_TCLCONFIG], [ # # Ok, lets find the tcl configuration # First, look for one uninstalled. # the alternative search directory is invoked by --with-tcl # if test x"${no_tcl}" = x ; then # we reset no_tcl in case something fails here no_tcl=true AC_ARG_WITH(tcl, [ --with-tcl directory containing tcl configuration (tclConfig.sh)], with_tclconfig=${withval}) AC_MSG_CHECKING([for Tcl configuration]) AC_CACHE_VAL(ac_cv_c_tclconfig,[ # First check to see if --with-tcl was specified. if test x"${with_tclconfig}" != x ; then if test -f "${with_tclconfig}/tclConfig.sh" ; then ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)` else AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh]) fi fi # then check for a private Tcl installation if test x"${ac_cv_c_tclconfig}" = x ; then for i in \ ../tcl \ `ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \ ../../tcl \ `ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \ ../../../tcl \ `ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do if test -f "$i/unix/tclConfig.sh" ; then ac_cv_c_tclconfig=`(cd $i/unix; pwd)` break fi done fi # on Darwin, check in Framework installation locations if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then for i in `ls -d ~/Library/Frameworks 2>/dev/null` \ `ls -d /Library/Frameworks 2>/dev/null` \ `ls -d /Network/Library/Frameworks 2>/dev/null` \ `ls -d /System/Library/Frameworks 2>/dev/null` \ ; do if test -f "$i/Tcl.framework/tclConfig.sh" ; then ac_cv_c_tclconfig=`(cd $i/Tcl.framework; pwd)` break fi done fi # check in a few common install locations if test x"${ac_cv_c_tclconfig}" = x ; then for i in `ls -d ${libdir} 2>/dev/null` \ `ls -d ${exec_prefix}/lib 2>/dev/null` \ `ls -d ${prefix}/lib 2>/dev/null` \ `ls -d /usr/local/lib 2>/dev/null` \ `ls -d /usr/contrib/lib 2>/dev/null` \ `ls -d /usr/share/tcltk/tcl8.4 2>/dev/null` \ `ls -d /usr/lib64/ 2>/dev/null` \ `ls -d /usr/lib 2>/dev/null` \ ; do if test -f "$i/tclConfig.sh" ; then ac_cv_c_tclconfig=`(cd $i; pwd)` break fi done fi # check in a few other private locations if test x"${ac_cv_c_tclconfig}" = x ; then for i in \ ${srcdir}/../tcl \ `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do if test -f "$i/unix/tclConfig.sh" ; then ac_cv_c_tclconfig=`(cd $i/unix; pwd)` break fi done fi ]) if test x"${ac_cv_c_tclconfig}" = x ; then TCL_BIN_DIR="# no Tcl configs found" AC_MSG_WARN([Can't find Tcl configuration definitions]) else no_tcl= TCL_BIN_DIR=${ac_cv_c_tclconfig} AC_MSG_RESULT([found ${TCL_BIN_DIR}/tclConfig.sh]) fi fi ]) #------------------------------------------------------------------------ # SC_PATH_TKCONFIG -- # # Locate the tkConfig.sh file # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --with-tk=... # # Defines the following vars: # TK_BIN_DIR Full path to the directory containing # the tkConfig.sh file #------------------------------------------------------------------------ AC_DEFUN([SC_PATH_TKCONFIG], [ # # Ok, lets find the tk configuration # First, look for one uninstalled. # the alternative search directory is invoked by --with-tk # if test x"${no_tk}" = x ; then # we reset no_tk in case something fails here no_tk=true AC_ARG_WITH(tk, [ --with-tk directory containing tk configuration (tkConfig.sh)], with_tkconfig=${withval}) AC_MSG_CHECKING([for Tk configuration]) AC_CACHE_VAL(ac_cv_c_tkconfig,[ # First check to see if --with-tkconfig was specified. if test x"${with_tkconfig}" != x ; then if test -f "${with_tkconfig}/tkConfig.sh" ; then ac_cv_c_tkconfig=`(cd ${with_tkconfig}; pwd)` else AC_MSG_ERROR([${with_tkconfig} directory doesn't contain tkConfig.sh]) fi fi # then check for a private Tk library if test x"${ac_cv_c_tkconfig}" = x ; then for i in \ ../tk \ `ls -dr ../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../tk[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../tk[[8-9]].[[0-9]]* 2>/dev/null` \ ../../tk \ `ls -dr ../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../../tk[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../../tk[[8-9]].[[0-9]]* 2>/dev/null` \ ../../../tk \ `ls -dr ../../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ../../../tk[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ../../../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do if test -f "$i/unix/tkConfig.sh" ; then ac_cv_c_tkconfig=`(cd $i/unix; pwd)` break fi done fi # on Darwin, check in Framework installation locations if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tkconfig}" = x ; then for i in `ls -d ~/Library/Frameworks 2>/dev/null` \ `ls -d /Library/Frameworks 2>/dev/null` \ `ls -d /Network/Library/Frameworks 2>/dev/null` \ `ls -d /System/Library/Frameworks 2>/dev/null` \ ; do if test -f "$i/Tk.framework/tkConfig.sh" ; then ac_cv_c_tkconfig=`(cd $i/Tk.framework; pwd)` break fi done fi # check in a few common install locations if test x"${ac_cv_c_tkconfig}" = x ; then for i in `ls -d ${libdir} 2>/dev/null` \ `ls -d ${exec_prefix}/lib 2>/dev/null` \ `ls -d ${prefix}/lib 2>/dev/null` \ `ls -d /usr/local/lib 2>/dev/null` \ `ls -d /usr/contrib/lib 2>/dev/null` \ `ls -d /usr/share/tcltk/tk8.4 2>/dev/null` \ `ls -d /usr/lib 2>/dev/null` \ ; do if test -f "$i/tkConfig.sh" ; then ac_cv_c_tkconfig=`(cd $i; pwd)` break fi done fi # check in a few other private locations if test x"${ac_cv_c_tkconfig}" = x ; then for i in \ ${srcdir}/../tk \ `ls -dr ${srcdir}/../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \ `ls -dr ${srcdir}/../tk[[8-9]].[[0-9]] 2>/dev/null` \ `ls -dr ${srcdir}/../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do if test -f "$i/unix/tkConfig.sh" ; then ac_cv_c_tkconfig=`(cd $i/unix; pwd)` break fi done fi ]) if test x"${ac_cv_c_tkconfig}" = x ; then TK_BIN_DIR="# no Tk configs found" AC_MSG_WARN([Can't find Tk configuration definitions]) else no_tk= TK_BIN_DIR=${ac_cv_c_tkconfig} AC_MSG_RESULT([found ${TK_BIN_DIR}/tkConfig.sh]) fi fi ]) #------------------------------------------------------------------------ # SC_LOAD_TCLCONFIG -- # # Load the tclConfig.sh file # # Arguments: # # Requires the following vars to be set: # TCL_BIN_DIR # # Results: # # Subst the following vars: # TCL_BIN_DIR # TCL_SRC_DIR # TCL_LIB_FILE # #------------------------------------------------------------------------ AC_DEFUN([SC_LOAD_TCLCONFIG], [ AC_MSG_CHECKING([for existence of ${TCL_BIN_DIR}/tclConfig.sh]) if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then AC_MSG_RESULT([loading]) . ${TCL_BIN_DIR}/tclConfig.sh else AC_MSG_RESULT([could not find ${TCL_BIN_DIR}/tclConfig.sh]) fi # eval is required to do the TCL_DBGX substitution eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\"" eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\"" # If the TCL_BIN_DIR is the build directory (not the install directory), # then set the common variable name to the value of the build variables. # For example, the variable TCL_LIB_SPEC will be set to the value # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC # instead of TCL_BUILD_LIB_SPEC since it will work with both an # installed and uninstalled version of Tcl. if test -f ${TCL_BIN_DIR}/Makefile ; then TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC} TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC} TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH} elif test "`uname -s`" = "Darwin"; then # If Tcl was built as a framework, attempt to use the libraries # from the framework at the given location so that linking works # against Tcl.framework installed in an arbitary location. case ${TCL_DEFS} in *TCL_FRAMEWORK*) if test -f ${TCL_BIN_DIR}/${TCL_LIB_FILE}; then for i in "`cd ${TCL_BIN_DIR}; pwd`" \ "`cd ${TCL_BIN_DIR}/../..; pwd`"; do if test "`basename "$i"`" = "${TCL_LIB_FILE}.framework"; then TCL_LIB_SPEC="-F`dirname "$i"` -framework ${TCL_LIB_FILE}" break fi done fi if test -f ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}; then TCL_STUB_LIB_SPEC="-L${TCL_BIN_DIR} ${TCL_STUB_LIB_FLAG}" TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}" fi ;; esac fi # eval is required to do the TCL_DBGX substitution eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\"" eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\"" eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\"" eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\"" AC_SUBST(TCL_VERSION) AC_SUBST(TCL_PATCH_LEVEL) AC_SUBST(TCL_BIN_DIR) AC_SUBST(TCL_SRC_DIR) AC_SUBST(TCL_LIB_FILE) AC_SUBST(TCL_LIB_FLAG) AC_SUBST(TCL_LIB_SPEC) AC_SUBST(TCL_STUB_LIB_FILE) AC_SUBST(TCL_STUB_LIB_FLAG) AC_SUBST(TCL_STUB_LIB_SPEC) ]) #------------------------------------------------------------------------ # SC_LOAD_TKCONFIG -- # # Load the tkConfig.sh file # # Arguments: # # Requires the following vars to be set: # TK_BIN_DIR # # Results: # # Sets the following vars that should be in tkConfig.sh: # TK_BIN_DIR #------------------------------------------------------------------------ AC_DEFUN([SC_LOAD_TKCONFIG], [ AC_MSG_CHECKING([for existence of ${TK_BIN_DIR}/tkConfig.sh]) if test -f "${TK_BIN_DIR}/tkConfig.sh" ; then AC_MSG_RESULT([loading]) . ${TK_BIN_DIR}/tkConfig.sh else AC_MSG_RESULT([could not find ${TK_BIN_DIR}/tkConfig.sh]) fi # eval is required to do the TK_DBGX substitution eval "TK_LIB_FILE=\"${TK_LIB_FILE}\"" eval "TK_STUB_LIB_FILE=\"${TK_STUB_LIB_FILE}\"" # If the TK_BIN_DIR is the build directory (not the install directory), # then set the common variable name to the value of the build variables. # For example, the variable TK_LIB_SPEC will be set to the value # of TK_BUILD_LIB_SPEC. An extension should make use of TK_LIB_SPEC # instead of TK_BUILD_LIB_SPEC since it will work with both an # installed and uninstalled version of Tcl. if test -f ${TK_BIN_DIR}/Makefile ; then TK_LIB_SPEC=${TK_BUILD_LIB_SPEC} TK_STUB_LIB_SPEC=${TK_BUILD_STUB_LIB_SPEC} TK_STUB_LIB_PATH=${TK_BUILD_STUB_LIB_PATH} elif test "`uname -s`" = "Darwin"; then # If Tk was built as a framework, attempt to use the libraries # from the framework at the given location so that linking works # against Tk.framework installed in an arbitary location. case ${TK_DEFS} in *TK_FRAMEWORK*) if test -f ${TK_BIN_DIR}/${TK_LIB_FILE}; then for i in "`cd ${TK_BIN_DIR}; pwd`" \ "`cd ${TK_BIN_DIR}/../..; pwd`"; do if test "`basename "$i"`" = "${TK_LIB_FILE}.framework"; then TK_LIB_SPEC="-F`dirname "$i"` -framework ${TK_LIB_FILE}" break fi done fi if test -f ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}; then TK_STUB_LIB_SPEC="-L${TK_BIN_DIR} ${TK_STUB_LIB_FLAG}" TK_STUB_LIB_PATH="${TK_BIN_DIR}/${TK_STUB_LIB_FILE}" fi ;; esac fi # eval is required to do the TK_DBGX substitution eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}\"" eval "TK_LIB_SPEC=\"${TK_LIB_SPEC}\"" eval "TK_STUB_LIB_FLAG=\"${TK_STUB_LIB_FLAG}\"" eval "TK_STUB_LIB_SPEC=\"${TK_STUB_LIB_SPEC}\"" AC_SUBST(TK_VERSION) AC_SUBST(TK_BIN_DIR) AC_SUBST(TK_SRC_DIR) AC_SUBST(TK_LIB_FILE) AC_SUBST(TK_LIB_FLAG) AC_SUBST(TK_LIB_SPEC) AC_SUBST(TK_STUB_LIB_FILE) AC_SUBST(TK_STUB_LIB_FLAG) AC_SUBST(TK_STUB_LIB_SPEC) ]) #------------------------------------------------------------------------ # SC_PROG_TCLSH # Locate a tclsh shell installed on the system path. This macro # will only find a Tcl shell that already exists on the system. # It will not find a Tcl shell in the Tcl build directory or # a Tcl shell that has been installed from the Tcl build directory. # If a Tcl shell can't be located on the PATH, then TCLSH_PROG will # be set to "". Extensions should take care not to create Makefile # rules that are run by default and depend on TCLSH_PROG. An # extension can't assume that an executable Tcl shell exists at # build time. # # Arguments # none # # Results # Subst's the following values: # TCLSH_PROG #------------------------------------------------------------------------ AC_DEFUN([SC_PROG_TCLSH], [ AC_MSG_CHECKING([for tclsh]) AC_CACHE_VAL(ac_cv_path_tclsh, [ search_path=`echo ${PATH} | sed -e 's/:/ /g'` for dir in $search_path ; do for j in `ls -r $dir/tclsh[[8-9]]* 2> /dev/null` \ `ls -r $dir/tclsh* 2> /dev/null` ; do if test x"$ac_cv_path_tclsh" = x ; then if test -f "$j" ; then ac_cv_path_tclsh=$j break fi fi done done ]) if test -f "$ac_cv_path_tclsh" ; then TCLSH_PROG="$ac_cv_path_tclsh" AC_MSG_RESULT([$TCLSH_PROG]) else # It is not an error if an installed version of Tcl can't be located. TCLSH_PROG="" AC_MSG_RESULT([No tclsh found on PATH]) fi AC_SUBST(TCLSH_PROG) ]) #------------------------------------------------------------------------ # SC_BUILD_TCLSH # Determine the fully qualified path name of the tclsh executable # in the Tcl build directory. This macro will correctly determine # the name of the tclsh executable even if tclsh has not yet # been built in the build directory. The build tclsh must be used # when running tests from an extension build directory. It is not # correct to use the TCLSH_PROG in cases like this. # # Arguments # none # # Results # Subst's the following values: # BUILD_TCLSH #------------------------------------------------------------------------ AC_DEFUN([SC_BUILD_TCLSH], [ AC_MSG_CHECKING([for tclsh in Tcl build directory]) BUILD_TCLSH=${TCL_BIN_DIR}/tclsh AC_MSG_RESULT([$BUILD_TCLSH]) AC_SUBST(BUILD_TCLSH) ]) #------------------------------------------------------------------------ # SC_ENABLE_SHARED -- # # Allows the building of shared libraries # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --enable-shared=yes|no # # Defines the following vars: # STATIC_BUILD Used for building import/export libraries # on Windows. # # Sets the following vars: # SHARED_BUILD Value of 1 or 0 #------------------------------------------------------------------------ AC_DEFUN([SC_ENABLE_SHARED], [ AC_MSG_CHECKING([how to build libraries]) AC_ARG_ENABLE(shared, [ --enable-shared build and link with shared libraries [--enable-shared]], [tcl_ok=$enableval], [tcl_ok=yes]) if test "${enable_shared+set}" = set; then enableval="$enable_shared" tcl_ok=$enableval else tcl_ok=yes fi if test "$tcl_ok" = "yes" ; then AC_MSG_RESULT([shared]) SHARED_BUILD=1 else AC_MSG_RESULT([static]) SHARED_BUILD=0 AC_DEFINE(STATIC_BUILD) fi ]) #------------------------------------------------------------------------ # SC_ENABLE_FRAMEWORK -- # # Allows the building of shared libraries into frameworks # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --enable-framework=yes|no # # Sets the following vars: # FRAMEWORK_BUILD Value of 1 or 0 #------------------------------------------------------------------------ AC_DEFUN([SC_ENABLE_FRAMEWORK], [ if test "`uname -s`" = "Darwin" ; then AC_MSG_CHECKING([how to package libraries]) AC_ARG_ENABLE(framework, [ --enable-framework package shared libraries in MacOSX frameworks [--disable-framework]], [enable_framework=$enableval], [enable_framework=no]) if test $enable_framework = yes; then if test $SHARED_BUILD = 0; then AC_MSG_WARN([Frameworks can only be built if --enable-shared is yes]) enable_framework=no fi if test $tcl_corefoundation = no; then AC_MSG_WARN([Frameworks can only be used when CoreFoundation is available]) enable_framework=no fi fi if test $enable_framework = yes; then AC_MSG_RESULT([framework]) FRAMEWORK_BUILD=1 else if test $SHARED_BUILD = 1; then AC_MSG_RESULT([shared library]) else AC_MSG_RESULT([static library]) fi FRAMEWORK_BUILD=0 fi fi ]) #------------------------------------------------------------------------ # SC_ENABLE_THREADS -- # # Specify if thread support should be enabled. TCL_THREADS is # checked so that if you are compiling an extension against a # threaded core, your extension must be compiled threaded as well. # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --enable-threads # # Sets the following vars: # THREADS_LIBS Thread library(s) # # Defines the following vars: # TCL_THREADS # _REENTRANT # _THREAD_SAFE # #------------------------------------------------------------------------ AC_DEFUN([SC_ENABLE_THREADS], [ AC_ARG_ENABLE(threads, [ --enable-threads build with threads], [tcl_ok=$enableval], [tcl_ok=no]) if test "${TCL_THREADS}" = 1; then tcl_threaded_core=1; fi if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then TCL_THREADS=1 # USE_THREAD_ALLOC tells us to try the special thread-based # allocator that significantly reduces lock contention AC_DEFINE(USE_THREAD_ALLOC) AC_DEFINE(_REENTRANT) if test "`uname -s`" = "SunOS" ; then AC_DEFINE(_POSIX_PTHREAD_SEMANTICS) fi AC_DEFINE(_THREAD_SAFE) AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no) if test "$tcl_ok" = "no"; then # Check a little harder for __pthread_mutex_init in the same # library, as some systems hide it there until pthread.h is # defined. We could alternatively do an AC_TRY_COMPILE with # pthread.h, but that will work with libpthread really doesn't # exist, like AIX 4.2. [Bug: 4359] AC_CHECK_LIB(pthread, __pthread_mutex_init, tcl_ok=yes, tcl_ok=no) fi if test "$tcl_ok" = "yes"; then # The space is needed THREADS_LIBS=" -lpthread" else AC_CHECK_LIB(pthreads, pthread_mutex_init, tcl_ok=yes, tcl_ok=no) if test "$tcl_ok" = "yes"; then # The space is needed THREADS_LIBS=" -lpthreads" else AC_CHECK_LIB(c, pthread_mutex_init, tcl_ok=yes, tcl_ok=no) if test "$tcl_ok" = "no"; then AC_CHECK_LIB(c_r, pthread_mutex_init, tcl_ok=yes, tcl_ok=no) if test "$tcl_ok" = "yes"; then # The space is needed THREADS_LIBS=" -pthread" else TCL_THREADS=0 AC_MSG_WARN([Don't know how to find pthread lib on your system - you must disable thread support or edit the LIBS in the Makefile...]) fi fi fi fi # Does the pthread-implementation provide # 'pthread_attr_setstacksize' ? ac_saved_libs=$LIBS LIBS="$LIBS $THREADS_LIBS" AC_CHECK_FUNCS(pthread_attr_setstacksize) AC_CHECK_FUNCS(pthread_atfork) LIBS=$ac_saved_libs else TCL_THREADS=0 fi # Do checking message here to not mess up interleaved configure output AC_MSG_CHECKING([for building with threads]) if test "${TCL_THREADS}" = 1; then AC_DEFINE(TCL_THREADS, 1, [Are we building with threads enabled?]) if test "${tcl_threaded_core}" = 1; then AC_MSG_RESULT([yes (threaded core)]) else AC_MSG_RESULT([yes]) fi else AC_MSG_RESULT([no (default)]) fi AC_SUBST(TCL_THREADS) ]) #------------------------------------------------------------------------ # SC_ENABLE_SYMBOLS -- # # Specify if debugging symbols should be used. # Memory (TCL_MEM_DEBUG) and compile (TCL_COMPILE_DEBUG) debugging # can also be enabled. # # Arguments: # none # # Requires the following vars to be set in the Makefile: # CFLAGS_DEBUG # CFLAGS_OPTIMIZE # LDFLAGS_DEBUG # LDFLAGS_OPTIMIZE # # Results: # # Adds the following arguments to configure: # --enable-symbols # # Defines the following vars: # CFLAGS_DEFAULT Sets to $(CFLAGS_DEBUG) if true # Sets to $(CFLAGS_OPTIMIZE) if false # LDFLAGS_DEFAULT Sets to $(LDFLAGS_DEBUG) if true # Sets to $(LDFLAGS_OPTIMIZE) if false # DBGX Debug library extension # #------------------------------------------------------------------------ AC_DEFUN([SC_ENABLE_SYMBOLS], [ AC_MSG_CHECKING([for build with symbols]) AC_ARG_ENABLE(symbols, [ --enable-symbols build with debugging symbols [--disable-symbols]], [tcl_ok=$enableval], [tcl_ok=no]) # FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT. if test "$tcl_ok" = "no"; then CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)' LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)' DBGX="" AC_MSG_RESULT([no]) else CFLAGS_DEFAULT='$(CFLAGS_DEBUG)' LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)' DBGX=g if test "$tcl_ok" = "yes"; then AC_MSG_RESULT([yes (standard debugging)]) fi fi AC_SUBST(CFLAGS_DEFAULT) AC_SUBST(LDFLAGS_DEFAULT) if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then AC_DEFINE(TCL_MEM_DEBUG) fi if test "$tcl_ok" = "compile" -o "$tcl_ok" = "all"; then AC_DEFINE(TCL_COMPILE_DEBUG) AC_DEFINE(TCL_COMPILE_STATS) fi if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then if test "$tcl_ok" = "all"; then AC_MSG_RESULT([enabled symbols mem compile debugging]) else AC_MSG_RESULT([enabled $tcl_ok debugging]) fi fi ]) #------------------------------------------------------------------------ # SC_ENABLE_LANGINFO -- # # Allows use of modern nl_langinfo check for better l10n. # This is only relevant for Unix. # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --enable-langinfo=yes|no (default is yes) # # Defines the following vars: # HAVE_LANGINFO Triggers use of nl_langinfo if defined. # #------------------------------------------------------------------------ AC_DEFUN([SC_ENABLE_LANGINFO], [ AC_ARG_ENABLE(langinfo, [ --enable-langinfo use nl_langinfo if possible to determine encoding at startup, otherwise use old heuristic], [langinfo_ok=$enableval], [langinfo_ok=yes]) HAVE_LANGINFO=0 if test "$langinfo_ok" = "yes"; then AC_CHECK_HEADER(langinfo.h,[langinfo_ok=yes],[langinfo_ok=no]) fi AC_MSG_CHECKING([whether to use nl_langinfo]) if test "$langinfo_ok" = "yes"; then AC_CACHE_VAL(tcl_cv_langinfo_h, [ AC_TRY_COMPILE([#include ], [nl_langinfo(CODESET);], [tcl_cv_langinfo_h=yes],[tcl_cv_langinfo_h=no])]) AC_MSG_RESULT([$tcl_cv_langinfo_h]) if test $tcl_cv_langinfo_h = yes; then AC_DEFINE(HAVE_LANGINFO) fi else AC_MSG_RESULT([$langinfo_ok]) fi ]) #-------------------------------------------------------------------- # SC_CONFIG_MANPAGES # # Decide whether to use symlinks for linking the manpages, # whether to compress the manpages after installation, and # whether to add a package name suffix to the installed # manpages to avoidfile name clashes. # If compression is enabled also find out what file name suffix # the given compression program is using. # # Arguments: # none # # Results: # # Adds the following arguments to configure: # --enable-man-symlinks # --enable-man-compression=PROG # --enable-man-suffix[=STRING] # # Defines the following variable: # # MAN_FLAGS - The apropriate flags for installManPage # according to the user's selection. # #-------------------------------------------------------------------- AC_DEFUN([SC_CONFIG_MANPAGES], [ AC_MSG_CHECKING([whether to use symlinks for manpages]) AC_ARG_ENABLE(man-symlinks, [ --enable-man-symlinks use symlinks for the manpages], test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks", enableval="no") AC_MSG_RESULT([$enableval]) AC_MSG_CHECKING([whether to compress the manpages]) AC_ARG_ENABLE(man-compression, [ --enable-man-compression=PROG compress the manpages with PROG], [case $enableval in yes) AC_MSG_ERROR([missing argument to --enable-man-compression]);; no) ;; *) MAN_FLAGS="$MAN_FLAGS --compress $enableval";; esac], enableval="no") AC_MSG_RESULT([$enableval]) if test "$enableval" != "no"; then AC_MSG_CHECKING([for compressed file suffix]) touch TeST $enableval TeST Z=`ls TeST* | sed 's/^....//'` rm -f TeST* MAN_FLAGS="$MAN_FLAGS --extension $Z" AC_MSG_RESULT([$Z]) fi AC_MSG_CHECKING([whether to add a package name suffix for the manpages]) AC_ARG_ENABLE(man-suffix, [ --enable-man-suffix=STRING use STRING as a suffix to manpage file names (default: $1)], [case $enableval in yes) enableval="$1" MAN_FLAGS="$MAN_FLAGS --suffix $enableval";; no) ;; *) MAN_FLAGS="$MAN_FLAGS --suffix $enableval";; esac], enableval="no") AC_MSG_RESULT([$enableval]) AC_SUBST(MAN_FLAGS) ]) #-------------------------------------------------------------------- # SC_CONFIG_SYSTEM # # Determine what the system is (some things cannot be easily checked # on a feature-driven basis, alas). This can usually be done via the # "uname" command, but there are a few systems, like Next, where # this doesn't work. # # Arguments: # none # # Results: # Defines the following var: # # system - System/platform/version identification code. # #-------------------------------------------------------------------- AC_DEFUN([SC_CONFIG_SYSTEM], [ AC_CACHE_CHECK([system version], tcl_cv_sys_version, [ if test -f /usr/lib/NextStep/software_version; then tcl_cv_sys_version=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version` else tcl_cv_sys_version=`uname -s`-`uname -r` if test "$?" -ne 0 ; then AC_MSG_WARN([can't find uname command]) tcl_cv_sys_version=unknown else # Special check for weird MP-RAS system (uname returns weird # results, and the version is kept in special file). if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then tcl_cv_sys_version=MP-RAS-`awk '{print $[3]}' /etc/.relid` fi if test "`uname -s`" = "AIX" ; then tcl_cv_sys_version=AIX-`uname -v`.`uname -r` fi if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then tcl_cv_sys_version=NetBSD-Debian fi fi fi ]) system=$tcl_cv_sys_version ]) #-------------------------------------------------------------------- # SC_CONFIG_CFLAGS # # Try to determine the proper flags to pass to the compiler # for building shared libraries and other such nonsense. # # Arguments: # none # # Results: # # Defines and substitutes the following vars: # # DL_OBJS - Name of the object file that implements dynamic # loading for Tcl on this system. # DL_LIBS - Library file(s) to include in tclsh and other base # applications in order for the "load" command to work. # LDFLAGS - Flags to pass to the compiler when linking object # files into an executable application binary such # as tclsh. # LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib", # that tell the run-time dynamic linker where to look # for shared libraries such as libtcl.so. Depends on # the variable LIB_RUNTIME_DIR in the Makefile. Could # be the same as CC_SEARCH_FLAGS if ${CC} is used to link. # CC_SEARCH_FLAGS-Flags to pass to ${CC}, such as "-Wl,-rpath,/usr/local/tcl/lib", # that tell the run-time dynamic linker where to look # for shared libraries such as libtcl.so. Depends on # the variable LIB_RUNTIME_DIR in the Makefile. # MAKE_LIB - Command to execute to build the a library; # differs when building shared or static. # MAKE_STUB_LIB - # Command to execute to build a stub library. # INSTALL_LIB - Command to execute to install a library; # differs when building shared or static. # INSTALL_STUB_LIB - # Command to execute to install a stub library. # STLIB_LD - Base command to use for combining object files # into a static library. # SHLIB_CFLAGS - Flags to pass to cc when compiling the components # of a shared library (may request position-independent # code, among other things). # SHLIB_LD - Base command to use for combining object files # into a shared library. # SHLIB_LD_LIBS - Dependent libraries for the linker to scan when # creating shared libraries. This symbol typically # goes at the end of the "ld" commands that build # shared libraries. The value of the symbol is # "${LIBS}" if all of the dependent libraries should # be specified when creating a shared library. If # dependent libraries should not be specified (as on # SunOS 4.x, where they cause the link to fail, or in # general if Tcl and Tk aren't themselves shared # libraries), then this symbol has an empty string # as its value. # SHLIB_SUFFIX - Suffix to use for the names of dynamically loadable # extensions. An empty string means we don't know how # to use shared libraries on this platform. # TCL_SHLIB_LD_EXTRAS - Additional element which are added to SHLIB_LD_LIBS # TK_SHLIB_LD_EXTRAS for the build of Tcl and Tk, but not recorded in the # tclConfig.sh, since they are only used for the build # of Tcl and Tk. # Examples: MacOS X records the library version and # compatibility version in the shared library. But # of course the Tcl version of this is only used for Tcl. # LIB_SUFFIX - Specifies everything that comes after the "libfoo" # in a static or shared library name, using the $VERSION variable # to put the version in the right place. This is used # by platforms that need non-standard library names. # Examples: ${VERSION}.so.1.1 on NetBSD, since it needs # to have a version after the .so, and ${VERSION}.a # on AIX, since a shared library needs to have # a .a extension whereas shared objects for loadable # extensions have a .so extension. Defaults to # ${VERSION}${SHLIB_SUFFIX}. # TCL_NEEDS_EXP_FILE - # 1 means that an export file is needed to link to a # shared library. # TCL_EXP_FILE - The name of the installed export / import file which # should be used to link to the Tcl shared library. # Empty if Tcl is unshared. # TCL_BUILD_EXP_FILE - # The name of the built export / import file which # should be used to link to the Tcl shared library. # Empty if Tcl is unshared. # CFLAGS_DEBUG - # Flags used when running the compiler in debug mode # CFLAGS_OPTIMIZE - # Flags used when running the compiler in optimize mode # CFLAGS - Additional CFLAGS added as necessary (usually 64-bit) # #-------------------------------------------------------------------- AC_DEFUN([SC_CONFIG_CFLAGS], [ # Step 0.a: Enable 64 bit support? AC_MSG_CHECKING([if 64bit support is requested]) AC_ARG_ENABLE(64bit,[ --enable-64bit enable 64bit support (where applicable)], [do64bit=$enableval], [do64bit=no]) AC_MSG_RESULT([$do64bit]) # Step 0.b: Enable Solaris 64 bit VIS support? AC_MSG_CHECKING([if 64bit Sparc VIS support is requested]) AC_ARG_ENABLE(64bit-vis,[ --enable-64bit-vis enable 64bit Sparc VIS support], [do64bitVIS=$enableval], [do64bitVIS=no]) AC_MSG_RESULT([$do64bitVIS]) if test "$do64bitVIS" = "yes"; then # Force 64bit on with VIS do64bit=yes fi # Step 1: set the variable "system" to hold the name and version number # for the system. SC_CONFIG_SYSTEM # Step 2: check for existence of -ldl library. This is needed because # Linux can use either -ldl or -ldld for dynamic loading. AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no) # Require ranlib early so we can override it in special cases below. AC_REQUIRE([AC_PROG_RANLIB]) # Step 3: set configuration options based on system name and version. do64bit_ok=no LDFLAGS_ORIG="$LDFLAGS" TCL_EXPORT_FILE_SUFFIX="" UNSHARED_LIB_SUFFIX="" TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`' ECHO_VERSION='`echo ${VERSION}`' TCL_LIB_VERSIONS_OK=ok CFLAGS_DEBUG=-g CFLAGS_OPTIMIZE=-O if test "$GCC" = "yes" ; then CFLAGS_WARNING="-Wall -Wno-implicit-int -fno-strict-aliasing" else CFLAGS_WARNING="" fi TCL_NEEDS_EXP_FILE=0 TCL_BUILD_EXP_FILE="" TCL_EXP_FILE="" dnl FIXME: Replace AC_CHECK_PROG with AC_CHECK_TOOL once cross compiling is fixed. dnl AC_CHECK_TOOL(AR, ar) AC_CHECK_PROG(AR, ar, ar) if test "${AR}" = "" ; then AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.]) fi STLIB_LD='${AR} cr' LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" PLAT_OBJS="" PLAT_SRCS="" case $system in AIX-*) if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes" ; then # AIX requires the _r compiler when gcc isn't being used case "${CC}" in *_r) # ok ... ;; *) CC=${CC}_r ;; esac AC_MSG_RESULT([Using $CC for compiling with threads]) fi LIBS="$LIBS -lc" SHLIB_CFLAGS="" # Note: need the LIBS below, otherwise Tk won't find Tcl's # symbols when dynamically loaded into tclsh. SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" LD_LIBRARY_PATH_VAR="LIBPATH" # Check to enable 64-bit flags for compiler/linker on AIX 4+ if test "$do64bit" = "yes" -a "`uname -v`" -gt "3" ; then if test "$GCC" = "yes" ; then AC_MSG_WARN([64bit mode not supported with GCC on $system]) else do64bit_ok=yes CFLAGS="$CFLAGS -q64" LDFLAGS="$LDFLAGS -q64" RANLIB="${RANLIB} -X64" AR="${AR} -X64" SHLIB_LD_FLAGS="-b64" fi fi if test "`uname -m`" = "ia64" ; then # AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC SHLIB_LD="/usr/ccs/bin/ld -G -z text" # AIX-5 has dl* in libc.so DL_LIBS="" if test "$GCC" = "yes" ; then CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' else CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}' fi LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' else if test "$GCC" = "yes" ; then SHLIB_LD="gcc -shared" else SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry" fi SHLIB_LD="${TCL_SRC_DIR}/unix/ldAix ${SHLIB_LD} ${SHLIB_LD_FLAGS}" DL_LIBS="-ldl" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} TCL_NEEDS_EXP_FILE=1 TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.exp' fi # AIX v<=4.1 has some different flags than 4.2+ if test "$system" = "AIX-4.1" -o "`uname -v`" -lt "4" ; then LIBOBJS="$LIBOBJS tclLoadAix.o" DL_LIBS="-lld" fi # On AIX <=v4 systems, libbsd.a has to be linked in to support # non-blocking file IO. This library has to be linked in after # the MATH_LIBS or it breaks the pow() function. The way to # insure proper sequencing, is to add it to the tail of MATH_LIBS. # This library also supplies gettimeofday. # # AIX does not have a timezone field in struct tm. When the AIX # bsd library is used, the timezone global and the gettimeofday # methods are to be avoided for timezone deduction instead, we # deduce the timezone by comparing the localtime result on a # known GMT value. AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes, libbsd=no) if test $libbsd = yes; then MATH_LIBS="$MATH_LIBS -lbsd" AC_DEFINE(USE_DELTA_FOR_TZ) fi ;; BeOS*) SHLIB_CFLAGS="-fPIC" SHLIB_LD="${CC} -nostart" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" #----------------------------------------------------------- # Check for inet_ntoa in -lbind, for BeOS (which also needs # -lsocket, even if the network functions are in -lnet which # is always linked to, for compatibility. #----------------------------------------------------------- AC_CHECK_LIB(bind, inet_ntoa, [LIBS="$LIBS -lbind -lsocket"]) ;; BSD/OS-2.1*|BSD/OS-3*) SHLIB_CFLAGS="" SHLIB_LD="shlicc -r" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; BSD/OS-4.*) SHLIB_CFLAGS="-export-dynamic -fPIC" SHLIB_LD="cc -shared" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" LDFLAGS="$LDFLAGS -export-dynamic" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; dgux*) SHLIB_CFLAGS="-K PIC" SHLIB_LD="cc -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; HP-UX-*.11.*) # Use updated header definitions where possible AC_DEFINE(_XOPEN_SOURCE) # Use the XOPEN network library AC_DEFINE(_XOPEN_SOURCE_EXTENDED) # Use the XOPEN network library LIBS="$LIBS -lxnet" # Use the XOPEN network library if test "`uname -m`" = "ia64" ; then SHLIB_SUFFIX=".so" else SHLIB_SUFFIX=".sl" fi AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no) if test "$tcl_ok" = yes; then SHLIB_CFLAGS="+z" SHLIB_LD="ld -b" SHLIB_LD_LIBS='${LIBS}' DL_OBJS="tclLoadShl.o" DL_LIBS="-ldld" LDFLAGS="$LDFLAGS -Wl,-E" CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.' LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.' LD_LIBRARY_PATH_VAR="SHLIB_PATH" fi if test "$GCC" = "yes" ; then SHLIB_LD="gcc -shared" SHLIB_LD_LIBS='${LIBS}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc #CFLAGS="$CFLAGS +DAportable" # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = "yes" ; then if test "$GCC" = "yes" ; then hpux_arch=`${CC} -dumpmachine` case $hpux_arch in hppa64*) # 64-bit gcc in use. Fix flags for GNU ld. do64bit_ok=yes SHLIB_LD="${CC} -shared" SHLIB_LD_LIBS='${LIBS}' CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} ;; *) AC_MSG_WARN([64bit mode not supported with GCC on $system]) ;; esac else do64bit_ok=yes CFLAGS="$CFLAGS +DD64" LDFLAGS="$LDFLAGS +DD64" fi fi ;; HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*) SHLIB_SUFFIX=".sl" AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no) if test "$tcl_ok" = yes; then SHLIB_CFLAGS="+z" SHLIB_LD="ld -b" SHLIB_LD_LIBS="" DL_OBJS="tclLoadShl.o" DL_LIBS="-ldld" LDFLAGS="$LDFLAGS -Wl,-E" CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.' LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.' LD_LIBRARY_PATH_VAR="SHLIB_PATH" fi ;; IRIX-4.*) SHLIB_CFLAGS="-G 0" SHLIB_SUFFIX=".a" SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0" SHLIB_LD_LIBS='${LIBS}' DL_OBJS="tclLoadAout.o" DL_LIBS="" LDFLAGS="$LDFLAGS -Wl,-D,08000000" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}.a' ;; IRIX-5.*) SHLIB_CFLAGS="" SHLIB_LD="ld -shared -rdata_shared" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' ;; IRIX-6.*) SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' if test "$GCC" = "yes" ; then CFLAGS="$CFLAGS -mabi=n32" LDFLAGS="$LDFLAGS -mabi=n32" else case $system in IRIX-6.3) # Use to build 6.2 compatible binaries on 6.3. CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS" ;; *) CFLAGS="$CFLAGS -n32" ;; esac LDFLAGS="$LDFLAGS -n32" fi ;; IRIX64-6.*) SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = "yes" ; then if test "$GCC" = "yes" ; then AC_MSG_WARN([64bit mode not supported by gcc]) else do64bit_ok=yes SHLIB_LD="ld -64 -shared -rdata_shared" CFLAGS="$CFLAGS -64" LDFLAGS="$LDFLAGS -64" fi fi ;; Linux*|GNU*|NetBSD-Debian) SHLIB_CFLAGS="-fPIC" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" CFLAGS_OPTIMIZE=-O2 # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings # when you inline the string and math operations. Turn this off to # get rid of the warnings. #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES" # following line added by CW for Debian GNU/Linux TCL_SHLIB_LD_EXTRAS="-Wl,-soname,\${TCL_LIB_FILE}.0" if test "$have_dl" = yes; then SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}' DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" LDFLAGS="$LDFLAGS -Wl,--export-dynamic" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else AC_CHECK_HEADER(dld.h, [ SHLIB_LD="ld -shared" DL_OBJS="tclLoadDld.o" DL_LIBS="-ldld" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS=""]) fi if test "`uname -m`" = "alpha" ; then CFLAGS="$CFLAGS -mieee" fi if test $do64bit = yes; then AC_CACHE_CHECK([if compiler accepts -m64 flag], tcl_cv_cc_m64, [ hold_cflags=$CFLAGS CFLAGS="$CFLAGS -m64" AC_TRY_LINK(,, tcl_cv_cc_m64=yes, tcl_cv_cc_m64=no) CFLAGS=$hold_cflags]) if test $tcl_cv_cc_m64 = yes; then CFLAGS="$CFLAGS -m64" do64bit_ok=yes fi fi # The combo of gcc + glibc has a bug related # to inlining of functions like strtod(). The # -fno-builtin flag should address this problem # but it does not work. The -fno-inline flag # is kind of overkill but it works. # Disable inlining only when one of the # files in compat/*.c is being linked in. if test x"${LIBOBJS}" != x ; then CFLAGS="$CFLAGS -fno-inline" fi # XIM peeking works under XFree86. AC_DEFINE(PEEK_XCLOSEIM) ;; GNU*) SHLIB_CFLAGS="-fPIC" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" if test "$have_dl" = yes; then SHLIB_LD="${CC} -shared" DL_OBJS="" DL_LIBS="-ldl" LDFLAGS="$LDFLAGS -Wl,--export-dynamic" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" else AC_CHECK_HEADER(dld.h, [ SHLIB_LD="ld -shared" DL_OBJS="" DL_LIBS="-ldld" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS=""]) fi if test "`uname -m`" = "alpha" ; then CFLAGS="$CFLAGS -mieee" fi ;; Lynx*) SHLIB_CFLAGS="-fPIC" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" CFLAGS_OPTIMIZE=-02 SHLIB_LD="${CC} -shared " DL_OBJS="tclLoadDl.o" DL_LIBS="-mshared -ldl" LD_FLAGS="-Wl,--export-dynamic" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' ;; MP-RAS-02*) SHLIB_CFLAGS="-K PIC" SHLIB_LD="cc -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; MP-RAS-*) SHLIB_CFLAGS="-K PIC" SHLIB_LD="cc -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" LDFLAGS="$LDFLAGS -Wl,-Bexport" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; NetBSD-*|FreeBSD-[[1-2]].*) # Not available on all versions: check for include file. AC_CHECK_HEADER(dlfcn.h, [ # NetBSD/SPARC needs -fPIC, -fpic will not do. SHLIB_CFLAGS="-fPIC" SHLIB_LD="ld -Bshareable -x" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [ AC_EGREP_CPP(yes, [ #ifdef __ELF__ yes #endif ], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)]) if test $tcl_cv_ld_elf = yes; then SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so' else SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0' fi ], [ SHLIB_CFLAGS="" SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".a" DL_OBJS="tclLoadAout.o" DL_LIBS="" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' ]) # FreeBSD doesn't handle version numbers with dots. UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' TCL_LIB_VERSIONS_OK=nodots ;; OpenBSD-*) case `arch -s` in m88k|vax) SHLIB_CFLAGS="" SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".a" DL_OBJS="tclLoadAout.o" DL_LIBS="" LDFLAGS="" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' ;; *) # OpenBSD/SPARC[64] needs -fPIC, -fpic will not do. case `machine` in sparc|sparc64) SHLIB_CFLAGS="-fPIC";; *) SHLIB_CFLAGS="-fpic";; esac SHLIB_LD="${CC} -shared ${SHLIB_CFLAGS}" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0' AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [ AC_EGREP_CPP(yes, [ #ifdef __ELF__ yes #endif ], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)]) if test $tcl_cv_ld_elf = yes; then LDFLAGS=-Wl,-export-dynamic else LDFLAGS="" fi ;; esac # OpenBSD doesn't do version numbers with dots. UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' TCL_LIB_VERSIONS_OK=nodots ;; FreeBSD-*) # FreeBSD 3.* and greater have ELF. SHLIB_CFLAGS="-fPIC" SHLIB_LD="ld -Bshareable -x" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" LDFLAGS="$LDFLAGS -export-dynamic" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' if test "${TCL_THREADS}" = "1" ; then # The -pthread needs to go in the CFLAGS, not LIBS LIBS=`echo $LIBS | sed s/-pthread//` CFLAGS="$CFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread" fi case $system in FreeBSD-3.*) # FreeBSD-3 doesn't handle version numbers with dots. UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so' TCL_LIB_VERSIONS_OK=nodots ;; esac ;; Darwin-*) CFLAGS_OPTIMIZE="-Os" SHLIB_CFLAGS="-fno-common" # To avoid discrepancies between what headers configure sees during # preprocessing tests and compiling tests, move any -isysroot and # -mmacosx-version-min flags from CFLAGS to CPPFLAGS: CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \ awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \ if ([$]i~/^(isysroot|mmacosx-version-min)/) print "-"[$]i}'`" CFLAGS="`echo " ${CFLAGS}" | \ awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \ if (!([$]i~/^(isysroot|mmacosx-version-min)/)) print "-"[$]i}'`" if test $do64bit = yes; then case `arch` in ppc) AC_CACHE_CHECK([if compiler accepts -arch ppc64 flag], tcl_cv_cc_arch_ppc64, [ hold_cflags=$CFLAGS CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5" AC_TRY_LINK(,, tcl_cv_cc_arch_ppc64=yes, tcl_cv_cc_arch_ppc64=no) CFLAGS=$hold_cflags]) if test $tcl_cv_cc_arch_ppc64 = yes; then CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5" do64bit_ok=yes fi;; i386) AC_CACHE_CHECK([if compiler accepts -arch x86_64 flag], tcl_cv_cc_arch_x86_64, [ hold_cflags=$CFLAGS CFLAGS="$CFLAGS -arch x86_64" AC_TRY_LINK(,, tcl_cv_cc_arch_x86_64=yes, tcl_cv_cc_arch_x86_64=no) CFLAGS=$hold_cflags]) if test $tcl_cv_cc_arch_x86_64 = yes; then CFLAGS="$CFLAGS -arch x86_64" do64bit_ok=yes fi;; *) AC_MSG_WARN([Don't know how enable 64-bit on architecture `arch`]);; esac else # Check for combined 32-bit and 64-bit fat build echo "$CFLAGS " | grep -E -q -- '-arch (ppc64|x86_64) ' && \ echo "$CFLAGS " | grep -E -q -- '-arch (ppc|i386) ' && \ fat_32_64=yes fi SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS}' AC_CACHE_CHECK([if ld accepts -single_module flag], tcl_cv_ld_single_module, [ hold_ldflags=$LDFLAGS LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module" AC_TRY_LINK(, [int i;], tcl_cv_ld_single_module=yes, tcl_cv_ld_single_module=no) LDFLAGS=$hold_ldflags]) if test $tcl_cv_ld_single_module = yes; then SHLIB_LD="${SHLIB_LD} -Wl,-single_module" fi SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".dylib" DL_OBJS="tclLoadDyld.o" DL_LIBS="" # Don't use -prebind when building for Mac OS X 10.4 or later only: test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int([$]2)}'`" -lt 4 -a \ "`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int([$]2)}'`" -lt 4 && \ LDFLAGS="$LDFLAGS -prebind" LDFLAGS="$LDFLAGS -headerpad_max_install_names" AC_CACHE_CHECK([if ld accepts -search_paths_first flag], tcl_cv_ld_search_paths_first, [ hold_ldflags=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,-search_paths_first" AC_TRY_LINK(, [int i;], tcl_cv_ld_search_paths_first=yes, tcl_cv_ld_search_paths_first=no) LDFLAGS=$hold_ldflags]) if test $tcl_cv_ld_search_paths_first = yes; then LDFLAGS="$LDFLAGS -Wl,-search_paths_first" fi CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH" PLAT_OBJS=\$\(MAC\_OSX_OBJS\) PLAT_SRCS=\$\(MAC\_OSX_SRCS\) AC_MSG_CHECKING([whether to use CoreFoundation]) AC_ARG_ENABLE(corefoundation, [ --enable-corefoundation use CoreFoundation API [--enable-corefoundation]], [tcl_corefoundation=$enableval], [tcl_corefoundation=yes]) AC_MSG_RESULT([$tcl_corefoundation]) if test $tcl_corefoundation = yes; then AC_CACHE_CHECK([for CoreFoundation.framework], tcl_cv_lib_corefoundation, [ hold_libs=$LIBS if test "$fat_32_64" = yes; then for v in CFLAGS CPPFLAGS LDFLAGS; do # On Tiger there is no 64-bit CF, so remove 64-bit archs # from CFLAGS et al. while testing for presence of CF. # 64-bit CF is disabled in tclUnixPort.h if necessary. eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"' done; fi LIBS="$LIBS -framework CoreFoundation" AC_TRY_LINK([#include ], [CFBundleRef b = CFBundleGetMainBundle();], tcl_cv_lib_corefoundation=yes, tcl_cv_lib_corefoundation=no) if test "$fat_32_64" = yes; then for v in CFLAGS CPPFLAGS LDFLAGS; do eval $v'="$hold_'$v'"' done; fi; LIBS=$hold_libs]) if test $tcl_cv_lib_corefoundation = yes; then LIBS="$LIBS -framework CoreFoundation" AC_DEFINE(HAVE_COREFOUNDATION) else tcl_corefoundation=no fi if test "$fat_32_64" = yes -a $tcl_corefoundation = yes; then AC_CACHE_CHECK([for 64-bit CoreFoundation], tcl_cv_lib_corefoundation_64, [ for v in CFLAGS CPPFLAGS LDFLAGS; do eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"' done AC_TRY_LINK([#include ], [CFBundleRef b = CFBundleGetMainBundle();], tcl_cv_lib_corefoundation_64=yes, tcl_cv_lib_corefoundation_64=no) for v in CFLAGS CPPFLAGS LDFLAGS; do eval $v'="$hold_'$v'"' done]) if test $tcl_cv_lib_corefoundation_64 = no; then AC_DEFINE(NO_COREFOUNDATION_64) fi fi fi AC_DEFINE(MAC_OSX_TCL) ;; NEXTSTEP-*) SHLIB_CFLAGS="" SHLIB_LD="cc -nostdlib -r" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadNext.o" DL_LIBS="" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; OS/390-*) CFLAGS_OPTIMIZE="" # Optimizer is buggy AC_DEFINE(_OE_SOCKETS) # needed in sys/socket.h ;; OSF1-1.0|OSF1-1.1|OSF1-1.2) # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1 SHLIB_CFLAGS="" # Hack: make package name same as library name SHLIB_LD='ld -R -export $@:' SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadOSF.o" DL_LIBS="" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; OSF1-1.*) # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2 SHLIB_CFLAGS="-fPIC" if test "$SHARED_BUILD" = "1" ; then SHLIB_LD="ld -shared" else SHLIB_LD="ld -non_shared" fi SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; OSF1-V*) # Digital OSF/1 SHLIB_CFLAGS="" if test "$SHARED_BUILD" = "1" ; then SHLIB_LD='ld -shared -expect_unresolved "*"' else SHLIB_LD='ld -non_shared -expect_unresolved "*"' fi SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' if test "$GCC" = "yes" ; then CFLAGS="$CFLAGS -mieee" else CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" fi # see pthread_intro(3) for pthread support on osf1, k.furukawa if test "${TCL_THREADS}" = "1" ; then CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" LIBS=`echo $LIBS | sed s/-lpthreads//` if test "$GCC" = "yes" ; then LIBS="$LIBS -lpthread -lmach -lexc" else CFLAGS="$CFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread" fi fi ;; QNX-6*) # QNX RTP # This may work for all QNX, but it was only reported for v6. SHLIB_CFLAGS="-fPIC" SHLIB_LD="ld -Bshareable -x" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" # dlopen is in -lc on QNX DL_LIBS="" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; RISCos-*) SHLIB_CFLAGS="-G 0" SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0" SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".a" DL_OBJS="tclLoadAout.o" DL_LIBS="" LDFLAGS="$LDFLAGS -Wl,-D,08000000" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} ;; SCO_SV-3.2*) # Note, dlopen is available only on SCO 3.2.5 and greater. However, # this test works, since "uname -s" was non-standard in 3.2.4 and # below. if test "$GCC" = "yes" ; then SHLIB_CFLAGS="-fPIC -melf" LDFLAGS="$LDFLAGS -melf -Wl,-Bexport" else SHLIB_CFLAGS="-Kpic -belf" LDFLAGS="$LDFLAGS -belf -Wl,-Bexport" fi SHLIB_LD="ld -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; SINIX*5.4*) SHLIB_CFLAGS="-K PIC" SHLIB_LD="cc -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; SunOS-4*) SHLIB_CFLAGS="-PIC" SHLIB_LD="ld" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} # SunOS can't handle version numbers with dots in them in library # specs, like -ltcl7.5, so use -ltcl75 instead. Also, it # requires an extra version number at the end of .so file names. # So, the library has to have a name like libtcl75.so.1.0 SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0' UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a' TCL_LIB_VERSIONS_OK=nodots ;; SunOS-5.[[0-6]]) # Careful to not let 5.10+ fall into this case # Note: If _REENTRANT isn't defined, then Solaris # won't define thread-safe library routines. AC_DEFINE(_REENTRANT) AC_DEFINE(_POSIX_PTHREAD_SEMANTICS) SHLIB_CFLAGS="-KPIC" # Note: need the LIBS below, otherwise Tk won't find Tcl's # symbols when dynamically loaded into tclsh. SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" if test "$GCC" = "yes" ; then SHLIB_LD="$CC -shared" CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else SHLIB_LD="/usr/ccs/bin/ld -G -z text" CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi ;; SunOS-5*) # Note: If _REENTRANT isn't defined, then Solaris # won't define thread-safe library routines. AC_DEFINE(_REENTRANT) AC_DEFINE(_POSIX_PTHREAD_SEMANTICS) SHLIB_CFLAGS="-KPIC" # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = "yes" ; then arch=`isainfo` if test "$arch" = "sparcv9 sparc" ; then if test "$GCC" = "yes" ; then if test "`gcc -dumpversion | awk -F. '{print [$]1}'`" -lt "3" ; then AC_MSG_WARN([64bit mode not supported with GCC < 3.2 on $system]) else do64bit_ok=yes CFLAGS="$CFLAGS -m64 -mcpu=v9" LDFLAGS="$LDFLAGS -m64 -mcpu=v9" SHLIB_CFLAGS="-fPIC" fi else do64bit_ok=yes if test "$do64bitVIS" = "yes" ; then CFLAGS="$CFLAGS -xarch=v9a" LDFLAGS="$LDFLAGS -xarch=v9a" else CFLAGS="$CFLAGS -xarch=v9" LDFLAGS="$LDFLAGS -xarch=v9" fi # Solaris 64 uses this as well #LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64" fi elif test "$arch" = "amd64 i386" ; then if test "$GCC" = "yes" ; then AC_MSG_WARN([64bit mode not supported with GCC on $system]) else do64bit_ok=yes CFLAGS="$CFLAGS -xarch=amd64" LDFLAGS="$LDFLAGS -xarch=amd64" fi else AC_MSG_WARN([64bit mode not supported for $arch]) fi fi # Note: need the LIBS below, otherwise Tk won't find Tcl's # symbols when dynamically loaded into tclsh. SHLIB_LD_LIBS='${LIBS}' SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" if test "$GCC" = "yes" ; then SHLIB_LD="$CC -shared" CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "$do64bit_ok" = "yes" ; then # We need to specify -static-libgcc or we need to # add the path to the sparv9 libgcc. SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc" # for finding sparcv9 libgcc, get the regular libgcc # path, remove so name and append 'sparcv9' #v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..." #CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir" fi else case $system in SunOS-5.[[1-9]][[0-9]]*) SHLIB_LD='${CC} -G -z text ${LDFLAGS}';; *) SHLIB_LD="/usr/ccs/bin/ld -G -z text";; esac CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' fi ;; ULTRIX-4.*) SHLIB_CFLAGS="-G 0" SHLIB_SUFFIX=".a" SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0" SHLIB_LD_LIBS='${LIBS}' DL_OBJS="tclLoadAout.o" DL_LIBS="" LDFLAGS="$LDFLAGS -Wl,-D,08000000" CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "$GCC" != "yes" ; then CFLAGS="$CFLAGS -DHAVE_TZSET -std1" fi ;; UNIX_SV* | UnixWare-5*) SHLIB_CFLAGS="-KPIC" SHLIB_LD="cc -G" SHLIB_LD_LIBS="" SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="-ldl" # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers # that don't grok the -Bexport option. Test that it does. AC_CACHE_CHECK([for ld accepts -Bexport flag], tcl_cv_ld_Bexport, [ hold_ldflags=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,-Bexport" AC_TRY_LINK(, [int i;], tcl_cv_ld_Bexport=yes, tcl_cv_ld_Bexport=no) LDFLAGS=$hold_ldflags]) if test $tcl_cv_ld_Bexport = yes; then LDFLAGS="$LDFLAGS -Wl,-Bexport" fi CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; esac if test "$do64bit" = "yes" -a "$do64bit_ok" = "no" ; then AC_MSG_WARN([64bit support being disabled -- don't know magic for this platform]) fi dnl # Add any CPPFLAGS set in the environment to our CFLAGS, but delay doing so dnl # until the end of configure, as configure's compile and link tests use dnl # both CPPFLAGS and CFLAGS (unlike our compile and link) but configure's dnl # preprocessing tests use only CPPFLAGS. SC_CONFIG_COMMANDS_PRE([CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""]) # Step 4: If pseudo-static linking is in use (see K. B. Kenny, "Dynamic # Loading for Tcl -- What Became of It?". Proc. 2nd Tcl/Tk Workshop, # New Orleans, LA, Computerized Processes Unlimited, 1994), then we need # to determine which of several header files defines the a.out file # format (a.out.h, sys/exec.h, or sys/exec_aout.h). At present, we # support only a file format that is more or less version-7-compatible. # In particular, # - a.out files must begin with `struct exec'. # - the N_TXTOFF on the `struct exec' must compute the seek address # of the text segment # - The `struct exec' must contain a_magic, a_text, a_data, a_bss # and a_entry fields. # The following compilation should succeed if and only if either sys/exec.h # or a.out.h is usable for the purpose. # # Note that the modified COFF format used on MIPS Ultrix 4.x is usable; the # `struct exec' includes a second header that contains information that # duplicates the v7 fields that are needed. if test "x$DL_OBJS" = "xtclLoadAout.o" ; then AC_CACHE_CHECK([sys/exec.h], tcl_cv_sysexec_h, [ AC_TRY_COMPILE([#include ],[ struct exec foo; unsigned long seek; int flag; #if defined(__mips) || defined(mips) seek = N_TXTOFF (foo.ex_f, foo.ex_o); #else seek = N_TXTOFF (foo); #endif flag = (foo.a_magic == OMAGIC); return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry; ], tcl_cv_sysexec_h=usable, tcl_cv_sysexec_h=unusable)]) if test $tcl_cv_sysexec_h = usable; then AC_DEFINE(USE_SYS_EXEC_H) else AC_CACHE_CHECK([a.out.h], tcl_cv_aout_h, [ AC_TRY_COMPILE([#include ],[ struct exec foo; unsigned long seek; int flag; #if defined(__mips) || defined(mips) seek = N_TXTOFF (foo.ex_f, foo.ex_o); #else seek = N_TXTOFF (foo); #endif flag = (foo.a_magic == OMAGIC); return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry; ], tcl_cv_aout_h=usable, tcl_cv_aout_h=unusable)]) if test $tcl_cv_aout_h = usable; then AC_DEFINE(USE_A_OUT_H) else AC_CACHE_CHECK([sys/exec_aout.h], tcl_cv_sysexecaout_h, [ AC_TRY_COMPILE([#include ],[ struct exec foo; unsigned long seek; int flag; #if defined(__mips) || defined(mips) seek = N_TXTOFF (foo.ex_f, foo.ex_o); #else seek = N_TXTOFF (foo); #endif flag = (foo.a_midmag == OMAGIC); return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry; ], tcl_cv_sysexecaout_h=usable, tcl_cv_sysexecaout_h=unusable)]) if test $tcl_cv_sysexecaout_h = usable; then AC_DEFINE(USE_SYS_EXEC_AOUT_H) else DL_OBJS="" fi fi fi fi # Step 5: disable dynamic loading if requested via a command-line switch. AC_ARG_ENABLE(load, [ --disable-load disallow dynamic loading and "load" command], [tcl_ok=$enableval], [tcl_ok=yes]) if test "$tcl_ok" = "no"; then DL_OBJS="" fi if test "x$DL_OBJS" != "x" ; then BUILD_DLTEST="\$(DLTEST_TARGETS)" else echo "Can't figure out how to do dynamic loading or shared libraries" echo "on this system." SHLIB_CFLAGS="" SHLIB_LD="" SHLIB_SUFFIX="" DL_OBJS="tclLoadNone.o" DL_LIBS="" LDFLAGS="$LDFLAGS_ORIG" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" BUILD_DLTEST="" fi # If we're running gcc, then change the C flags for compiling shared # libraries to the right flags for gcc, instead of those for the # standard manufacturer compiler. if test "$DL_OBJS" != "tclLoadNone.o" ; then if test "$GCC" = "yes" ; then case $system in AIX-*) ;; BSD/OS*) ;; IRIX*) ;; NetBSD-*|FreeBSD-*|OpenBSD-*) ;; Darwin-*) ;; RISCos-*) ;; SCO_SV-3.2*) ;; ULTRIX-4.*) ;; *) SHLIB_CFLAGS="-fPIC" ;; esac fi fi if test "$SHARED_LIB_SUFFIX" = "" ; then SHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}${SHLIB_SUFFIX}' fi if test "$UNSHARED_LIB_SUFFIX" = "" ; then UNSHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}.a' fi if test "${SHARED_BUILD}" = "1" && test "${SHLIB_SUFFIX}" != "" ; then LIB_SUFFIX=${SHARED_LIB_SUFFIX} MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}' INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) $(LIB_INSTALL_DIR)/$(LIB_FILE)' else LIB_SUFFIX=${UNSHARED_LIB_SUFFIX} if test "$RANLIB" = "" ; then MAKE_LIB='$(STLIB_LD) [$]@ ${OBJS}' INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) $(LIB_INSTALL_DIR)/$(LIB_FILE)' else MAKE_LIB='${STLIB_LD} [$]@ ${OBJS} ; ${RANLIB} [$]@' INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) $(LIB_INSTALL_DIR)/$(LIB_FILE) ; (cd $(LIB_INSTALL_DIR) ; $(RANLIB) $(LIB_FILE))' fi dnl Not at all clear what this was doing in Tcl's configure.in dnl or why it was needed was needed. In any event, this sort of dnl things needs to be done in the big loop above. dnl REMOVE THIS BLOCK LATER! (mdejong) dnl case $system in dnl BSD/OS*) dnl ;; dnl AIX-[[1-4]].*) dnl ;; dnl *) dnl SHLIB_LD_LIBS="" dnl ;; dnl esac fi # Stub lib does not depend on shared/static configuration if test "$RANLIB" = "" ; then MAKE_STUB_LIB='${STLIB_LD} [$]@ ${STUB_LIB_OBJS}' INSTALL_STUB_LIB='$(INSTALL_LIBRARY) $(STUB_LIB_FILE) $(LIB_INSTALL_DIR)/$(STUB_LIB_FILE)' else MAKE_STUB_LIB='${STLIB_LD} [$]@ ${STUB_LIB_OBJS} ; ${RANLIB} [$]@' INSTALL_STUB_LIB='$(INSTALL_LIBRARY) $(STUB_LIB_FILE) $(LIB_INSTALL_DIR)/$(STUB_LIB_FILE) ; (cd $(LIB_INSTALL_DIR) ; $(RANLIB) $(STUB_LIB_FILE))' fi AC_SUBST(DL_LIBS) AC_SUBST(DL_OBJS) AC_SUBST(PLAT_OBJS) AC_SUBST(PLAT_SRCS) AC_SUBST(CFLAGS) AC_SUBST(CFLAGS_DEBUG) AC_SUBST(CFLAGS_OPTIMIZE) AC_SUBST(CFLAGS_WARNING) AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS_DEBUG) AC_SUBST(LDFLAGS_OPTIMIZE) AC_SUBST(CC_SEARCH_FLAGS) AC_SUBST(LD_SEARCH_FLAGS) AC_SUBST(STLIB_LD) AC_SUBST(SHLIB_LD) AC_SUBST(TCL_SHLIB_LD_EXTRAS) AC_SUBST(TK_SHLIB_LD_EXTRAS) AC_SUBST(SHLIB_LD_LIBS) AC_SUBST(SHLIB_CFLAGS) AC_SUBST(SHLIB_SUFFIX) AC_SUBST(MAKE_LIB) AC_SUBST(MAKE_STUB_LIB) AC_SUBST(INSTALL_LIB) AC_SUBST(INSTALL_STUB_LIB) AC_SUBST(RANLIB) ]) #-------------------------------------------------------------------- # SC_SERIAL_PORT # # Determine which interface to use to talk to the serial port. # Note that #include lines must begin in leftmost column for # some compilers to recognize them as preprocessor directives, # and some build environments have stdin not pointing at a # pseudo-terminal (usually /dev/null instead.) # # Arguments: # none # # Results: # # Defines only one of the following vars: # HAVE_SYS_MODEM_H # USE_TERMIOS # USE_TERMIO # USE_SGTTY # #-------------------------------------------------------------------- AC_DEFUN([SC_SERIAL_PORT], [ AC_CHECK_HEADERS(sys/modem.h) AC_CACHE_CHECK([termios vs. termio vs. sgtty], tcl_cv_api_serial, [ AC_TRY_RUN([ #include int main() { struct termios t; if (tcgetattr(0, &t) == 0) { cfsetospeed(&t, 0); t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB; return 0; } return 1; }], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no) if test $tcl_cv_api_serial = no ; then AC_TRY_RUN([ #include int main() { struct termio t; if (ioctl(0, TCGETA, &t) == 0) { t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB; return 0; } return 1; }], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no) fi if test $tcl_cv_api_serial = no ; then AC_TRY_RUN([ #include int main() { struct sgttyb t; if (ioctl(0, TIOCGETP, &t) == 0) { t.sg_ospeed = 0; t.sg_flags |= ODDP | EVENP | RAW; return 0; } return 1; }], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=no, tcl_cv_api_serial=no) fi if test $tcl_cv_api_serial = no ; then AC_TRY_RUN([ #include #include int main() { struct termios t; if (tcgetattr(0, &t) == 0 || errno == ENOTTY || errno == ENXIO || errno == EINVAL) { cfsetospeed(&t, 0); t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB; return 0; } return 1; }], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no) fi if test $tcl_cv_api_serial = no; then AC_TRY_RUN([ #include #include int main() { struct termio t; if (ioctl(0, TCGETA, &t) == 0 || errno == ENOTTY || errno == ENXIO || errno == EINVAL) { t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB; return 0; } return 1; }], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no) fi if test $tcl_cv_api_serial = no; then AC_TRY_RUN([ #include #include int main() { struct sgttyb t; if (ioctl(0, TIOCGETP, &t) == 0 || errno == ENOTTY || errno == ENXIO || errno == EINVAL) { t.sg_ospeed = 0; t.sg_flags |= ODDP | EVENP | RAW; return 0; } return 1; }], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=none, tcl_cv_api_serial=none) fi]) case $tcl_cv_api_serial in termios) AC_DEFINE(USE_TERMIOS);; termio) AC_DEFINE(USE_TERMIO);; sgtty) AC_DEFINE(USE_SGTTY);; esac ]) #-------------------------------------------------------------------- # SC_MISSING_POSIX_HEADERS # # Supply substitutes for missing POSIX header files. Special # notes: # - stdlib.h doesn't define strtol, strtoul, or # strtod insome versions of SunOS # - some versions of string.h don't declare procedures such # as strstr # # Arguments: # none # # Results: # # Defines some of the following vars: # NO_DIRENT_H # NO_ERRNO_H # NO_VALUES_H # HAVE_LIMITS_H or NO_LIMITS_H # NO_STDLIB_H # NO_STRING_H # NO_SYS_WAIT_H # NO_DLFCN_H # HAVE_UNISTD_H # HAVE_SYS_PARAM_H # # HAVE_STRING_H ? # #-------------------------------------------------------------------- AC_DEFUN([SC_MISSING_POSIX_HEADERS], [ AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h, [ AC_TRY_LINK([#include #include ], [ #ifndef _POSIX_SOURCE # ifdef __Lynx__ /* * Generate compilation error to make the test fail: Lynx headers * are only valid if really in the POSIX environment. */ missing_procedure(); # endif #endif DIR *d; struct dirent *entryPtr; char *p; d = opendir("foobar"); entryPtr = readdir(d); p = entryPtr->d_name; closedir(d); ], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no)]) if test $tcl_cv_dirent_h = no; then AC_DEFINE(NO_DIRENT_H) fi AC_CHECK_HEADER(errno.h, , [AC_DEFINE(NO_ERRNO_H)]) AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H)]) AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H)]) AC_CHECK_HEADER(limits.h, [AC_DEFINE(HAVE_LIMITS_H)], [AC_DEFINE(NO_LIMITS_H)]) AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0) AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0) AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0) AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0) if test $tcl_ok = 0; then AC_DEFINE(NO_STDLIB_H) fi AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0) AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0) AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0) # See also memmove check below for a place where NO_STRING_H can be # set and why. if test $tcl_ok = 0; then AC_DEFINE(NO_STRING_H) fi AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H)]) AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H)]) # OS/390 lacks sys/param.h (and doesn't need it, by chance). AC_HAVE_HEADERS(unistd.h sys/param.h) ]) #-------------------------------------------------------------------- # SC_PATH_X # # Locate the X11 header files and the X11 library archive. Try # the ac_path_x macro first, but if it doesn't find the X stuff # (e.g. because there's no xmkmf program) then check through # a list of possible directories. Under some conditions the # autoconf macro will return an include directory that contains # no include files, so double-check its result just to be safe. # # Arguments: # none # # Results: # # Sets the the following vars: # XINCLUDES # XLIBSW # #-------------------------------------------------------------------- AC_DEFUN([SC_PATH_X], [ AC_PATH_X not_really_there="" if test "$no_x" = ""; then if test "$x_includes" = ""; then AC_TRY_CPP([#include ], , not_really_there="yes") else if test ! -r $x_includes/X11/Intrinsic.h; then not_really_there="yes" fi fi fi if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then AC_MSG_CHECKING([for X11 header files]) found_xincludes="no" AC_TRY_CPP([#include ], found_xincludes="yes", found_xincludes="no") if test "$found_xincludes" = "no"; then dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/X11R6/include /usr/X11R5/include /usr/include/X11R5 /usr/include/X11R4 /usr/openwin/include /usr/X11/include /usr/sww/include" for i in $dirs ; do if test -r $i/X11/Intrinsic.h; then AC_MSG_RESULT([$i]) XINCLUDES=" -I$i" found_xincludes="yes" break fi done fi else if test "$x_includes" != ""; then XINCLUDES="-I$x_includes" found_xincludes="yes" fi fi if test found_xincludes = "no"; then AC_MSG_RESULT([couldn't find any!]) fi if test "$no_x" = yes; then AC_MSG_CHECKING([for X11 libraries]) XLIBSW=nope dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/X11R6/lib /usr/X11R5/lib /usr/lib/X11R5 /usr/lib/X11R4 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib" for i in $dirs ; do if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl; then AC_MSG_RESULT([$i]) XLIBSW="-L$i -lX11" x_libraries="$i" break fi done else if test "$x_libraries" = ""; then XLIBSW=-lX11 else XLIBSW="-L$x_libraries -lX11" fi fi if test "$XLIBSW" = nope ; then AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow) fi if test "$XLIBSW" = nope ; then AC_MSG_RESULT([could not find any! Using -lX11.]) XLIBSW=-lX11 fi ]) #-------------------------------------------------------------------- # SC_BLOCKING_STYLE # # The statements below check for systems where POSIX-style # non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented. # On these systems (mostly older ones), use the old BSD-style # FIONBIO approach instead. # # Arguments: # none # # Results: # # Defines some of the following vars: # HAVE_SYS_IOCTL_H # HAVE_SYS_FILIO_H # USE_FIONBIO # O_NONBLOCK # #-------------------------------------------------------------------- AC_DEFUN([SC_BLOCKING_STYLE], [ AC_CHECK_HEADERS(sys/ioctl.h) AC_CHECK_HEADERS(sys/filio.h) SC_CONFIG_SYSTEM AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O]) case $system in # There used to be code here to use FIONBIO under AIX. However, it # was reported that FIONBIO doesn't work under AIX 3.2.5. Since # using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO # code (JO, 5/31/97). OSF*) AC_DEFINE(USE_FIONBIO) AC_MSG_RESULT([FIONBIO]) ;; SunOS-4*) AC_DEFINE(USE_FIONBIO) AC_MSG_RESULT([FIONBIO]) ;; ULTRIX-4.*) AC_DEFINE(USE_FIONBIO) AC_MSG_RESULT([FIONBIO]) ;; *) AC_MSG_RESULT([O_NONBLOCK]) ;; esac ]) #-------------------------------------------------------------------- # SC_TIME_HANLDER # # Checks how the system deals with time.h, what time structures # are used on the system, and what fields the structures have. # # Arguments: # none # # Results: # # Defines some of the following vars: # USE_DELTA_FOR_TZ # HAVE_TM_GMTOFF # HAVE_TM_TZADJ # HAVE_TIMEZONE_VAR # #-------------------------------------------------------------------- AC_DEFUN([SC_TIME_HANDLER], [ AC_CHECK_HEADERS(sys/time.h) AC_HEADER_TIME AC_STRUCT_TIMEZONE AC_CHECK_FUNCS(gmtime_r localtime_r) AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [ AC_TRY_COMPILE([#include ], [struct tm tm; tm.tm_tzadj;], tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no)]) if test $tcl_cv_member_tm_tzadj = yes ; then AC_DEFINE(HAVE_TM_TZADJ) fi AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff, [ AC_TRY_COMPILE([#include ], [struct tm tm; tm.tm_gmtoff;], tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no)]) if test $tcl_cv_member_tm_gmtoff = yes ; then AC_DEFINE(HAVE_TM_GMTOFF) fi # # Its important to include time.h in this check, as some systems # (like convex) have timezone functions, etc. # AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long, [ AC_TRY_COMPILE([#include ], [extern long timezone; timezone += 1; exit (0);], tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no)]) if test $tcl_cv_timezone_long = yes ; then AC_DEFINE(HAVE_TIMEZONE_VAR) else # # On some systems (eg IRIX 6.2), timezone is a time_t and not a long. # AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time, [ AC_TRY_COMPILE([#include ], [extern time_t timezone; timezone += 1; exit (0);], tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no)]) if test $tcl_cv_timezone_time = yes ; then AC_DEFINE(HAVE_TIMEZONE_VAR) fi fi ]) #-------------------------------------------------------------------- # SC_BUGGY_STRTOD # # Under Solaris 2.4, strtod returns the wrong value for the # terminating character under some conditions. Check for this # and if the problem exists use a substitute procedure # "fixstrtod" (provided by Tcl) that corrects the error. # Also, on Compaq's Tru64 Unix 5.0, # strtod(" ") returns 0.0 instead of a failure to convert. # # Arguments: # none # # Results: # # Might defines some of the following vars: # strtod (=fixstrtod) # #-------------------------------------------------------------------- AC_DEFUN([SC_BUGGY_STRTOD], [ AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0) if test "$tcl_strtod" = 1; then AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[ AC_TRY_RUN([ extern double strtod(); int main() { char *infString="Inf", *nanString="NaN", *spaceString=" "; char *term; double value; value = strtod(infString, &term); if ((term != infString) && (term[-1] == 0)) { exit(1); } value = strtod(nanString, &term); if ((term != nanString) && (term[-1] == 0)) { exit(1); } value = strtod(spaceString, &term); if (term == (spaceString+1)) { exit(1); } exit(0); }], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy, tcl_cv_strtod_buggy=buggy)]) if test "$tcl_cv_strtod_buggy" = buggy; then LIBOBJS="$LIBOBJS fixstrtod.o" AC_DEFINE(strtod, fixstrtod) fi fi ]) #-------------------------------------------------------------------- # SC_TCL_LINK_LIBS # # Search for the libraries needed to link the Tcl shell. # Things like the math library (-lm) and socket stuff (-lsocket vs. # -lnsl) are dealt with here. # # Arguments: # Requires the following vars to be set in the Makefile: # DL_LIBS # LIBS # MATH_LIBS # # Results: # # Subst's the following var: # TCL_LIBS # MATH_LIBS # # Might append to the following vars: # LIBS # # Might define the following vars: # HAVE_NET_ERRNO_H # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_LINK_LIBS], [ #-------------------------------------------------------------------- # On a few very rare systems, all of the libm.a stuff is # already in libc.a. Set compiler flags accordingly. # Also, Linux requires the "ieee" library for math to work # right (and it must appear before "-lm"). #-------------------------------------------------------------------- AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm") AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"]) #-------------------------------------------------------------------- # Interactive UNIX requires -linet instead of -lsocket, plus it # needs net/errno.h to define the socket-related error codes. #-------------------------------------------------------------------- AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"]) AC_CHECK_HEADER(net/errno.h, [AC_DEFINE(HAVE_NET_ERRNO_H)]) #-------------------------------------------------------------------- # Check for the existence of the -lsocket and -lnsl libraries. # The order here is important, so that they end up in the right # order in the command line generated by make. Here are some # special considerations: # 1. Use "connect" and "accept" to check for -lsocket, and # "gethostbyname" to check for -lnsl. # 2. Use each function name only once: can't redo a check because # autoconf caches the results of the last check and won't redo it. # 3. Use -lnsl and -lsocket only if they supply procedures that # aren't already present in the normal libraries. This is because # IRIX 5.2 has libraries, but they aren't needed and they're # bogus: they goof up name resolution if used. # 4. On some SVR4 systems, can't use -lsocket without -lnsl too. # To get around this problem, check for both libraries together # if -lsocket doesn't work by itself. #-------------------------------------------------------------------- tcl_checkBoth=0 AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1) if test "$tcl_checkSocket" = 1; then AC_CHECK_FUNC(setsockopt, , [AC_CHECK_LIB(socket, setsockopt, LIBS="$LIBS -lsocket", tcl_checkBoth=1)]) fi if test "$tcl_checkBoth" = 1; then tk_oldLibs=$LIBS LIBS="$LIBS -lsocket -lnsl" AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs]) fi AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname, [LIBS="$LIBS -lnsl"])]) # Don't perform the eval of the libraries here because DL_LIBS # won't be set until we call SC_CONFIG_CFLAGS TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}' AC_SUBST(TCL_LIBS) AC_SUBST(MATH_LIBS) ]) #-------------------------------------------------------------------- # SC_TCL_EARLY_FLAGS # # Check for what flags are needed to be passed so the correct OS # features are available. # # Arguments: # None # # Results: # # Might define the following vars: # _ISOC99_SOURCE # _LARGEFILE64_SOURCE # _LARGEFILE_SOURCE64 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_EARLY_FLAG],[ AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]), AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no, AC_TRY_COMPILE([[#define ]$1[ 1 ]$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no))) if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then AC_DEFINE($1) tcl_flags="$tcl_flags $1" fi ]) AC_DEFUN([SC_TCL_EARLY_FLAGS],[ AC_MSG_CHECKING([for required early compiler flags]) tcl_flags="" SC_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include ], [char *p = (char *)strtoll; char *q = (char *)strtoull;]) SC_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include ], [struct stat64 buf; int i = stat64("/", &buf);]) SC_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include ], [char *p = (char *)open64;]) if test "x${tcl_flags}" = "x" ; then AC_MSG_RESULT([none]) else AC_MSG_RESULT([${tcl_flags}]) fi ]) #-------------------------------------------------------------------- # SC_TCL_64BIT_FLAGS # # Check for what is defined in the way of 64-bit features. # # Arguments: # None # # Results: # # Might define the following vars: # TCL_WIDE_INT_IS_LONG # TCL_WIDE_INT_TYPE # HAVE_STRUCT_DIRENT64 # HAVE_STRUCT_STAT64 # HAVE_TYPE_OFF64_T # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_64BIT_FLAGS], [ AC_MSG_CHECKING([for 64-bit integer type]) AC_CACHE_VAL(tcl_cv_type_64bit,[ tcl_cv_type_64bit=none # See if the compiler knows natively about __int64 AC_TRY_COMPILE(,[__int64 value = (__int64) 0;], tcl_type_64bit=__int64, tcl_type_64bit="long long") # See if we should use long anyway Note that we substitute in the # type that is our current guess for a 64-bit type inside this check # program, so it should be modified only carefully... AC_TRY_COMPILE(,[switch (0) { case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ; }],tcl_cv_type_64bit=${tcl_type_64bit})]) if test "${tcl_cv_type_64bit}" = none ; then AC_DEFINE(TCL_WIDE_INT_IS_LONG) AC_MSG_RESULT([using long]) else AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit}) AC_MSG_RESULT([${tcl_cv_type_64bit}]) # Now check for auxiliary declarations AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[ AC_TRY_COMPILE([#include #include ],[struct dirent64 p;], tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)]) if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then AC_DEFINE(HAVE_STRUCT_DIRENT64) fi AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[ AC_TRY_COMPILE([#include ],[struct stat64 p; ], tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)]) if test "x${tcl_cv_struct_stat64}" = "xyes" ; then AC_DEFINE(HAVE_STRUCT_STAT64) fi AC_CHECK_FUNCS(open64 lseek64) AC_MSG_CHECKING([for off64_t]) AC_CACHE_VAL(tcl_cv_type_off64_t,[ AC_TRY_COMPILE([#include ],[off64_t offset; ], tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)]) dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the dnl functions lseek64 and open64 are defined. if test "x${tcl_cv_type_off64_t}" = "xyes" && \ test "x${ac_cv_func_lseek64}" = "xyes" && \ test "x${ac_cv_func_open64}" = "xyes" ; then AC_DEFINE(HAVE_TYPE_OFF64_T) AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) fi fi ]) #-------------------------------------------------------------------- # SC_TCL_GETHOSTBYADDR_R # # Check if we have MT-safe variant of gethostbyaddr(). # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETHOSTBYADDR_R # HAVE_GETHOSTBYADDR_R_7 # HAVE_GETHOSTBYADDR_R_8 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETHOSTBYADDR_R], [AC_CHECK_FUNC(gethostbyaddr_r, [ AC_CACHE_CHECK([for gethostbyaddr_r with 7 args], tcl_cv_api_gethostbyaddr_r_7, [ AC_TRY_COMPILE([ #include ], [ char *addr; int length; int type; struct hostent *result; char buffer[2048]; int buflen = 2048; int h_errnop; (void) gethostbyaddr_r(addr, length, type, result, buffer, buflen, &h_errnop); ], tcl_cv_api_gethostbyaddr_r_7=yes, tcl_cv_api_gethostbyaddr_r_7=no)]) tcl_ok=$tcl_cv_api_gethostbyaddr_r_7 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYADDR_R_7) else AC_CACHE_CHECK([for gethostbyaddr_r with 8 args], tcl_cv_api_gethostbyaddr_r_8, [ AC_TRY_COMPILE([ #include ], [ char *addr; int length; int type; struct hostent *result, *resultp; char buffer[2048]; int buflen = 2048; int h_errnop; (void) gethostbyaddr_r(addr, length, type, result, buffer, buflen, &resultp, &h_errnop); ], tcl_cv_api_gethostbyaddr_r_8=yes, tcl_cv_api_gethostbyaddr_r_8=no)]) tcl_ok=$tcl_cv_api_gethostbyaddr_r_8 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYADDR_R_8) fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYADDR_R) fi ])]) #-------------------------------------------------------------------- # SC_TCL_GETHOSTBYNAME_R # # Check to see what variant of gethostbyname_r() we have. # Based on David Arnold's example from the comp.programming.threads # FAQ Q213 # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETHOSTBYADDR_R # HAVE_GETHOSTBYADDR_R_3 # HAVE_GETHOSTBYADDR_R_5 # HAVE_GETHOSTBYADDR_R_6 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETHOSTBYNAME_R], [AC_CHECK_FUNC(gethostbyname_r, [ AC_CACHE_CHECK([for gethostbyname_r with 6 args], tcl_cv_api_gethostbyname_r_6, [ AC_TRY_COMPILE([ #include ], [ char *name; struct hostent *he, *res; char buffer[2048]; int buflen = 2048; int h_errnop; (void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop); ], tcl_cv_api_gethostbyname_r_6=yes, tcl_cv_api_gethostbyname_r_6=no)]) tcl_ok=$tcl_cv_api_gethostbyname_r_6 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYNAME_R_6) else AC_CACHE_CHECK([for gethostbyname_r with 5 args], tcl_cv_api_gethostbyname_r_5, [ AC_TRY_COMPILE([ #include ], [ char *name; struct hostent *he; char buffer[2048]; int buflen = 2048; int h_errnop; (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop); ], tcl_cv_api_gethostbyname_r_5=yes, tcl_cv_api_gethostbyname_r_5=no)]) tcl_ok=$tcl_cv_api_gethostbyname_r_5 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYNAME_R_5) else AC_CACHE_CHECK([for gethostbyname_r with 3 args], tcl_cv_api_gethostbyname_r_3, [ AC_TRY_COMPILE([ #include ], [ char *name; struct hostent *he; struct hostent_data data; (void) gethostbyname_r(name, he, &data); ], tcl_cv_api_gethostbyname_r_3=yes, tcl_cv_api_gethostbyname_r_3=no)]) tcl_ok=$tcl_cv_api_gethostbyname_r_3 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYNAME_R_3) fi fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETHOSTBYNAME_R) fi ])]) #-------------------------------------------------------------------- # SC_TCL_GETPWUID_R # # Check if we have MT-safe variant of getpwuid() and if yes, # which one exactly. # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETPWUID_R # HAVE_GETPWUID_R_4 # HAVE_GETPWUID_R_5 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETPWUID_R], [AC_CHECK_FUNC(getpwuid_r, [ AC_CACHE_CHECK([for getpwuid_r with 5 args], tcl_cv_api_getpwuid_r_5, [ AC_TRY_COMPILE([ #include #include ], [ uid_t uid; struct passwd pw, *pwp; char buf[512]; int buflen = 512; (void) getpwuid_r(uid, &pw, buf, buflen, &pwp); ], tcl_cv_api_getpwuid_r_5=yes, tcl_cv_api_getpwuid_r_5=no)]) tcl_ok=$tcl_cv_api_getpwuid_r_5 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWUID_R_5) else AC_CACHE_CHECK([for getpwuid_r with 4 args], tcl_cv_api_getpwuid_r_4, [ AC_TRY_COMPILE([ #include #include ], [ uid_t uid; struct passwd pw; char buf[512]; int buflen = 512; (void)getpwnam_r(uid, &pw, buf, buflen); ], tcl_cv_api_getpwuid_r_4=yes, tcl_cv_api_getpwuid_r_4=no)]) tcl_ok=$tcl_cv_api_getpwuid_r_4 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWUID_R_4) fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWUID_R) fi ])]) #-------------------------------------------------------------------- # SC_TCL_GETPWNAM_R # # Check if we have MT-safe variant of getpwnam() and if yes, # which one exactly. # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETPWNAM_R # HAVE_GETPWNAM_R_4 # HAVE_GETPWNAM_R_5 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETPWNAM_R], [AC_CHECK_FUNC(getpwnam_r, [ AC_CACHE_CHECK([for getpwnam_r with 5 args], tcl_cv_api_getpwnam_r_5, [ AC_TRY_COMPILE([ #include #include ], [ char *name; struct passwd pw, *pwp; char buf[512]; int buflen = 512; (void) getpwnam_r(name, &pw, buf, buflen, &pwp); ], tcl_cv_api_getpwnam_r_5=yes, tcl_cv_api_getpwnam_r_5=no)]) tcl_ok=$tcl_cv_api_getpwnam_r_5 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWNAM_R_5) else AC_CACHE_CHECK([for getpwnam_r with 4 args], tcl_cv_api_getpwnam_r_4, [ AC_TRY_COMPILE([ #include #include ], [ char *name; struct passwd pw; char buf[512]; int buflen = 512; (void)getpwnam_r(name, &pw, buf, buflen); ], tcl_cv_api_getpwnam_r_4=yes, tcl_cv_api_getpwnam_r_4=no)]) tcl_ok=$tcl_cv_api_getpwnam_r_4 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWNAM_R_4) fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETPWNAM_R) fi ])]) #-------------------------------------------------------------------- # SC_TCL_GETGRGID_R # # Check if we have MT-safe variant of getgrgid() and if yes, # which one exactly. # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETGRGID_R # HAVE_GETGRGID_R_4 # HAVE_GETGRGID_R_5 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETGRGID_R], [AC_CHECK_FUNC(getgrgid_r, [ AC_CACHE_CHECK([for getgrgid_r with 5 args], tcl_cv_api_getgrgid_r_5, [ AC_TRY_COMPILE([ #include #include ], [ gid_t gid; struct group gr, *grp; char buf[512]; int buflen = 512; (void) getgrgid_r(gid, &gr, buf, buflen, &grp); ], tcl_cv_api_getgrgid_r_5=yes, tcl_cv_api_getgrgid_r_5=no)]) tcl_ok=$tcl_cv_api_getgrgid_r_5 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRGID_R_5) else AC_CACHE_CHECK([for getgrgid_r with 4 args], tcl_cv_api_getgrgid_r_4, [ AC_TRY_COMPILE([ #include #include ], [ gid_t gid; struct group gr; char buf[512]; int buflen = 512; (void)getgrgid_r(gid, &gr, buf, buflen); ], tcl_cv_api_getgrgid_r_4=yes, tcl_cv_api_getgrgid_r_4=no)]) tcl_ok=$tcl_cv_api_getgrgid_r_4 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRGID_R_4) fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRGID_R) fi ])]) #-------------------------------------------------------------------- # SC_TCL_GETGRNAM_R # # Check if we have MT-safe variant of getgrnam() and if yes, # which one exactly. # # Arguments: # None # # Results: # # Might define the following vars: # HAVE_GETGRNAM_R # HAVE_GETGRNAM_R_4 # HAVE_GETGRNAM_R_5 # #-------------------------------------------------------------------- AC_DEFUN([SC_TCL_GETGRNAM_R], [AC_CHECK_FUNC(getgrnam_r, [ AC_CACHE_CHECK([for getgrnam_r with 5 args], tcl_cv_api_getgrnam_r_5, [ AC_TRY_COMPILE([ #include #include ], [ char *name; struct group gr, *grp; char buf[512]; int buflen = 512; (void) getgrnam_r(name, &gr, buf, buflen, &grp); ], tcl_cv_api_getgrnam_r_5=yes, tcl_cv_api_getgrnam_r_5=no)]) tcl_ok=$tcl_cv_api_getgrnam_r_5 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRNAM_R_5) else AC_CACHE_CHECK([for getgrnam_r with 4 args], tcl_cv_api_getgrnam_r_4, [ AC_TRY_COMPILE([ #include #include ], [ char *name; struct group gr; char buf[512]; int buflen = 512; (void)getgrnam_r(name, &gr, buf, buflen); ], tcl_cv_api_getgrnam_r_4=yes, tcl_cv_api_getgrnam_r_4=no)]) tcl_ok=$tcl_cv_api_getgrnam_r_4 if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRNAM_R_4) fi fi if test "$tcl_ok" = yes; then AC_DEFINE(HAVE_GETGRNAM_R) fi ])]) #-------------------------------------------------------------------- # SC_CONFIG_COMMANDS_PRE(CMDS) # # Replacement for autoconf 2.5x AC_COMMANDS_PRE: # Commands to run right before config.status is # created. Accumulates. # # Requires presence of SC_OUTPUT_COMMANDS_PRE at the end # of configure.in (right before AC_OUTPUT). # #-------------------------------------------------------------------- AC_DEFUN([SC_CONFIG_COMMANDS_PRE], [ define([SC_OUTPUT_COMMANDS_PRE], defn([SC_OUTPUT_COMMANDS_PRE])[$1 ])]) AC_DEFUN([SC_OUTPUT_COMMANDS_PRE]) test/000077500000000000000000000000001507046215500120425ustar00rootroot00000000000000test/Makefile.am000066400000000000000000000002561507046215500141010ustar00rootroot00000000000000 EXTRA_DIST = runtest noinst_PROGRAMS = libgpib_test libgpib_test_SOURCES = libgpib_test.c libgpib_test_CFLAGS = $(LIBGPIB_CFLAGS) libgpib_test_LDADD = $(LIBGPIB_LDFLAGS) test/README000066400000000000000000000022351507046215500127240ustar00rootroot00000000000000libgpib_test is used by developers to test the library, feel free to add tests for untested functions. It requires two gpib boards on the same GPIB bus, exactly one of which is the system controller. Two instances of libgpib_test must be run, one with the --master option and one with --slave. Their stdin and stdout need to be connected to each other (see the "runtest" script in this directory) so they can synchronize at various points in the tests. The runtest script will pass any command line options to both the master and slave invocations of libgpib_test. Example: ./runtest --pad 2 libgpib_test options: -n, --num_loops N loop through tests N times -M, --minor Specify board index to use -m, --master Use bus master gpib board -S, --slave Use slave gpib board -p, --pad N For master, open device with primary address N. For slave, sets board's primary address to N. -s, --sad For master, open device with secondary address N. For slave, sets board's secondary address to N. N must be in the range [0, 30]. If this option is not specified, then secondary addressing is disabled. -v, --verbose Produce verbose debugging output (doesn't do much yet). test/libgpib_test.c000066400000000000000000000503651507046215500146660ustar00rootroot00000000000000/*************************************************************************** libgpib_test.c ------------------- Test program for libgpib. Requires two gpib boards installed in the computer, on the same GPIB bus, and one of which is the system controller. copyright : (C) 2003 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include "gpib/ib.h" struct program_options { int num_loops; int master; int pad; int sad; int verbosity; int minor; }; #define PRINT_FAILED() \ fprintf( stderr, "FAILED: %s line %i, ibsta 0x%x, iberr %i, ibcntl %li\n", \ __FILE__, __LINE__, ThreadIbsta(), ThreadIberr(), ThreadIbcntl() ); \ static int sync_message(const struct program_options *options, const char *message) { char buffer[1024] = {0}; if(options->verbosity) { fprintf(stderr, "syncing: master=%i, message=%s\n", options->master, message); } if(options->master) { fprintf(stdout, "%s\n", message); fflush(stdout); } if(fgets(buffer, sizeof(buffer), stdin) == NULL) { fprintf(stderr, "failed to read from standard input.\n"); return -1; } if(strncmp(message, buffer, strlen(message))) { fprintf(stderr, "received unexpected sync message: %s\n", buffer); fprintf(stderr, "expected: %s\n", message); PRINT_FAILED(); return -1; } if(options->master == 0) { // echo back fprintf(stdout, "%s\n", message); fflush(stdout); } return 0; } static int init_board(int board_desc, const struct program_options *options) { int status; if(options->master == 0) { if(ibpad(board_desc, options->pad) & ERR) { PRINT_FAILED(); return -1; } if(options->sad >= 0) { if(ibsad(board_desc, MSA(options->sad)) & ERR) { PRINT_FAILED(); return -1; } } } ibtmo( board_desc, T30s ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } ibeot( board_desc, 1 ); if( ibsta & ERR ) { PRINT_FAILED(); return -1; } status = ibeos( board_desc, 0 ); if( status & ERR ) { PRINT_FAILED(); return -1; } if( status != ThreadIbsta() || ThreadIbsta() != ibsta ) { PRINT_FAILED(); return -1; } // for parallel poll test if(options->master == 0) { ibist(board_desc, 1); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } } return 0; } static int find_board(int *board, const struct program_options *options) { int i; int status, result; fprintf( stderr, "Finding board..." ); for( i = 0; i < GPIB_MAX_NUM_BOARDS; i++ ) { if(options->minor >= 0 && i != options->minor) continue; if(options->verbosity) fprintf(stderr, "\tchecking board %i\n", i); status = ibask( i, IbaSC, &result ); if( status & ERR ) continue; if(options->master && result != 0 ) { *board = i; break; }else if(options->master == 0 && result == 0) { *board = i; break; } } if(i == GPIB_MAX_NUM_BOARDS) { PRINT_FAILED(); return -1; } if(options->verbosity) fprintf(stderr, "\tfound board %i\n", i); if(init_board(*board, options)) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } Addr4882_t slaveAddress(const struct program_options *options) { Addr4882_t address; int sad; if(options->sad >= 0) sad = MSA(options->sad); else sad = 0; address = MakeAddr(options->pad, sad); return address; } static int open_slave_device_descriptor(int board, const struct program_options *options, int timeout, int eot, int eos ) { int sad; int ud; if(options->sad >= 0) sad = MSA(options->sad); else sad = 0; ud = ibdev( board, options->pad, sad, timeout, eot, eos ); if( ud < 0 ) { PRINT_FAILED(); } return ud; } static const char read_write_string1[] = "dig8esdfas sdf\n"; static const char read_write_string2[] = "DFLIJFES8F3 "; static int master_read_write_test(int board, const struct program_options *options) { int ud; int status; char buffer[1000]; int i; fprintf( stderr, "%s...", __FUNCTION__ ); ud = open_slave_device_descriptor( board, options, T30s, 1, 0 ); if( ud < 0 ) return -1; for( i = 0; i < 2; i++ ) { if(options->verbosity) fprintf(stderr, "\tloop %i\n", i); status = ibwrt( ud, read_write_string1, strlen( read_write_string1 ) + 1 ); if( ( status & ERR ) || !( status & CMPL ) ) { PRINT_FAILED(); fprintf(stderr, "\tloop %i\n", i); ibonl( ud, 0 ); return -1; } memset( buffer, 0, sizeof( buffer ) ); status = ibrd(ud, buffer, sizeof(buffer) - 1); if( ( status & ERR ) || !( status & CMPL ) || !( status & END ) ) { PRINT_FAILED(); fprintf( stderr, "received bytes:\"%s\"\n", buffer ); fprintf(stderr, "loop %i\n", i); ibonl( ud, 0 ); return -1; } if(strcmp(buffer, read_write_string2)) { PRINT_FAILED(); fprintf( stderr, "received bytes:\"%s\"\n", buffer ); fprintf(stderr, "\tloop %i\n", i); ibonl( ud, 0 ); return -1; } } ibonl( ud, 0 ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int slave_read_write_test(int board, const struct program_options *options) { char buffer[ 1000 ]; int status; int i; fprintf( stderr, "%s...", __FUNCTION__ ); for( i = 0; i < 2; i++ ) { memset( buffer, 0, sizeof( buffer ) ); status = ibrd(board, buffer, sizeof( buffer ) ); if(status & ERR) { PRINT_FAILED(); fprintf(stderr, "loop %i\n", i); return -1; } if(strcmp(buffer, read_write_string1)) { PRINT_FAILED(); fprintf( stderr, "got bad data from ibrd\n" ); fprintf( stderr, "received %i bytes:%s\n", ThreadIbcnt(), buffer ); fprintf(stderr, "loop %i\n", i); return -1; } status = ibwrt(board, read_write_string2, strlen(read_write_string2) + 1); if( status & ERR ) { PRINT_FAILED(); fprintf(stderr, "loop %i\n", i); return -1; } } fprintf( stderr, "OK\n" ); return 0; } static int master_async_read_write_test(int board, const struct program_options *options) { int ud; int i; int status; fprintf( stderr, "%s...", __FUNCTION__ ); ud = open_slave_device_descriptor(board, options, T3s, 1, 0); if( ud < 0 ) return -1; for( i = 0; i < 2; i++ ) { status = ibwrta( ud, read_write_string1, strlen( read_write_string1 ) + 1 ); if( status & ERR ) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } status = ibwait(ud, CMPL | TIMO); if((status & (ERR | TIMO)) || !(status & CMPL) ) { PRINT_FAILED(); fprintf( stderr, "loop %i, write status 0x%x, error %i\n", i, ThreadIbsta(), ThreadIberr() ); ibonl( ud, 0 ); return -1; } } ibonl( ud, 0 ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int slave_async_read_write_test(int board, const struct program_options *options) { char buffer[ 1000 ]; int i; int status; fprintf( stderr, "%s...", __FUNCTION__ ); for( i = 0; i < 2; i++ ) { memset( buffer, 0, sizeof( buffer ) ); status = ibrda( board, buffer, sizeof( buffer ) ); if( status & ERR ) { PRINT_FAILED(); fprintf( stderr, "read error %i\n", ThreadIberr() ); return -1; } status = ibwait( board, CMPL | TIMO ); if((status & (ERR | TIMO)) || !(status & CMPL)) { PRINT_FAILED(); fprintf( stderr, "loop %i, read status 0x%x, error %i\n", i, ThreadIbsta(), ThreadIberr() ); return -1; } if(strcmp(buffer, read_write_string1)) { PRINT_FAILED(); fprintf( stderr, "loop %i got bad data from ibrd\n", i); fprintf( stderr, "received %i bytes:%s\n", ThreadIbcnt(), buffer ); return -1; } } fprintf( stderr, "OK\n" ); return 0; } const int status_byte = 0x43; static int master_serial_poll_test(int board, const struct program_options *options) { int ud; char result; fprintf( stderr, "%s...", __FUNCTION__ ); ud = open_slave_device_descriptor(board, options, T3s, 1, 0 ); if( ud < 0 ) return -1; /* make sure status queue is empty */ while( ibwait( ud, 0 ) & RQS ) { ibrsp( ud, &result ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } } if(ibconfig(board, IbcAUTOPOLL, 1 ) & ERR) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } if(sync_message(options, "request service")) { ibonl( ud, 0 ); return -1; } ibwait(ud, RQS | TIMO); if((ThreadIbsta() & (ERR | TIMO)) || !(ThreadIbsta() & RQS)) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } result = 0; ibrsp(ud, &result); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } if((result & 0xff) != status_byte) { PRINT_FAILED(); ibonl( ud, 0 ); return -1; } ibonl( ud, 0 ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int slave_serial_poll_test(int board, const struct program_options *options) { fprintf( stderr, "%s...", __FUNCTION__ ); if(sync_message(options, "request service")) { PRINT_FAILED(); return -1; } ibrsv(board, status_byte); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int master_parallel_poll_test(int board, const struct program_options *options) { int ud; char result; int line, sense; fprintf( stderr, "%s...", __FUNCTION__ ); ud = open_slave_device_descriptor(board, options, T3s, 1, 0 ); if( ud < 0 ) return -1; if(sync_message(options, "ist is 1")) { ibonl( ud, 0 ); return -1; } line = 4; sense = 1; ibppc(ud, PPE_byte(line, sense)); if(ibsta & ERR) { PRINT_FAILED(); return -1; } ibrpp( board, &result ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } if((result & (1 << (line - 1))) == 0) { PRINT_FAILED(); fprintf( stderr, "parallel poll result: 0x%x\n", (unsigned int)result ); return -1; } if(sync_message(options, "set ist to 0")) { ibonl( ud, 0 ); return -1; } if(sync_message(options, "ist is 0")) { ibonl( ud, 0 ); return -1; } ibrpp( board, &result ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } if((result & (1 << (line - 1)))) { PRINT_FAILED(); fprintf( stderr, "parallel poll result: 0x%x\n", (unsigned int)result ); return -1; } ibonl( ud, 0 ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int slave_parallel_poll_test(int board, const struct program_options *options) { fprintf( stderr, "%s...", __FUNCTION__ ); ibist(board, 1); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } if(sync_message(options, "ist is 1")) { PRINT_FAILED(); return -1; } if(sync_message(options, "set ist to 0")) { PRINT_FAILED(); return -1; } ibist(board, 0); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } if(sync_message(options, "ist is 0")) { PRINT_FAILED(); return -1; } fprintf( stderr, "OK\n" ); return 0; } static int do_master_eos_pass(int board, const struct program_options *options, int eosmode, const char *test_message, const char *first_read_result, const char *second_read_result) { int ud; char buffer[1024]; ud = open_slave_device_descriptor(board, options, T3s, 0, eosmode); if( ud < 0 ) return -1; ibrd(ud, buffer, sizeof(buffer) - 1); buffer[ThreadIbcntl()] = '\0'; if( ThreadIbsta() & ERR ) { PRINT_FAILED(); fprintf( stderr, "ibrd status 0x%x, error %i, count %li\n", ThreadIbsta(), ThreadIberr(), ThreadIbcntl()); fprintf(stderr, "first read got: '%s'\n" "expected: '%s'\n", buffer, first_read_result); return -1; } if(strcmp(buffer, first_read_result)) { PRINT_FAILED(); fprintf(stderr, "first read got: '%s'\n" "expected: '%s'\n", buffer, first_read_result); return -1; } if(second_read_result != NULL) { ibrd(ud, buffer, sizeof(buffer) - 1); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } buffer[ThreadIbcntl()] = '\0'; if(strcmp(buffer, second_read_result)) { PRINT_FAILED(); fprintf(stderr, "second read got: '%s'\n" "expected: '%s'\n", buffer, second_read_result); return -1; } } ibonl( ud, 0 ); if( ThreadIbsta() & ERR ) { PRINT_FAILED(); return -1; } return 0; } static int do_slave_eos_pass(int board, const struct program_options *options, int eosmode, const char *test_message, const char *first_read_result, const char *second_read_result) { ibwrt(board, test_message, strlen(test_message)); if(ThreadIbsta() & ERR) { PRINT_FAILED(); fprintf(stderr, "%s: test_message=%s\n", __FUNCTION__, test_message); return -1; } return 0; } static int master_eos_test(int board, const struct program_options *options) { int retval; int seven_bit_eos; fprintf( stderr, "%s...", __FUNCTION__ ); //check if board supports 7 bit eos compares if(ibask(board, Iba7BitEOS, &seven_bit_eos) & ERR) { PRINT_FAILED(); return -1; } if(seven_bit_eos == 0) { fprintf(stderr, "board does not support 7 bit eos comparisons, skipping 7 bit eos test.\n"); retval = do_master_eos_pass(board, options, 0, "adfis\xf8gibblex", "adfis\xf8gibblex", NULL); if(retval < 0) return retval; }else { retval = do_master_eos_pass(board, options, 'x' | REOS, "adfis\xf8gibblex", "adfis\xf8", "gibblex"); if(retval < 0) return retval; } retval = do_master_eos_pass(board, options, 'x' | REOS | BIN, "adfis\xf8gibblex", "adfis\xf8gibblex", NULL); if(retval < 0) return retval; fprintf( stderr, "OK\n" ); return 0; } static int slave_eos_test(int board, const struct program_options *options) { int retval; fprintf( stderr, "%s...", __FUNCTION__ ); retval = do_slave_eos_pass(board, options, 'x' | REOS, "adfis\xf8gibblex", "adfis\xf8", "gibblex"); if(retval < 0) return retval; retval = do_slave_eos_pass(board, options, 'x' | REOS | BIN, "adfis\xf8gibblex", "adfis\xf8gibblex", NULL); if(retval < 0) return retval; fprintf( stderr, "OK\n" ); return 0; } static int master_remote_and_lockout_test(int board, const struct program_options *options) { Addr4882_t addressList[] = {slaveAddress(options), NOADDR}; int ud; fprintf( stderr, "%s...", __FUNCTION__ ); ud = open_slave_device_descriptor(board, options, T3s, 1, 0); if( ud < 0 ) return -1; EnableLocal(board, addressList); if(sync_message(options, "set local mode")) { ibonl( ud, 0 ); return -1; } if(ThreadIbsta() & ERR) { PRINT_FAILED(); return -1; } if(sync_message(options, "local detected")) { ibonl( ud, 0 ); return -1; } SetRWLS(board, addressList); if(ThreadIbsta() & ERR) { PRINT_FAILED(); return -1; } if(sync_message(options, "set remote with lockout")) { ibonl( ud, 0 ); return -1; } if(sync_message(options, "lockout detected")) { ibonl( ud, 0 ); return -1; } if(ibsre(board, 0) & ERR) { PRINT_FAILED(); return -1; } if(sync_message(options, "lockout cleared")) { ibonl( ud, 0 ); return -1; } if(sync_message(options, "lockout clear detected")) { ibonl( ud, 0 ); return -1; } EnableRemote(board, addressList); if(ThreadIbsta() & ERR) { PRINT_FAILED(); return -1; } if(sync_message(options, "remote enabled")) { ibonl( ud, 0 ); return -1; } if(sync_message(options, "remote detected")) { ibonl( ud, 0 ); return -1; } ibonl( ud, 0 ); fprintf( stderr, "OK\n" ); return 0; } static int slave_remote_and_lockout_test(int board, const struct program_options *options) { int failed = 0; fprintf( stderr, "%s...", __FUNCTION__ ); if(sync_message(options, "set local mode")) { PRINT_FAILED(); return -1; } if((ibwait(board, 0) & REM)) { fprintf(stderr, "REM did not clear. ibsta=0x%x\n", ThreadIbsta()); PRINT_FAILED(); ++failed; } if(sync_message(options, "local detected")) { PRINT_FAILED(); return -1; } if(sync_message(options, "set remote with lockout")) { PRINT_FAILED(); return -1; } if((ibwait(board, LOK | TIMO) & LOK) == 0) { fprintf(stderr, "failed to detect LOK status. ibsta=0x%x\n", ThreadIbsta()); PRINT_FAILED(); ++failed; } if(sync_message(options, "lockout detected")) { PRINT_FAILED(); return -1; } if(sync_message(options, "lockout cleared")) { PRINT_FAILED(); return -1; } if(ibwait(board, 0) & LOK) { PRINT_FAILED(); ++failed; } if(sync_message(options, "lockout clear detected")) { PRINT_FAILED(); return -1; } if(sync_message(options, "remote enabled")) { PRINT_FAILED(); return -1; } if((ibwait(board, REM | TIMO) & REM) == 0) { PRINT_FAILED(); ++failed; } if(sync_message(options, "remote detected")) { PRINT_FAILED(); return -1; } if(failed == 0) { fprintf( stderr, "OK\n" ); return 0; }else return -1; } int parse_program_options(int argc, char *argv[], struct program_options *options) { static struct option long_options[] = { {"num_loops", required_argument, NULL, 'n'}, {"master", no_argument, NULL, 'm'}, {"minor", required_argument, NULL, 'M'}, {"slave", no_argument, NULL, 'S'}, {"pad", required_argument, NULL, 'p'}, {"sad", required_argument, NULL, 's'}, {"verbose", no_argument, NULL, 'v'}, {0, 0, 0, 0} }; int c; int option_index = 0; memset(options, 0, sizeof(*options)); options->num_loops = 1; options->pad = 1; options->sad = -1; options->minor = -1; while(1) { c = getopt_long(argc, argv, "n:mSp:s:v", long_options, &option_index); if(c < 0) break; switch(c) { case 'n': options->num_loops = strtol(optarg, NULL, 0); fprintf(stderr, "option: loop %i times\n", options->num_loops); break; case 'm': options->master = 1; fprintf(stderr, "option: run as bus master\n"); break; case 'M': options->minor = strtol(optarg, NULL, 0); fprintf(stderr, "option: minor %i\n", options->minor); break; case 'S': options->master = 0; fprintf(stderr, "option: run as slave\n"); break; case 'p': options->pad = strtol(optarg, NULL, 0); fprintf(stderr, "option: pad %i\n", options->pad); break; case 's': options->sad = strtol(optarg, NULL, 0); fprintf(stderr, "option: sad %i\n", options->sad); break; case 'v': options->verbosity = 1; fprintf(stderr, "option: verbose\n"); break; default: fprintf(stderr, "bad option?\n"); return -1; break; } } return 0; } int main( int argc, char *argv[] ) { int board; int retval; struct program_options options; int i; if(parse_program_options(argc, argv, &options) < 0) return -1; for(i = 0; i < options.num_loops; i++) { if(options.master) { if(sync_message(&options, "found slave board")) return -1; retval = find_board(&board, &options); if( retval < 0 ) return retval; retval = master_read_write_test(board, &options); if( retval < 0 ) return retval; retval = master_async_read_write_test(board, &options); if( retval < 0 ) return retval; retval = master_serial_poll_test(board, &options); if( retval < 0 ) return retval; retval = master_parallel_poll_test(board, &options); if( retval < 0 ) return retval; retval = master_eos_test(board, &options); if( retval < 0 ) return retval; retval = master_remote_and_lockout_test(board, &options); if( retval < 0 ) return retval; }else { retval = find_board(&board, &options); if( retval < 0 ) return retval; if(sync_message(&options, "found slave board")) return -1; retval = slave_read_write_test(board, &options); if( retval < 0 ) return retval; retval = slave_async_read_write_test(board, &options); if( retval < 0 ) return retval; retval = slave_serial_poll_test(board, &options); if( retval < 0 ) return retval; retval = slave_parallel_poll_test(board, &options); if( retval < 0 ) return retval; retval = slave_eos_test(board, &options); if( retval < 0 ) return retval; retval = slave_remote_and_lockout_test(board, &options); if( retval < 0 ) return retval; } } return 0; } test/runtest000077500000000000000000000011471507046215500134770ustar00rootroot00000000000000#!/bin/bash # Note: it is possible to run the two instances of libgpib_test on different # computers by calling one through ssh instead of running it directly. COMMON_OPTIONS="$*" MASTER_OPTIONS="--master" SLAVE_OPTIONS="--slave" MYFIFO="/tmp/libgpib_test_fifo" rm -f $MYFIFO mknod $MYFIFO p ./libgpib_test $COMMON_OPTIONS $MASTER_OPTIONS 0< $MYFIFO 2> master_out | \ ./libgpib_test $COMMON_OPTIONS $SLAVE_OPTIONS 1>> $MYFIFO 2>slave_out rm -f $MYFIFO echo echo ========== echo "Output of master run:" echo ========== cat master_out echo echo ========== echo "Output of slave run:" echo ========== cat slave_out usb/000077500000000000000000000000001507046215500116545ustar00rootroot00000000000000usb/98-gpib-generic.rules000066400000000000000000000021101507046215500155130ustar00rootroot00000000000000#set mode/ownership for gpib device files KERNEL=="gpib[0-9]*", MODE="0660", GROUP="gpib" #example specifying NI gpib-usb-hs+ with serial number 01ABC414 should be #configured on /dev/gpib1 #SUBSYSTEM=="usb", ACTION=="add|change", ATTRS{idVendor}=="3923", ATTRS{idProduct}=="7618", ATTRS{serial}=="01ABC414", ENV{GPIB_CONFIG_OPTIONS}="--minor 1" #example specifying that an agilent_82357a with serial number MY12345678 #should be configured on /dev/gpib2 #SUBSYSTEM=="usb", ACTION=="add|change", ATTRS{idVendor}=="0957", ATTRS{idProduct}=="0107", ATTRS{serial}=="MY12345678", ENV{GPIB_CONFIG_OPTIONS}="--minor 2" #example specifying that an agilent_82357b with serial number MY0986754 #should be configured on /dev/gpib3 #SUBSYSTEM=="usb", ACTION=="add|change", ATTRS{idVendor}=="0957", ATTRS{idProduct}=="0718", ATTRS{serial}=="MY0987654", ENV{GPIB_CONFIG_OPTIONS}="--minor 3" #example specifying a board with a specific device path should be #configured on /dev/gpib4 #ACTION=="add|change", DEVPATH=="/devices/pci0000:00/0000:00:13.5/usb1/1-1/1-1:1.0", ENV{GPIB_CONFIG_OPTIONS}="--minor 4" usb/Makefile.am000066400000000000000000000025221507046215500137110ustar00rootroot00000000000000# Makefile.am # copyright (C) 2004 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. SUBDIRS = agilent_82357a ni_usb_gpib lpvo_usb_gpib EXTRA_DIST = 98-gpib-generic.rules gpib_udev_fxloader.in gpib_udev_config udevadm.sh CLEANFILES = gpib_udev_fxloader UDEV_RULES_DIR = $(sysconfdir)/udev/rules.d do_subst = $(SED) -e 's,[@]sbindir[@],$(sbindir),g'\ -e 's,[@]datadir[@],$(datadir),g'\ -e 's,[@]libdir[@],$(libdir),g' gpib_udev_fxloader: gpib_udev_fxloader.in $(do_subst) < $(srcdir)/gpib_udev_fxloader.in >$@ all-local: gpib_udev_fxloader install-data-local: 98-gpib-generic.rules test -d $(DESTDIR)$(UDEV_RULES_DIR) && test -e $(DESTDIR)$(UDEV_RULES_DIR)/98-gpib-generic.rules ||\ $(INSTALL_DATA) -D $(srcdir)/98-gpib-generic.rules $(DESTDIR)$(UDEV_RULES_DIR)/98-gpib-generic.rules install-exec-local: udevadm.sh $(INSTALL_SCRIPT) -D $(srcdir)/udevadm.sh $(DESTDIR)$(UDEV_LIBDIR)/gpib_udevadm_wrapper $(INSTALL_SCRIPT) -D gpib_udev_fxloader $(DESTDIR)$(UDEV_LIBDIR)/gpib_udev_fxloader $(INSTALL_SCRIPT) -D $(srcdir)/gpib_udev_config $(DESTDIR)$(UDEV_LIBDIR)/gpib_udev_config usb/agilent_82357a/000077500000000000000000000000001507046215500142105ustar00rootroot00000000000000usb/agilent_82357a/99-agilent_82357a.rules.in000066400000000000000000000022401507046215500204620ustar00rootroot00000000000000#82357a without firmware ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0957", ATTR{idProduct}=="0007", ENV{DEVICE}="$devnode", RUN+="@UDEV_LIBDIR@/gpib_udev_fxloader" #82357b without firmware ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0957", ATTR{idProduct}=="0518", ENV{DEVICE}="$devnode", RUN+="@UDEV_LIBDIR@/gpib_udev_fxloader" #automatically set the correct --board-type option and export SERIAL number for gpib_udev_config ACTION=="add|change", SUBSYSTEM=="usb", DRIVER=="agilent_82357a", ATTRS{serial}=="*", ENV{GPIB_CONFIG_OPTIONS}+="--board-type agilent_82357a", ENV{SERIAL}="$attr{serial}" #82357a/b with firmware ACTION=="add|change", SUBSYSTEM=="usb", DRIVER=="agilent_82357a", RUN+="@UDEV_LIBDIR@/gpib_udev_config" #this rule generates new "change" udev events for devices supported by the #driver after the module is loaded. #it is needed because if the driver is not already loaded when the hardware is plugged in, #then the initial hardware "add" event will not be able to accomplish anything. SUBSYSTEM=="module", ACTION=="add", DEVPATH=="/module/agilent_82357a", RUN+="@UDEV_LIBDIR@/gpib_udevadm_wrapper trigger --property-match DRIVER=agilent_82357a" usb/agilent_82357a/Makefile.am000066400000000000000000000021431507046215500162440ustar00rootroot00000000000000# Makefile.am # copyright (C) 2004 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = 99-agilent_82357a.rules.in CLEANFILES = 99-agilent_82357a.rules USB_FIRMWARE_DIR=$(datadir)/usb UDEV_RULES_DIR=$(sysconfdir)/udev/rules.d do_subst = $(SED) -e 's,[@]sbindir[@],$(sbindir),g'\ -e 's,[@]datadir[@],$(datadir),g'\ -e 's,[@]libdir[@],$(libdir),g'\ -e 's,[@]UDEV_LIBDIR[@],$(UDEV_LIBDIR),g' 99-agilent_82357a.rules: 99-agilent_82357a.rules.in $(do_subst) < $(srcdir)/99-agilent_82357a.rules.in >99-agilent_82357a.rules all-local: 99-agilent_82357a.rules install-data-local: $(INSTALL) -d $(DESTDIR)$(USB_FIRMWARE_DIR)/agilent_82357a test -d $(DESTDIR)$(UDEV_RULES_DIR) && test -e $(DESTDIR)$(UDEV_RULES_DIR)/99-agilent_82357a.rules ||\ $(INSTALL_DATA) -D 99-agilent_82357a.rules $(DESTDIR)$(UDEV_RULES_DIR)/99-agilent_82357a.rules usb/gpib_udev_config000077500000000000000000000005771507046215500151040ustar00rootroot00000000000000#!/bin/sh PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin HOME=/root export HOME PATH mylog() { if [ -x /usr/bin/logger ]; then /usr/bin/logger -t "$0" -- "$1" fi } mylog "entered for Product: $PRODUCT Devpath: $DEVPATH Serial: $SERIAL" mylog "gpib_config options: $GPIB_CONFIG_OPTIONS" gpib_config $GPIB_CONFIG_OPTIONS --sysfs-device-path $DEVPATH usb/gpib_udev_fxloader.in000077500000000000000000000030671507046215500160450ustar00rootroot00000000000000#!/bin/sh DATADIR=@datadir@ FXLOAD=fxload FXLOAD_OPTIONS= PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin HOME=/root export HOME PATH FIRMWARE= SS_LOADER= mylog() { if [ -x /usr/bin/logger ]; then /usr/bin/logger -t "$0" -- "$1" fi } # pre-renumeration device IDs case $PRODUCT in # ni-usb-b or kusb-488 without firmware 3923/702b/* | 3923/713b/*) FIRMWARE=$DATADIR/usb/ni_usb_gpib/niusbb_firmware.hex SS_LOADER=$DATADIR/usb/ni_usb_gpib/niusbb_loader.hex FXLOAD_OPTIONS="-t fx" ;; # 82357a without firmware 957/7/*) FIRMWARE=$DATADIR/usb/agilent_82357a/82357a_fw.hex ;; # 82357b without firmware 957/518/*) FIRMWARE=$DATADIR/usb/agilent_82357a/measat_releaseX1.8.hex FXLOAD_OPTIONS="-t fx2" ;; *) mylog "unsupported Product: $PRODUCT" exit 1; ;; esac # quit unless we were called to download some firmware if [ "$FIRMWARE" = "" ]; then # OR: restructure to do other things for # specific post-renumeration devices exit 0 fi # missing firmware? if [ ! -r $FIRMWARE ]; then mylog "missing firmware $FIRMWARE for $PRODUCT ??" exit 1 fi # missing fxload? if ! which $FXLOAD; then mylog "missing $FXLOAD ??" exit 1 fi mylog "loading firmware $FIRMWARE for $PRODUCT to $DEVICE" if [ "$SS_LOADER" = "" ]; then SS_LOADER_OPTION="" else # missing second stage loader? if [ ! -r $SS_LOADER ]; then mylog "missing second stage loader $SS_LOADER for $PRODUCT ??" exit 1 fi SS_LOADER_OPTION="-s $SS_LOADER" mylog "using second stage loader $SS_LOADER" fi $FXLOAD $FXLOAD_OPTIONS -I $FIRMWARE $SS_LOADER_OPTION usb/lpvo_usb_gpib/000077500000000000000000000000001507046215500145065ustar00rootroot00000000000000usb/lpvo_usb_gpib/99-lpvo_usb_gpib.rules.in000066400000000000000000000014611507046215500212620ustar00rootroot00000000000000#automatically set the correct --board-type option ACTION=="add|change", SUBSYSTEM=="usb", DRIVER=="lpvo_usb_gpib", ATTRS{serial}=="*", ENV{GPIB_CONFIG_OPTIONS}+="--board-type lpvo_usb_gpib", ENV{SERIAL}="$attr{serial}" ACTION=="add|change", SUBSYSTEM=="usb", DRIVER=="lpvo_usb_gpib", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", RUN+="@UDEV_LIBDIR@/gpib_udev_config" #this rule generates new "change" udev events for devices supported by the #driver after the module is loaded. #it is needed because if the driver is not already loaded when the hardware is plugged in, #then the initial hardware "add" event will not be able to accomplish anything. SUBSYSTEM=="module", ACTION=="add", DEVPATH=="/module/lpvo_usb_gpib", RUN+="@UDEV_LIBDIR@/gpib_udevadm_wrapper trigger --property-match DRIVER=lpvo_usb_gpib" usb/lpvo_usb_gpib/Makefile.am000066400000000000000000000020201507046215500165340ustar00rootroot00000000000000# Makefile.am # copyright (C) 2004 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = 99-lpvo_usb_gpib.rules.in lpvo_usb_gpib.conf CLEANFILES = 99-lpvo_usb_gpib.rules UDEV_RULES_DIR=$(sysconfdir)/udev/rules.d do_subst = $(SED) -e 's,[@]sbindir[@],$(sbindir),g'\ -e 's,[@]datadir[@],$(datadir),g'\ -e 's,[@]libdir[@],$(libdir),g'\ -e 's,[@]UDEV_LIBDIR[@],$(UDEV_LIBDIR),g' 99-lpvo_usb_gpib.rules: 99-lpvo_usb_gpib.rules.in $(do_subst) < $(srcdir)/99-lpvo_usb_gpib.rules.in >99-lpvo_usb_gpib.rules all-local: 99-lpvo_usb_gpib.rules install-data-local: test -d $(DESTDIR)$(UDEV_RULES_DIR) && test -e $(DESTDIR)$(UDEV_RULES_DIR)/99-lpvo_usb_gpib.rules ||\ $(INSTALL_DATA) -D 99-lpvo_usb_gpib.rules $(DESTDIR)$(UDEV_RULES_DIR)/99-lpvo_usb_gpib.rules usb/lpvo_usb_gpib/lpvo_usb_gpib.conf000066400000000000000000000000761507046215500202120ustar00rootroot00000000000000 alias usb:v0403p6001d*dc*dsc*dp*ic*isc*ip*in* lpvo_usb_gpib usb/ni_usb_gpib/000077500000000000000000000000001507046215500141345ustar00rootroot00000000000000usb/ni_usb_gpib/99-ni_usb_gpib.rules.in000066400000000000000000000023301507046215500203320ustar00rootroot00000000000000#gpib-usb-b without firmware SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="3923", ATTR{idProduct}=="702b", ENV{DEVICE}="$devnode", RUN+="@UDEV_LIBDIR@/gpib_udev_fxloader" #device id 713b is a keithley kusb-488 before we load it with firmware SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="3923", ATTR{idProduct}=="713b", ENV{DEVICE}="$devnode", RUN+="@UDEV_LIBDIR@/gpib_udev_fxloader" #automatically set the correct --board-type option and export SERIAL number for gpib_udev_config ACTION=="add|change", SUBSYSTEM=="usb", DRIVER=="ni_usb_gpib", ATTRS{serial}=="*", ENV{GPIB_CONFIG_OPTIONS}+="--board-type ni_usb_b", ENV{SERIAL}="$attr{serial}" #devices ready to be configured with gpib_config SUBSYSTEM=="usb", ACTION=="add|change", DRIVER=="ni_usb_gpib", RUN+="@UDEV_LIBDIR@/gpib_udev_config" #this rule generates new "change" udev events for devices supported by the #driver after the module is loaded. #it is needed because if the driver is not already loaded when the hardware is plugged in, #then the initial hardware "add" event will not be able to accomplish anything. SUBSYSTEM=="module", ACTION=="add", DEVPATH=="/module/ni_usb_gpib", RUN+="@UDEV_LIBDIR@/gpib_udevadm_wrapper trigger --property-match DRIVER=ni_usb_gpib" usb/ni_usb_gpib/Makefile.am000066400000000000000000000021021507046215500161630ustar00rootroot00000000000000# Makefile.am # copyright (C) 2004 by Frank Mori Hess # email : fmhess@users.sourceforge.net # # This Makefile.am is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. EXTRA_DIST = 99-ni_usb_gpib.rules.in CLEANFILES = 99-ni_usb_gpib.rules USB_FIRMWARE_DIR=$(datadir)/usb UDEV_RULES_DIR=$(sysconfdir)/udev/rules.d do_subst = $(SED) -e 's,[@]sbindir[@],$(sbindir),g'\ -e 's,[@]datadir[@],$(datadir),g'\ -e 's,[@]libdir[@],$(libdir),g'\ -e 's,[@]UDEV_LIBDIR[@],$(UDEV_LIBDIR),g' 99-ni_usb_gpib.rules: 99-ni_usb_gpib.rules.in $(do_subst) < $(srcdir)/99-ni_usb_gpib.rules.in >99-ni_usb_gpib.rules all-local: 99-ni_usb_gpib.rules install-data-local: $(INSTALL) -d $(DESTDIR)$(USB_FIRMWARE_DIR)/ni_usb_gpib test -d $(DESTDIR)$(UDEV_RULES_DIR) && test -e $(DESTDIR)$(UDEV_RULES_DIR)/99-ni_usb_gpib.rules ||\ $(INSTALL_DATA) -D 99-ni_usb_gpib.rules $(DESTDIR)$(UDEV_RULES_DIR)/99-ni_usb_gpib.rules usb/udevadm.sh000066400000000000000000000004331507046215500136350ustar00rootroot00000000000000#!/bin/sh # Wrapper script for udevadm UDEVADM_PATH="" for i in /bin /sbin /usr/bin /usr/sbin; do if [ -x $i/udevadm ]; then UDEVADM_PATH=$i/udevadm break; fi done if [ -n "$UDEVADM_PATH" ]; then $UDEVADM_PATH $@ else echo executable for udevadm not found fi util/000077500000000000000000000000001507046215500120405ustar00rootroot00000000000000util/templates/000077500000000000000000000000001507046215500140365ustar00rootroot00000000000000util/templates/gpib.conf000066400000000000000000000054261507046215500156350ustar00rootroot00000000000000/*********************************************************************** GPIB.CONF IEEE488 library config file ------------------- copyright : (C) 2002 by Frank Mori Hess (C) 1994 by C.Schroeter email : fmhess@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * Syntax: * * interface { ... } starts new interface board section * device {...} device configuration * ***************************************************************************/ /* This section configures the configurable driver characteristics * for an interface board, such as board address, and interrupt level. * minor = 0 configures /dev/gpib0, minor = 1 configures /dev/gpib1, etc. */ interface { minor = 0 /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */ board_type = "ni_pci" /* type of interface board being used */ name = "violet" /* optional name, allows you to get a board descriptor using ibfind() */ pad = 0 /* primary address of interface */ sad = 0 /* secondary address of interface */ timeout = T3s /* timeout for commands */ eos = 0x0a /* EOS Byte, 0xa is newline and 0xd is carriage return */ set-reos = yes /* Terminate read if EOS */ set-bin = no /* Compare EOS 8-bit */ set-xeos = no /* Assert EOI whenever EOS byte is sent */ set-eot = yes /* Assert EOI with last byte on writes */ /* settings for boards that lack plug-n-play capability */ base = 0 /* Base io ADDRESS */ irq = 0 /* Interrupt request level */ dma = 0 /* DMA channel (zero disables) */ /* pci_bus and pci_slot can be used to distinguish two pci boards supported by the same driver */ /* pci_bus = 0 */ /* pci_slot = 7 */ master = yes /* interface board is system controller */ } /* This is how you might set up a pcIIa board on /dev/gpib1, uncomment to use. */ /******************* interface { minor = 1 board_type = "pcIIa" pad = 0 sad = 0 timeout = T3s eos = 0x0a set-reos = yes set-bin = no base = 0x2e1 irq = 7 dma = 1 master = yes } *********************/ /* Now the device sections define the device characteristics for each device. * These are only used if you want to open the device using ibfind() (instead * of ibdev() ) */ device { minor = 0 /* minor number for interface board this device is connected to */ name = "voltmeter" /* device mnemonic */ pad = 7 /* The Primary Address */ sad = 0 /* Secondary Address */ eos = 0xa /* EOS Byte */ set-reos = no /* Terminate read if EOS */ set-bin = no /* Compare EOS 8-bit */ } device { minor = 0 name = "scope" pad = 8 sad = 0 }