1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>A Tutorial Introduction To HPIB</title>
</head>
<body>
<h1><a name="top">A Tutorial Introduction To HPIB</a></h1>
<p>
<em>v4.1 / 01 jan 99 / greg_goebel / public domain / hpib_tutorial</em>
</p>
<p>
* 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.
</p>
<hr />
<h1>Table Of Contents</h1>
<h2><a href="#ib1_m0">[1.0] HPIB Tutor (1): Introduction</a></h2>
<h2><a href="#ib2_m0">[2.0] HPIB Tutor (2): HPIB 488.1 / HPIB Fundamentals</a></h2>
<ul>
<li><a href="#ib2_m1">[2.1] 488.1 OVERVIEW</a>
</li>
<li><a href="#ib2_m2">[2.2] HPIB FUNCTIONS & CAPABILITIES</a>
</li>
<li><a href="#ib2_m3">[2.3] HPIB SIGNAL LINES & COMMANDS</a>
</li>
<li><a href="#ib2_m4">[2.4] HPIB ADDRESSING</a>
</li>
<li><a href="#ib2_m5">[2.5] HPIB COMMANDS</a>
</li>
<li><a href="#ib2_m6">[2.6] HPIB IN OPERATION -- AN HP BASIC EXAMPLE</a>
</li>
<li><a href="#ib2_m7">[2.7] HPIB IN PRACTICE</a>
</li>
<li><a href="#ib2_m8">[2.8] ASCII TABLE FOR HPIB</a>
</li>
</ul>
<h2><a href="#ib3_m0">[3.0] HPIB Tutor (3): IEEE 488.2 -- Overview & Data Formats</a></h2>
<ul>
<li><a href="#ib3_m1">[3.1] OVERVIEW</a>
</li>
<li><a href="#ib3_m2">[3.2] DATA CODING & FORMATS</a>
</li>
<li><a href="#ib3_m3">[3.3] SYNTAX</a>
</li>
</ul>
<h2><a href="#ib4_m0">[4.0] HPIB Tutor (4): 488.2 Common Commands & Status</a></h2>
<ul>
<li><a href="#ib4_m1">[4.1] 488.2 COMMON COMMANDS & STATUS OVERVIEW</a>
</li>
<li><a href="#ib4_m2">[4.2] ESSENTIAL COMMON COMMANDS</a>
</li>
<li><a href="#ib4_m3">[4.3] STATUS REPORTING</a>
</li>
<li><a href="#ib4_m4">[4.4] SECONDARY COMMON COMMANDS</a>
</li>
</ul>
<h2><a href="#ib5_m0">[5.0] HPIB Tutor (5): Introduction To SCPI</a></h2>
<ul>
<li><a href="#ib5_m1">[5.1] SCPI OVERVIEW</a>
</li>
<li><a href="#ib5_m2">[5.2] SCPI COMMAND SYNTAX</a>
</li>
<li><a href="#ib5_m3">[5.3] EXAMPLE SCPI COMMAND SETS</a>
</li>
<li><a href="#ib5_m4">[5.4] SCPI DATA FORMATS</a>
</li>
<li><a href="#ib5_m5">[5.5] STATUS & TRIGGERING</a>
</li>
</ul>
<h2><a href="#ib6_m0">[6.0] HPIB Tutor (6): A SCPI-Based HPIB Instrument -- The 34401 DMM</a></h2>
<ul>
<li><a href="#ib6_m1">[6.1] 34401 OVERVIEW</a>
</li>
<li><a href="#ib6_m2">[6.2] PROGRAMMING THE 34401</a>
</li>
<li><a href="#ib6_m3">[6.3] A SIMPLE 34401 EXAMPLE PROGRAM</a>
</li>
</ul>
<h2><a href="#ib7_m0">[7.0] HPIB Tutor (7): Notes & Comments</a></h2>
<ul>
<li><a href="#ib7_m1">[7.1] BENCHMARKS</a>
</li>
<li><a href="#ib7_m2">[7.2] PASS CONTROL & NON-CONTROLLER OPERATION</a>
</li>
</ul>
<hr />
<h1><a name="ib1_m0">[1.0] HPIB Tutor (1): Introduction</a></h1>
<p>
* 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.
</p>
<p>
The HPIB standard is defined at several levels:
</p>
<ul>
<li> The original 488.1 specification defines the mechanical and electrical
characteristics of the interface and its fundamental protocols.
</li>
<li> 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.
</li>
<li> 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 <em>any</em> 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.
</li>
</ul>
<p>
This document is divided into modules to discuss the following topics:
</p>
<ul>
<li> Fundamental HPIB (488-1) operation.
</li>
<li> 488.2 specs and data formats.
</li>
<li> 488.2 commands.
</li>
<li> SCPI commands.
</li>
<li> A SCPI instrument, the 34401A DMM.
</li>
<li> Comments on benchmarking and passing control.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
* If you are using this document for self-study rather than reference, a
few guidelines should help you make the best use of it:
</p>
<ul>
<li> 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).
<p>
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.
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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 <em>remarkably</em> out of hand).
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<hr />
<h1><a name="ib2_m0">[2.0] HPIB Tutor (2): HPIB 488.1 / HPIB Fundamentals</a></h1>
<p>
* This module provides an overview of the fundamental HPIB specification,
IEEE 488.1
</p>
<hr />
<ul>
<li>
<a href="#ib2_m1">[2.1] 488.1 OVERVIEW</a>
</li>
<li>
<a href="#ib2_m2">[2.2] HPIB FUNCTIONS & CAPABILITIES</a>
</li>
<li>
<a href="#ib2_m3">[2.3] HPIB SIGNAL LINES & COMMANDS</a>
</li>
<li>
<a href="#ib2_m4">[2.4] HPIB ADDRESSING</a>
</li>
<li>
<a href="#ib2_m5">[2.5] HPIB COMMANDS</a>
</li>
<li>
<a href="#ib2_m6">[2.6] HPIB IN OPERATION -- AN HP BASIC EXAMPLE</a>
</li>
<li>
<a href="#ib2_m7">[2.7] HPIB IN PRACTICE</a>
</li>
<li>
<a href="#ib2_m8">[2.8] ASCII TABLE FOR HPIB</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX </a>
</p>
<h2><a name="ib2_m1">[2.1] 488.1 OVERVIEW</a></h2>
<p>
* 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:
</p>
<ul>
<li> 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.
</li>
<li> Fifteen devices may be connected to one continuous bus.
</li>
<li> 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).
</li>
<li> Data rate across the interface does not exceed 1 megabyte per second.
(This data rate is rarely achieved in practice.)
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* The key specifications of IEEE 488.1 are listed below:
</p>
<ul>
<li> Interconnected devices: Up to 15 maximum on one contiguous bus.
</li>
<li> Interconnection path: Star or linear (or mixed) bus network, up to 20
meters total transmission path length.
</li>
<li> Signal lines: 16 active lines, consisting of 8 data lines and 8
communications management lines.
</li>
<li> Message transfer scheme: Byte-serial, bit-parallel, asynchronous data
transfer using an interlocking 3-wire handshake.
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<h2><a name="ib2_m2">[2.2] HPIB FUNCTIONS & CAPABILITIES</a></h2>
<p>
* 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:
</p>
<ul>
<li> 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.
</li>
<li> 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.
</li>
<li> 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".
</li>
</ul>
<p>
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.
</p>
<p>
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:
</p>
<ul>
<li> Talker / Extended Talker (T / TE): Capability required for a device to
Talk. Extended Talker is a Talker that supports secondary addressing.
</li>
<li> Listener / Extended Listener (L / LE): Capability required for a device
to Listen. Extended Listener is a Listener that supports secondary
addressing.
</li>
<li> 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).
</li>
<li> Acceptor Handshake (AH): Allows a device to receive command or data bytes
over the HPIB using the three-wire handshake.
</li>
<li> 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).
</li>
<li> Service Request (SR): Allows a device to assert an interrupt, or "service
request" (SRQ), over the HPIB to obtain service from the Active
Controller.
</li>
<li> 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.
</li>
<li> Device Clear (DC): Allows a device to be reset. Its actions are
implementation-dependent.
</li>
<li> Device Trigger (DT): Allows a device to be "triggered" by an HPIB command
to perform some implementation-dependent function.
</li>
<li> 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.
</li>
<li> Drivers (E): Describes the type of electrical bus drivers used in a
device.
</li>
</ul>
<p>
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.
</p>
<p>
For example, a device with:
</p>
<pre><strong>
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.
</strong></pre>
<p>
-- would be identified with these codes:
</p>
<pre><strong>
SH1 AH1 T6 L3 SR1 RL2 PP2 DC1 DT0 C0 E1
</strong></pre>
<p>
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.
</p>
<h2><a name="ib2_m3">[2.3] HPIB SIGNAL LINES & COMMANDS</a></h2>
<p>
* 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:
</p>
<ul>
<li> data lines
</li>
<li> byte transfer (handshake) lines
</li>
<li> general bus managment lines
</li>
</ul>
<p>
The organization of the signal lines is shown below:
</p>
<pre><strong>
DIO1 --------------------------------- -+
DIO2 --------------------------------- |
DIO3 --------------------------------- |
DIO4 --------------------------------- | data lines
DIO5 --------------------------------- |
DIO6 --------------------------------- |
DIO7 --------------------------------- |
DIO8 --------------------------------- -+
NDAC --------------------------------- -+
NRFD --------------------------------- | handshake lines
DAV --------------------------------- -+
EOI --------------------------------- -+
REN --------------------------------- |
SRQ --------------------------------- | general bus management lines
ATN --------------------------------- |
IFC --------------------------------- -+
</strong></pre>
<p>
The signal lines use TTL voltage levels. The pinouts are as follows:
</p>
<pre><strong>
*
* *
* *
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
* *
* *
*
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
The three handshake lines are defined as follows:
</p>
<ul>
<li> DAV (DAta Valid): Used by the source to indicate that a byte is ready to
be read.
</li>
<li> NRFD (Not Ready For Data): Used by acceptor to indicate that it is not
ready to receive a byte.
</li>
<li> NDAC (Not Data Accepted): Used by the acceptor to indicate that it has
not yet read the byte.
</li>
</ul>
<p>
The low-true logic of the handshake lines can be confusing. The protocol can
be outlined as follows:
</p>
<pre><strong>
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.
</strong></pre>
<p>
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. <em>all</em>
</p>
<p>
The following illustration shows the handshake in a different way:
</p>
<pre><strong>
+---------------------------------------------------------------+
| |
| ....................... ........... |
byte | ............ ............... |
| ....................... ........... |
| |
| .............. .................... |
DAV | : : : |
| :...................: :........ |
| |
| ........... ........... |
NRFD | : : : : : : : : |
| ......:.:.: :............................:.:.: :..... |
| |
| ........... |
NDAC | : : : : |
| ..........................:.:.: :........................ |
| |
+-----------+--+--+-------------+--+--+------------+--+--+------+
| | | | | | | | |
1 2 3 4 5 6 1 2 3
</strong></pre>
<p>
* The five general bus management lines are used to manage the orderly flow
of information over the HPIB:
</p>
<ul>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
<p>
The 488.1 spec was relaxed in 1987 to permit devices to ignore the state
of this line, but older devices will honor it.
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
In Command Mode, the Active Controller sends four classes of commands:
</p>
<ul>
<li> 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.
</li>
<li> Universal commands are commands the Active Controller sends to <em>all</em>
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).
</li>
<li> Addressed commands are byte commands similar to the universal multiline
commands, except that they apply only to those devices that have been
addressed.
</li>
<li> 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.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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:
</p>
<ul>
<li> 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.
<p>
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.
</p>
</li>
<li> 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.
<p>
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).
</p>
<p>
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.
</p>
</li>
<li> 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.)
<p>
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).
</p>
<p>
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.
</p>
<p>
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.
</p>
</li>
<li> 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.
<p>
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).
</p>
</li>
</ul>
<p>
The addressing scheme and command bytes are discussed in more detail in the
following sections.
</p>
<h2><a name="ib2_m4">[2.4] HPIB ADDRESSING</a></h2>
<p>
* 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.
</p>
<p>
If the device has DIP switches, they are usually arranged as follows:
</p>
<pre><strong>
1 2 4 8 16
+---------------------------+
| +-+ +-+ +-+ +-+ +-+ | 1
| |X| | | |X| | | | | |
| | | |X| | | |X| |X| |
| +-+ +-+ +-+ +-+ +-+ | 0
+---------------------------+
A1 A2 A3 A4 A5
</strong></pre>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
Listen address 5 = 32 + 5 = 37 decimal = 001 00101 binary
Talk address 5 = 64 + 5 = 69 decimal = 010 00101 binary
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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!
</p>
<p>
Note also that the address switches can physically be set to a value of 31,
but that is <em>not</em> a valid HPIB address! The address byte that has the
value 32 + 31 = 63 decimal is <em>not</em> 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib2_m5">[2.5] HPIB COMMANDS</a></h2>
<p>
* The five universal multiline (byte) commands are, as noted, accepted by
<em>all</em> devices on the HPIB. The commands consist of:
</p>
<ul>
<li> DCL (Device CLear): The universal DCL command causes all devices to
return to a device-dependent initial state.
</li>
<li> 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.
</li>
<li> 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).
</li>
<li> SPD (Serial Poll Disable): The SPD command takes the device out of
serial poll mode and returns it to normal Talker activity.
</li>
<li> PPU (Parallel Poll Unconfigure): The PPU command resets all parallel
poll devices to an idle state. As noted earlier, parallel poll is little
used.
</li>
</ul>
<p>
* 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.
</p>
<p>
* 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:
</p>
<ul>
<li> 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.
</li>
<li> 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.
</li>
<li> GTL (Go To Local): The GTL command sets the addressed Listeners back to
local mode.
</li>
<li> 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.
</li>
<li> TCT (Take Control Talker): The TCT command tells the addressed Talker to
become the active Controller.
</li>
</ul>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib2_m6">[2.6] HPIB IN OPERATION -- AN HP BASIC EXAMPLE</a></h2>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<pre><strong>
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
</strong></pre>
<p>
Let's take a look at the statements in the program in detail.
</p>
<p>
* 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.
</p>
<p>
The statement:
</p>
<pre><strong>
CLEAR 7
</strong></pre>
<p>
-- simply clears all the devices on the HPIB, though there's only one in this
case. The HPIB operations performed are as follows:
</p>
<pre><strong>
REN ATN : DCL
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
The next statement is:
</p>
<pre><strong>
OUTPUT @Dmm;"*RST"
</strong></pre>
<p>
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:
</p>
<pre><strong>
REN ATN : TAD30 (MTA)
REN ATN : UNL
REN ATN : LAD22
REN : "*"
REN : "R"
REN : "S"
REN : "T"
REN : CR
REN : LF
</strong></pre>
<p>
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.
</p>
<p>
Note how ATN is active when sending the three HPIB command bytes, and how it
is inactive when sending the instrument command string.
</p>
<p>
Another OUTPUT statement follows:
</p>
<pre><strong>
OUTPUT @Dmm;"*CLS"
</strong></pre>
<p>
This performs roughly the same actions as the first OUTPUT statement but
with a different string, "*CLS" (clear status):
</p>
<pre><strong>
REN ATN : TAD30 (MTA)
REN ATN : UNL
REN ATN : LAD22
REN : "*"
REN : "C"
REN : "L"
REN : "S"
REN : CR
REN : LF
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
The third OUTPUT statement:
</p>
<pre><strong>
OUTPUT @Dmm;"MEASURE:VOLTAGE:DC? DEF"
</strong></pre>
<p>
-- sends the DMM command bytes needed to tell the DMM to read a DC voltage:
</p>
<pre><strong>
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
</strong></pre>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
ENTER @Dmm;Rdg
</strong></pre>
<p>
This performs the actions:
</p>
<pre><strong>
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
</strong></pre>
<p>
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.
</p>
<p>
Once the program receives the voltage value back, it is printed to the
computer's display with:
</p>
<pre><strong>
PRINT "Reading Value: ";Rdg
</strong></pre>
<p>
The HP BASIC program then queries the DMM for serial-poll status with:
</p>
<pre><strong>
Stat=SPOLL(@Dmm)
</strong></pre>
<p>
This performs the following actions:
</p>
<pre><strong>
REN ATN : UNL
REN ATN : LAD30 (MLA)
REN ATN : TAD22
REN ATN : SPE
REN : 0
REN ATN : SPD
REN ATN : UNT
</strong></pre>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib2_m7">[2.7] HPIB IN PRACTICE</a></h2>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib2_m8">[2.8] ASCII TABLE FOR HPIB</a></h2>
<p>
* 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).
</p>
<p>
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.
</p>
<pre><strong>
__________________________________________________________________________
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).
__________________________________________________________________________
</strong></pre>
<hr />
<h1><a name="ib3_m0">[3.0] HPIB Tutor (3): IEEE 488.2 -- Overview & Data Formats</a></h1>
<p>
* This chapter and the next discusses the IEEE 488.2 specification.
</p>
<hr />
<ul>
<li>
<a href="#ib3_m1">[3.1] OVERVIEW</a>
</li>
<li>
<a href="#ib3_m2">[3.2] DATA CODING & FORMATS</a>
</li>
<li>
[<a href="#ib3_m3">3.3] SYNTAX</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX</a>
</p>
<h2><a name="ib3_m1">[3.1] OVERVIEW</a></h2>
<p>
* The 488.1 spec addressed the fundamental problems of interconnecting
digital devices, defining the mechanical and electrical requirements and the
basic communications protocols.
</p>
<p>
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.
</p>
<p>
IEEE 488.2-1987 was defined to address these problems. 488.2 provides:
</p>
<ul>
<li> A minimum required set of interface capabilities.
</li>
<li> Data formats.
</li>
<li> Device message protocols.
</li>
<li> A core common command set.
</li>
<li> A well-defined status-reporting model.
</li>
</ul>
<p>
This chapter discusses the details of data formats and protocols. The
following chapter discusses the common command set and status reporting.
</p>
<p>
* The minimum required set of interface capabilities defined by 488.2 is
given below:
</p>
<ul>
<li> Source Handshake / SH1 / Full capability.
</li>
<li> Acceptor Handshake / AH1 / Full capability.
</li>
<li> Talker / T(TE)5 or T(TE)6 / Basic Talker, serial poll, unTalk on MLA.
</li>
<li> Listener / L(LE)3 or L(LE)4 / Basic Listener, unListen on MTA.
</li>
<li> Service Request / SR1 / Full capability.
</li>
<li> Device Clear / DC1 / Full capability.
</li>
<li> Remote Local / RL0 or RL1 / None or full capability.
</li>
<li> Parallel Poll / PP0 or PP1 / None or full capability.
</li>
<li> Device Trigger / DT0 or DT1 / None or full capability.
</li>
<li> Controller / (C0 or C4) and (C5 or C7 or C8 or C11) / None or respond to
SRQ, send interface messages, pass & receive control.
</li>
<li> Electrical Interface / E1 or E2 / Open collector or tristate.
</li>
</ul>
<p>
This minimum capability set states that <em>all</em> 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.
</p>
<p>
* 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:
</p>
<ul>
<li> Listener Formats
<ul>
<li> <Decimal Numeric Program Data> / REQUIRED
</li>
<li> <Character Program Data> / optional
</li>
<li> <Suffix Program Data> / optional
</li>
<li> <Non-Decimal Numeric Program Data> / optional
</li>
<li> <String Program Data> / optional
</li>
<li> <Arbitrary Block Program Data> / optional
</li>
<li> <Expression Program Data> / optional
</li>
</ul>
</li>
<li> Talker Formats:
<ul>
<li> <NR1 Numeric Response Data> / REQUIRED
</li>
<li> <Arbitrary ASCII Response Data> / REQUIRED
</li>
<li> <Character Response Data> / optional
</li>
<li> <NR2 Numeric Response Data> / optional
</li>
<li> <NR3 Numeric Response Data> / optional
</li>
<li> <Hexadecimal Numeric Response Data> / optional
</li>
<li> <Octal Numeric Response Data> / optional
</li>
<li> <Binary Numeric Response Data> / optional
</li>
<li> <String Response Data> / optional
</li>
<li> <Definite Length Arbitrary Block Response Data> / optional
</li>
<li> <Indefinite Length Arbitrary Block Response Data> / optional
</li>
<li> <Expression Response Data> / optional
</li>
</ul>
</li>
</ul>
<p>
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."
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<h2><a name="ib3_m2">[3.2] DATA CODING & FORMATS</a></h2>
<p>
* 488.2 specifies three sets of codes for operation with HPIB devices:
</p>
<ul>
<li> US ASCII 7-bit (ANSI X3.4-1977) for alphanumerics.
</li>
<li> Binary 8-bit integer.
</li>
<li> Binary floating-point codes (IEEE 32- and 64-bit floating-point codes).
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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:
</p>
<pre><strong>
.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
</strong></pre>
<p>
The mantissa cannot have more than 255 characters, and the exponent must be
in the range of -32,000 to 32,000.
</p>
<p>
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:
</p>
<pre><strong>
1.3499 --> 1.3
1.35 --> 1.4
-2.456 --> -2.5
-2.447 --> -2.4
</strong></pre>
<p>
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:
</p>
<pre><strong>
_________________________________________________________________________
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
_________________________________________________________________________
</strong></pre>
<p>
The defined multipliers are as follows:
</p>
<pre><strong>
___________________________
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
___________________________
</strong></pre>
<p>
In the latest incarnation of 488.2, <Suffix Program Data> may also be used on
its own, without use of a preceding <NRf> element.
</p>
<p>
* The <Non-Decimal Numeric Program Data> format is a numeric string
representation of hexadecimal, octal, and binary numbers:
</p>
<pre><strong>
#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
</strong></pre>
<p>
* The <String Program Data> format is for sending ASCII strings (using 7-bit
USASCII characters):
</p>
<pre><strong>
'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"
</strong></pre>
<p>
Note that the two last examples do exactly the same thing, but in different
ways.
</p>
<p>
* 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.
</p>
<p>
Both formats start with a "#" character to distinguish them from other
device-listening formats. In the definite-length format, the "#" character
is followed by:
</p>
<ul>
<li> A single ASCII digit that gives the number of ASCII digits in the field
following it.
</li>
<li> A string of ASCII digits (where the field length was defined as above)
that gives the number of data bytes to follow the field.
</li>
<li> A stream of data bytes of a length given by the field above.
</li>
</ul>
<p>
This format may be a little easier to understand with some examples (note
that <DAB> stands for some arbitrary data byte):
</p>
<pre><strong>
#15<DAB><DAB><DAB><DAB><DAB>
#213<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>
</strong></pre>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
#0<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>NL&EOI
</strong></pre>
<p>
* 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: <em>very</em>
</p>
<pre><strong>
[ " ] [ # ] [ ' ] [ , ] [ ; ]
</strong></pre>
<p>
-- 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.
</p>
<p>
The device listening formats discussed above are very broad and forgiving.
The device talking formats are much more precise.
</p>
<p>
* The <NR1 Numeric Response Data -- Integers> format defines integer decimal
numbers with no decimal point or fractional part. For example:
</p>
<pre><strong>
123
+123
-12345
</strong></pre>
<p>
* The <NR2 Numeric Response Data -- Fixed Point> format defines decimal
numbers with a fractional part but no exponent. For example:
</p>
<pre><strong>
12.3
+1.234
-0.12345
</strong></pre>
<p>
* The <NR3 Numeric Response Data -- Floating Point> format defines decimal
numbers with a fractional part and an exponent. For example:
</p>
<pre><strong>
1.23E+5
123.4E-56
-12345.678E+90
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
#HAD0E
#H01F2
#HF3B
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
#Q7035
#Q30572
#Q765432
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
#B01101
#B10101010
#B1011
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
START
R2_D2
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
"You say hello"
"I say ""Goodbye""."
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
#3128<DAB1><DAB2><DAB3> ... <DAB128>
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
#0<DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB><DAB>NL&EOI
</strong></pre>
<p>
* 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. <em>very</em>
</p>
<p>
* 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:
</p>
<pre><strong>
[ " ] [ # ] [ ' ] [ , ] [ ; ]
</strong></pre>
<p>
-- 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.
</p>
<h2><a name="ib3_m3">[3.3] SYNTAX</a></h2>
<p>
* 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".
</p>
<p>
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.
</p>
<p>
* The elements of listening syntax fall into the following categories:
</p>
<ul>
<li> Terminators
</li>
<li> Separators
</li>
<li> Commands
</li>
<li> Queries
</li>
</ul>
<p>
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:
</p>
<ul>
<li> A newline.
</li>
<li> A newline with EOI.
</li>
<li> An EOI.
</li>
</ul>
<p>
A terminator is also sometimes informally referred to as an "arnold", but
this usage is clearly outside of the 488.2 spec.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
The <Program Data Separator> is just a "," (comma), and is used to separate
data in a data stream.
</p>
<p>
* Commands, or more properly <Command Program Headers>, also fall into three
categories, though in this case the categories are less distinct.
</p>
<p>
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:
</p>
<pre><strong>
MEASURE
</strong></pre>
<p>
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:
</p>
<pre><strong>
MEASURE:VOLTAGE
:MEASURE:VOLTAGE
</strong></pre>
<p>
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:
</p>
<pre><strong>
*IDN
*RST
*SRE
</strong></pre>
<p>
* 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:
</p>
<ul>
<li> <Simple Query Program Header>
</li>
<li> <Compound Query Program Header>
</li>
<li> <Common Query Program Header>
</li>
</ul>
<p>
The three have the same syntax as the complementary commands, except that a
"?" is tacked on to the end.
</p>
<p>
* 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:
</p>
<ul>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<p>
There are only four elements to the talking syntax:
</p>
<ul>
<li> <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.
</li>
<li> <Response Message Unit Separator>: This separator is defined as a ";"
(semicolon), and is used to separate different responses in the response
stream.
</li>
<li> <Response Data Data Separator>: This separator is defined as a ","
(comma), and is used to separate data items in a response.
</li>
<li> <Response Header Separator>: This separator is defined as a " " (space),
and is used to separate the response header from the response data.
</li>
</ul>
<hr />
<h1><a name="ib4_m0">[4.0] HPIB Tutor (4): 488.2 Common Commands & Status</a></h1>
<p>
* 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.
</p>
<hr />
<ul>
<li>
<a href="#ib4_m1">[4.1] 488.2 COMMON COMMANDS & STATUS OVERVIEW</a>
</li>
<li>
<a href="#ib4_m2">[4.2] ESSENTIAL COMMON COMMANDS</a>
</li>
<li>
<a href="#ib4_m3">[4.3] STATUS REPORTING</a>
</li>
<li>
<a href="#ib4_m4">[4.4] SECONDARY COMMON COMMANDS</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX</a>
</p>
<h2><a name="ib4_m1">[4.1] 488.2 COMMON COMMANDS & STATUS OVERVIEW</a></h2>
<p>
* 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:
</p>
<ul>
<li> AUTO CONFIGURE COMMANDS: Set device addresses via software.
<ul>
<li> *AAD / Assign Address / optional
</li>
<li> *DLF / Disable Listener Function / optional
</li>
</ul>
</li>
<li> SYSTEM DATA COMMANDS: Store or retrieve information about HPIB devices,
such as device descriptions and options.
<ul>
<li> *IDN? / Identification Query / REQUIRED
</li>
<li> *OPT? / Option Identification Query / optional
</li>
<li> *PUD / Protected User Data / optional
</li>
<li> *PUD? / Protected User Data Query / optional
</li>
<li> *RDT / Resource Description Transfer / optional
</li>
<li> *RDT? / Resource Description Transfer Query / optional
</li>
</ul>
</li>
<li> INTERNAL OPERATION COMMANDS: Control or read the internal operation of a
device through resets, self-tests, or self-calibration.
<ul>
<li> *CAL? / Calibration Query / optional
</li>
<li> *LRN? / Learn Device Setup Query / optional
</li>
<li> *RST / Reset / REQUIRED
</li>
<li> *TST? / Self-Test Query / REQUIRED
</li>
</ul>
</li>
<li> SYNCHRONIZATION COMMANDS: Control device synchronization within an HPIB
system.
<ul>
<li> *OPC / Operation Complete / REQUIRED
</li>
<li> *OPC? / Operation Complete Query / REQUIRED
</li>
<li> *WAI / Wait to Continue / REQUIRED
</li>
</ul>
</li>
<li> MACRO COMMANDS: Allow the user to define new commands as "macros" of
other commands.
<ul>
<li> *DMC / Define Macro / optional
</li>
<li> *EMC / Enable Macro / optional
</li>
<li> *EMC? / Enable Macro Query / optional
</li>
<li> *GMC? / Get Macro Contents Query / optional
</li>
<li> *LMC? / Learn Macro Query / optional
</li>
<li> *PMC / Purge Macros / optional
</li>
<li> *RMC / Remove Individual Macro / optional
</li>
</ul>
</li>
<li> PARALLEL POLL COMMANDS: Control how a device responds to a parallel poll,
and allow access to the same information without performing a parallel
poll.
<ul>
<li> *IST? / Individual Status Query / required if PP1
</li>
<li> *PRE / Parallel Poll Enable Register Enable / required if PP1
</li>
<li> *PRE? / Parallel Poll Enable Register Enable Query / required if PP1
</li>
</ul>
</li>
<li> STATUS & EVENT COMMANDS: Control device status reporting.
<ul>
<li> *CLS / Clear Status / REQUIRED
</li>
<li> *ESE / Event Status Enable / REQUIRED
</li>
<li> *ESE? / Event Status Enable Query / REQUIRED
</li>
<li> *ESR? / Event Status Register Query / REQUIRED
</li>
<li> *PSC / Power On Status Clear / optional
</li>
<li> *PSC? / Power On Status Clear Query / optional
</li>
<li> *SRE / Service Request Enable / REQUIRED
</li>
<li> *SRE? / Service Request Enable Query / REQUIRED
</li>
<li> *STB? / Read Status Byte Query / REQUIRED
</li>
</ul>
</li>
<li> DEVICE TRIGGER COMMANDS: Perform a Device Trigger and control how a
device responds to a trigger command.
<ul>
<li> *DDT / Define Device Trigger / optional if DT1
</li>
<li> *DDT? / Define Device Trigger Query / optional if DT1
</li>
<li> *TRG / Trigger / required if DT1
</li>
</ul>
</li>
<li> CONTROLLER COMMANDS: Defines the means of passing control between devices.
<ul>
<li> *PCB / Pass Control Back / required if ctl
</li>
</ul>
</li>
<li> STORED SETTING COMMANDS: Save and restore the state of the device.
<ul>
<li> *RCL / Recall Instrument State / optional
</li>
<li> *SAV / Save Instrument State / optional
</li>
<li> *SDS / Save Default Device Settings / optional
</li>
</ul>
</li>
</ul>
<p>
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.
</p>
<p>
* 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.)
</p>
<p>
* 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.
</p>
<h2><a name="ib4_m2">[4.2] ESSENTIAL COMMON COMMANDS</a></h2>
<p>
* In practice, the most important common commands are those outlined below:
</p>
<ul>
<li> SYSTEM DATA COMMANDS
<ul>
<li> *IDN? / Identification Query / REQUIRED
</li>
</ul>
</li>
<li> INTERNAL OPERATION COMMANDS
<ul>
<li> *LRN? / Learn Device Setup Query / optional
</li>
<li> *RST / Reset / REQUIRED
</li>
<li> *TST? / Self-Test Query / REQUIRED
</li>
</ul>
</li>
<li> SYNCHRONIZATION COMMANDS
<ul>
<li> *OPC / Operation Complete / REQUIRED
</li>
<li> *OPC? / Operation Complete Query / REQUIRED
</li>
<li> *WAI / Wait to Continue / REQUIRED
</li>
</ul>
</li>
<li> STATUS & EVENT COMMANDS
<ul>
<li> *CLS / Clear Status / REQUIRED
</li>
<li> *ESE / Event Status Enable / REQUIRED
</li>
<li> *ESE? / Event Status Enable Query / REQUIRED
</li>
<li> *ESR? / Event Status Register Query / REQUIRED
</li>
<li> *PSC / Power On Status Clear / optional
</li>
<li> *PSC? / Power On Status Clear Query / optional
</li>
<li> *SRE / Service Request Enable / REQUIRED
</li>
<li> *SRE? / Service Request Enable Query / REQUIRED
</li>
<li> *STB? / Read Status Byte Query / REQUIRED
</li>
</ul>
</li>
<li> DEVICE TRIGGER COMMANDS
<ul>
<li> *TRG / Trigger / required if DT1
</li>
</ul>
</li>
</ul>
<p>
* The *IDN? (Identification) query causes a device to return a string to
identify itself; this string has the format:
</p>
<pre><strong>
<manufacturer>,<model>,<serial_number>,<firmware_rev_level>
</strong></pre>
<p>
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:
</p>
<pre><strong>
HEWLETT-PACKARD,347A,222101113,A1
</strong></pre>
<p>
* 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.
</p>
<p>
* The *RST (Reset) command resets the device. It performs the following
actions:
</p>
<ul>
<li> Sets device functions to a known state.
</li>
<li> Sets the Device Defined Trigger (see *DDT command) to a known state.
</li>
<li> Disables macros (see the section on macro commands).
</li>
<li> Aborts all pending operations.
</li>
<li> Clears any received *OPC or *OPC? commands in progress.
</li>
</ul>
<p>
The *RST command does not affect:
</p>
<ul>
<li> The state of the HPIB address or its address.
</li>
<li> The bytes in the output queue.
</li>
<li> The service request enable register.
</li>
<li> The standard event status register.
</li>
<li> The power-on flag.
</li>
<li> Macro definitions (though they are disabled), calibration data,
protected user data, or the Resource Description Transfer Query Response.
</li>
</ul>
<p>
Note that *RST is the highest of three levels of resets defined under 488.1
and 488.2. These three levels are:
</p>
<ul>
<li> The 488.1 IFC line causes a level-1 reset. It unaddresses all devices and
returns control to the system controller.
</li>
<li> 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.
</li>
<li> The 488.2 *RST command performs a level-3 reset: it actually clears the
device itself as described above.
</li>
</ul>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
The matching *OPC? query tells the device to place an ASCII "1" in the
device's output queue when it completes all pending operations.
</p>
<p>
* 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.
</p>
<p>
* 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).
</p>
<p>
* 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.
</p>
<p>
The *ESE? query interrogates the Standard Event Status Enable Register. It
returns a decimal numeric string in the range "0" to "255".
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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".)
</p>
<p>
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.
</p>
<p>
* The *TRG (Trigger) command performs the same function as the GET command
byte.
</p>
<h2><a name="ib4_m3">[4.3] STATUS REPORTING</a></h2>
<p>
* 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.
</p>
<p>
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):
</p>
<pre><strong>
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?
</strong></pre>
<p>
In 488.2 bits 4, 5, and 6 in the status byte are defined as follows:
</p>
<ul>
<li> 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.
</li>
<li> Bit 5 is the event-status bit, or ESB, which captures events generated
from the Standard Event Status Register, which is defined below.
</li>
<li> 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.
<p>
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.
</p>
</li>
</ul>
<p>
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.)
</p>
<p>
The second status register defined by 488.2, the Standard Event Status
register (SRER), contains the following flags:
</p>
<ul>
<li> 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.
</li>
<li> Bit 1 -- Request Control (RQC) -- indicates that the device wants to
become the active controller.
</li>
<li> 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.
</li>
<li> Bit 3 -- Device-Dependent Error (DDE) -- indicates some unspecified device
error occurred.
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> Bit 6 -- User Request (URQ) -- indicates that the user has activated some
device-dependent control to request service.
</li>
<li> Bit 7 -- Power On (PON) -- indicates that the device has been power-cycled
since the last time it was queried.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
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).
</p>
<p>
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!)
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<pre><strong>
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
</strong></pre>
<p>
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.
</p>
<p>
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 <em>always</em> do this in your own programs,
since your program will hang indefinitely if you don't.
</p>
<p>
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.
</p>
<h2><a name="ib4_m4">[4.4] SECONDARY COMMON COMMANDS</a></h2>
<p>
* The remaining commands are implemented only in certain classes of
instruments, or aren't implemented at all.
</p>
<p>
* The optional Macro Commands allow a device to accept "macro" strings that
designate and instruct the device to execute a specific series of commands.
</p>
<p>
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:
</p>
<pre><strong>
*DMC "HOME",#18MOVE 0,0
</strong></pre>
<p>
-- defines a command that moves a pen plotter to its home position.
</p>
<p>
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.
</p>
<p>
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).
</p>
<p>
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 <em>operation</em>. 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.
</p>
<p>
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:
</p>
<pre><strong>
*GMC? "HOME"
</strong></pre>
<p>
-- returns the definition for "HOME", which is "#18MOVE 0,0", as shown in an
earlier example.
</p>
<p>
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.
</p>
<p>
The *PMC (Purge Macro) command wipes all defined macros from device memory.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
* The *PUD (Protected User Data) command stores up to 63 bytes of
device-dependent data. The data can be retrieved with a *PUD? query.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
* 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.)
</p>
<p>
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.)
</p>
<p>
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.
</p>
<hr />
<h1><a name="ib5_m0">[5.0] HPIB Tutor (5): Introduction To SCPI</a></h1>
<p>
* This chapter provides an overview of the Standards Commands for
Programmable Instruments (SCPI) command set spec.
</p>
<hr />
<ul>
<li>
<a href="#ib5_m1">[5.1] SCPI OVERVIEW</a>
</li>
<li>
<a href="#ib5_m2">[5.2] SCPI COMMAND SYNTAX</a>
</li>
<li>
<a href="#ib5_m3">[5.3] EXAMPLE SCPI COMMAND SETS</a>
</li>
<li>
<a href="#ib5_m4">[5.4] SCPI DATA FORMATS</a>
</li>
<li>
<a href="#ib5_m5">[5.5] STATUS & TRIGGERING</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX</a>
</p>
<h2><a name="ib5_m1">[5.1] SCPI OVERVIEW</a></h2>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib5_m2">[5.2] SCPI COMMAND SYNTAX</a></h2>
<p>
* 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".
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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:
</p>
<pre><strong>
SENSe
|
+---------------+---------------+
| |
CURRent VOLTage
| |
+------+------+ +------+------+
| | | |
RANGe RESolution RANGe RESolution
| | | |
+---+---+ | +---+---+ |
| | | | | |
UPPer AUTO AUTO UPPer AUTO AUTO
</strong></pre>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe:AUTO
</strong></pre>
<p>
-- which sets the DMM to read voltages and uses autoranging. Note how
colons (":") are used as path separators. Another path is:
</p>
<pre><strong>
:SENSe:CURRent:RANGe:UPPer
</strong></pre>
<p>
-- 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. <em>not</em>
</p>
<p>
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.
</p>
<p>
The parser navigates through the tree as directed by subsystem command
strings according to the following rules:
</p>
<ul>
<li> After power-on or the *RST common command is sent, the current path is set
to the root.
</li>
<li> A message terminator, usually a <newline> (line-feed) character, also sets
the current path to the root.
</li>
<li> 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".)
</li>
<li> A semicolon (";") separates two commands in the same subsystem command
string without changing the current path.
</li>
<li> 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.
<p>
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.
</p>
</li>
<li> Commas (",") are used to separate multiple parameters for a single
subsystem command.
</li>
<li> Common commands, such as *RST, are not subsystem commands and are not
interpreted as part of a path.
</li>
</ul>
<p>
For example:
</p>
<pre><strong>
:SENSe:VOLTage ; RANGe:AUTO ; RESolution:AUTO
</strong></pre>
<p>
-- is the same as executing:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe:AUTO
:SENSe:VOLTage:RESolution:AUTO
</strong></pre>
<p>
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:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe:AUTO ; :SENSe:CURRent:RANGe:UPPer
</strong></pre>
<p>
-- is the same as executing both commands separately, since the ":"
immediately following the separating ";" resets the current path to root.
</p>
<p>
* 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:
</p>
<pre><strong>
_______________________________________
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
_______________________________________
</strong></pre>
<p>
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:
</p>
<pre><strong>
:SENSe:CURRent:RANGe:AUTO ON
</strong></pre>
<p>
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.
<em>not</em>
</p>
<p>
What the lowercase letters in the definitions specify is that those
characters are optional, and may be discarded if desired. To illustrate:
</p>
<pre><strong>
:SENS:CURR:RANG:AUTO ON
</strong></pre>
<p>
-- is the same as:
</p>
<pre><strong>
:SENSe:CURRent:RANGe:AUTO ON
</strong></pre>
<p>
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:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe:UPPer 6.5
</strong></pre>
<p>
-- is the same as:
</p>
<pre><strong>
:VOLTage:RANGe 6.5
</strong></pre>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe
</strong></pre>
<p>
-- has the matching query:
</p>
<pre><strong>
:SENSe:VOLTage:RANGe?
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib5_m3">[5.3] EXAMPLE SCPI COMMAND SETS</a></h2>
<p>
* For examples of SCPI syntax, consider simplified command sets for a
hypothetical signal generator, DVM, and relay scanner.
</p>
<p>
These devices are examples of the three classes of programmable instruments:
source, sense, and switch devices:
</p>
<ul>
<li> Source instruments output some kind of signal, such as power supplies and
pulse generators.
</li>
<li> Sense instruments are those which measure signals, such as power meters
and counters.
</li>
<li> Switch instruments use relays or solid-state switches to route signals
between an instrument and devices under test.
</li>
</ul>
<p>
More sophisticated instruments may combine multiple instrument functions in a
single package.
</p>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
__________________________________________
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
__________________________________________
</strong></pre>
<p>
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:
</p>
<pre><strong>
: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.
</strong></pre>
<p>
The matchinq queries consist of:
</p>
<pre><strong>
:FREQ? Query output frequency.
:VOLT? Query output voltage.
:FUNC? Query output function.
:OUTPut:IMP? Query output impedance.
:OUTPut? Query output state.
</strong></pre>
<p>
Note that the :OUTPut:IMP command only has two values, 50 or 75. Other
values will be rounded to the allowed value.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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:
</p>
<pre><strong>
_______________________________________________
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.
_______________________________________________
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
Most measurements can be modeled as a three-step process:
</p>
<ul>
<li> Set up the instrument.
</li>
<li> Trigger the measurement.
</li>
<li> Retrieve the reading.
</li>
</ul>
<p>
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.
</p>
<p>
For the DVM, a low-level sequence of commands to read an AC voltage looks
like this:
</p>
<pre><strong>
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.
</strong></pre>
<p>
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:
</p>
<pre><strong>
10 OUTPUT @Dvm;":MEAS:VOLT:AC?" ! Measure AC volts.
20 ENTER @Dvm;Vac ! Get the reading.
</strong></pre>
<p>
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.
</p>
<p>
: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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
_______________________________________________
Command Parameters
_______________________________________________
[:ROUTe]
:CLOSe (@0:7)
:OPEN (@0:7)
:SCAN (@0:7)
:TRIGger
[:IMMediate]
:SOURce IMMediate or EXTernal
_______________________________________________
</strong></pre>
<p>
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:
</p>
<pre><strong>
(@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.
</strong></pre>
<p>
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.
</p>
<p>
The following statements configure the scanner to scan channels 1 through 3
using the rear panel BNC external trigger:
</p>
<pre><strong>
40 OUTPUT @Scan;"*RST;*CLS"
50 OUTPUT @Scan;":SCAN (@1:3)"
60 OUTPUT @Scan;":TRIG:SOUR EXT"
</strong></pre>
<p>
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.
</p>
<p>
The following statements perform some simple queries:
</p>
<pre><strong>
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.
</strong></pre>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
The program to perform these measurements follows below:
</p>
<pre><strong>
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
</strong></pre>
<h2><a name="ib5_m4">[5.4] SCPI DATA FORMATS</a></h2>
<p>
* 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.
</p>
<p>
Simple numeric parameters encompass familiar integer and floating-point
formats:
</p>
<pre><strong>
100
100.
-1.23
4.5e3
-7.89E-01
.5
</strong></pre>
<p>
Numeric parameters are a superset of simple numeric parameters, and add
certain constant values to that definition. All instruments will recognize
the constants:
</p>
<pre><strong>
MAXimum
MINimum
</strong></pre>
<p>
-- though the exact value of these constants is device-dependent. Other
special values, such as:
</p>
<pre><strong>
UP
INFinity
DEFault
</strong></pre>
<p>
-- may be defined for specific instruments. For example:
</p>
<pre><strong>
100 OUTPUT @Dvm;":VOLT:DC MAX"
110 OUTPUT @Dvm;":CONF:VOLT:DC 10.0,Min"
</strong></pre>
<p>
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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
For some practical examples:
</p>
<pre><strong>
100 OUTPUT @Dvm;":TRIGGER:SOURCE INT"
110 OUTPUT @Dvm;":ARM:SLOPE NEGATIVE"
</strong></pre>
<p>
Boolean parameters should be familiar:
</p>
<pre><strong>
ON
OFF
TRUE
FALSE
1
0
</strong></pre>
<p>
When you query a Boolean setting, you will always get back a "1" or "0".
For example:
</p>
<pre><strong>
100 OUTPUT @Dvm;":OUTPUT ON"
110 OUTPUT @Dvm;":OUTPUT 0"
</strong></pre>
<p>
String parameters allow ASCII strings to be sent as parameters. For
example:
</p>
<pre><strong>
'this is a STRING'
"this is also a string"
"one double quote inside brackets: [""]"
'one single quote inside brackets: ['']'
</strong></pre>
<p>
Single quotes are the most convenient format for HP BASIC:
</p>
<pre><strong>
110 OUTPUT @Dvm;":DISPLAY:TEXT 'STOP!'"
</strong></pre>
<p>
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:
</p>
<pre><strong>
#0<DAB><DAB> ... <DAB>NL&EOI
#<num_digits_in_byte_count><byte_count><DAB1><DAB2> ... <DABn>
</strong></pre>
<p>
For example, the following HP BASIC commands send the same 7 bytes of ASCII
text as indefinite- and definite-length blocks respectively:
</p>
<pre><strong>
120 OUTPUT @Dvm;"#0ABC_XYZ",END ! END asserts EOI.
OUTPUT @Dvm;"#17ABC_XYZ" ! <num_digits>=1, <byte_count>=7
</strong></pre>
<p>
Non-decimal numeric parameters allow numeric information to be sent as
binary, octal, or hexadecimal:
</p>
<pre><strong>
#b010110100
#Q773662
#h3FA1
</strong></pre>
<p>
The header may be upper- or lower-case characters.
</p>
<p>
* 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").
</p>
<p>
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:
</p>
<pre><strong>
:QUERY1?;:QUERY2?
</strong></pre>
<p>
-- 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. <em>always</em>
</p>
<p>
Real response data defines floating-point data types with a uniform format:
</p>
<pre><strong>
1.23E+0
-1.0E+2
-1.23
-100.0
-7.89E-01
0.5
</strong></pre>
<p>
Integer response data defines an integer-only data format:
</p>
<pre><strong>
0
+100
-100
256
65535
4
</strong></pre>
<p>
Discrete response data is defined exactly as is discrete parameter data, but
the response data, unlike the discrete parameter data, is always
uppercase: <em>always</em>
</p>
<pre><strong>
INT
EXT
POS
NEG
</strong></pre>
<p>
String response data is defined like string parameter data, except that only
double-quotes are legal:
</p>
<pre><strong>
"this is a string"
"one double quote inside brackets: [""]"
</strong></pre>
<p>
Definite-length and indefinite-length block response data types are totally
identical to their parameter equivalents.
</p>
<p>
Binary, octal, and hexadecimal response data types are identical to their
parameter equivalents, except that lower-case headers are not allowed:
</p>
<pre><strong>
#B00001111
#Q0707
#H0F1F
</strong></pre>
<h2><a name="ib5_m5">[5.5] STATUS & TRIGGERING</a></h2>
<p>
* SCPI specifies advanced features for status and triggering. In fact, it
defines more features than anyone could ever want.
</p>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
+-----+ +-----+
| 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?
</strong></pre>
<p>
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.) <em>not</em>
</p>
<p>
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?.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
The SCPI triggering system can become quite complicated but a simple subset
of it incoporates three levels:
</p>
<ul>
<li> An INIT level that simply tells the device to trigger.
</li>
<li> A TRIG level that adds triggering conditions.
</li>
<li> An ARM level that adds pretriggering setup conditions.
</li>
</ul>
<p>
This is more than enough for most purposes, and in fact many instruments
don't implement even this level of triggering capabilities.
</p>
<p>
* Example commands using INIT include:
</p>
<pre><strong>
: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.
</strong></pre>
<p>
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).
</p>
<p>
* 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:
</p>
<pre><strong>
: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.
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
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.
</p>
<p>
* 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".
</p>
<p>
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.
</p>
<pre><strong>
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.
</strong></pre>
<p>
The illustration below shows the operation of this trigger sequence:
</p>
<pre><strong>
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).
</strong></pre>
<p>
Even more complicated triggering actions could be defined as needed.
</p>
<hr />
<h1><a name="ib6_m0">[6.0] HPIB Tutor (6): A SCPI-Based HPIB Instrument -- The 34401 DMM</a></h1>
<p>
* 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".
</p>
<p>
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.
</p>
<hr />
<ul>
<li>
<a href="#ib6_m1">[6.1] 34401 OVERVIEW</a>
</li>
<li>
<a href="#ib6_m2">[6.2] PROGRAMMING THE 34401</a>
</li>
<li>
<a href="#ib6_m3">[6.3] A SIMPLE 34401 EXAMPLE PROGRAM</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX</a>
</p>
<h2><a name="ib6_m1">[6.1] 34401 OVERVIEW</a></h2>
<p>
* The 34401 DMM has the following measurement capabilities:
</p>
<ul>
<li> AC and DC volts, with a range from 0.1 to 1000 volts (750 volts AC).
</li>
<li> Resistance, with a range from 100 ohms to 100 megohms.
</li>
<li> AC and DC current, with a range from 10 milliamps (DC only) to 3 amps.
</li>
<li> Frequency and period, with ranges from 3 hertz to 300 kilohertz.
</li>
<li> Continuity and diode checking.
</li>
<li> Display resolution from 4.5 to 6.5 digits.
</li>
<li> Several math functions, and a capability to store 512 readings in memory.
</li>
<li> A menu-driven front-panel interface and a vacuum-fluorescent display.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
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:
</p>
<ul>
<li> Measurement configuration.
</li>
<li> Math operations.
</li>
<li> Triggering.
</li>
<li> System-related operations.
</li>
<li> Remote interface configuration.
</li>
<li> Calibration.
</li>
<li> Power-on and reset state.
</li>
</ul>
<p>
* The DMM's measurement configuration features include the following:
</p>
<ul>
<li> 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.
<p>
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.)
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
<p>
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.
</p>
<p>
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.
</p>
</li>
<li> 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 <em>only</em> be performed from the front
panel buttons. There is no way to do it programmatically.
</li>
<li> 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.
<p>
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.
</p>
</li>
<li> 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.
</li>
</ul>
<p>
* 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.
</p>
<p>
The table below shows the allowed math / measurement function combinations:
</p>
<pre><strong>
___________________________________________________
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
___________________________________________________
</strong></pre>
<p>
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:
</p>
<ul>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
<p>
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.
</p>
</li>
<li> 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.
<p>
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.)
</p>
<p>
You can set limits from the front panel either programmatically, or by
making a measurement.
</p>
</li>
</ul>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
Setting up a trigger requires the following steps:
</p>
<ul>
<li> The DMM must be configured for a measurement by selecting the function,
range, resolution, and so on.
</li>
<li> The trigger source must be selected: either a software (HPIB) trigger, a
hardware trigger from the EXTERNAL TRIGGER terminal, or an immediate
internal trigger.
</li>
<li> Finally, the DMM must be placed into the "wait for trigger" state and wait
for the trigger to come along.
</li>
</ul>
<p>
The actions required to perform these steps are outlined below.
</p>
<ul>
<li> 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.
<p>
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.
</p>
<p>
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.
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
<p>
The default delay time depends on the function, range, integration time,
and AC filter setting of the DMM; refer to DMM documentation for details.
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<p>
* System-related operations include such topics as reading memory, errors,
self-test, and display control:
</p>
<ul>
<li> 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.
</li>
<li> 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.
<p>
If no errors have occurred when you read the error queue, the DMM responds
with a "no error" (error 0) error message.
</p>
<p>
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.
</p>
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> Comma separators: You can set the DMM to display comma separators in long
numbers. This feature can only be set from the front panel.
</li>
<li> 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.
</li>
<li> SCPI Language Version: You can query the DMM programmatically to
determine its SCPI revision level.
</li>
</ul>
<p>
* 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.)
</p>
<p>
All these configuration settings are stored in non-volatile memory. It will
be retained even if the DMM is switched off.
</p>
<ul>
<li> Remote interface selection: You can select remote operation over either
the HPIB or RS-232 port from the front panel.
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> 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.
</li>
</ul>
<p>
* 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.
</p>
<ul>
<li> 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".
<p>
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).
</p>
</li>
<li> Calibration count: The number of times the DMM has been calibrated can be
read from the front panel or over the remote programming interface.
</li>
<li> 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.
</li>
</ul>
<h2><a name="ib6_m2">[6.2] PROGRAMMING THE 34401</a></h2>
<p>
* 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.
</p>
<p>
The only settings you can set are function, range, and resolution. You can
set these as parameters to the MEASure? command itself:
</p>
<pre><strong>
MEASure:<function> <range>, <resolution>
</strong></pre>
<p>
The relevant functions include:
</p>
<pre><strong>
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.
</strong></pre>
<p>
For example:
</p>
<pre><strong>
100 OUTPUT @Dmm;"MEAS:VOLT:DC? 10,0.003" ! DC, 10 V range, 3 mV resolution.
110 ENTER @Dmm;Volts
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
Note that if READ? is used, the output data will <em>not</em> 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?
</p>
<p>
For example:
</p>
<pre><strong>
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
</strong></pre>
<p>
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.
</p>
<p>
For example:
</p>
<pre><strong>
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
</strong></pre>
<p>
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:
</p>
<pre><strong>
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
</strong></pre>
<p>
There are a wide range of such low-level configuration commands, besides
FUNCtion, RANGe, and RESolution:
</p>
<pre><strong>
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.
</strong></pre>
<p>
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.
</p>
<p>
* The five math operations are set as follows:
</p>
<pre><strong>
CALCulate:FUNCtion NULL (default)
CALCulate:FUNCtion DB
CALCulate:FUNCtion DBM
CALCulate:FUNCtion AVERage
CALCulate:FUNCtion LIMit
</strong></pre>
<p>
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:
</p>
<pre><strong>
CALCulate:STATe ON
</strong></pre>
<p>
You can disable the math using the OFF parameter instead of the ON parameter.
You can interrogate the state with a CALCulate:STATe? query.
</p>
<p>
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:
</p>
<pre><strong>
CALCulate:NULL:OFFSet
CALCulate:DB:REFerence
CALCulate:DBM:REFerence
CALCulate:LIMit:LOWer
CALCulate:LIMit:UPPer
</strong></pre>
<p>
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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
The following sample program shows how to use the CONFigure command with a
dBm math operation:
</p>
<pre><strong>
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
</strong></pre>
<p>
* 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:
</p>
<ul>
<li> You must configure the DMM for the measurement by selecting the function,
range, resolution, and so on.
</li>
<li> Then you must select the trigger source: command trigger (GET or *TRG),
EXTERNAL TRIGGER input, or an immediate internal trigger.
</li>
<li> 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.
</li>
</ul>
<p>
The triggering system is controlled by the following commands:
</p>
<pre><strong>
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.
</strong></pre>
<p>
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.
</p>
<p>
* 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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
* 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.
</p>
<p>
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:
</p>
<ul>
<li> BIT 3 (8) -- Questionable Data: Indicates a bit set in the Questionable
Data register.
</li>
<li> BIT 4 (16) -- Message Available: Indicates data available in the output
queue.
</li>
<li> BIT 5 (32) -- Standard Event: Indicates a bit set in the Standard Event
register.
</li>
<li> BIT 6 (64) -- Request Service: Indicates that the DMM has requested
service.
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
* The Standard Event register implements six status bits:
</p>
<ul>
<li> BIT 0 (1) -- Operation Complete: Indicates that all commands prior to and
including a *OPC command have been executed.
</li>
<li> 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.
</li>
<li> BIT 3 (8) -- Device Error: Indicates that a self-test, calibration, or
reading overload error occurred.
</li>
<li> BIT 4 (16) -- Execution Error: Indicates that a command execution error
has occurred.
</li>
<li> BIT 5 (32) -- Command Error: Indicates a syntax error in a command string
sent to the DMM.
</li>
<li> BIT 7 (128) -- Power On: Indicates that power has been turn on and the
event register has not yet been read or cleared.
</li>
</ul>
<p>
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.
</p>
<p>
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).
</p>
<p>
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:
</p>
<pre><strong>
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?.
</strong></pre>
<p>
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.
</p>
<p>
* The Questionable Data register implements five status bits:
</p>
<ul>
<li> BIT 0 (1) -- Voltage Overload: Indicates overrange on DC volts, AC volts,
frequency, period, diode, or ratio function.
</li>
<li> BIT 1 (2) -- Current Overload: Indicates overrange on DC or AC current
function.
</li>
<li> BIT 9 (512) -- Ohms Overload: Indicates overrange on 2-wire or 4-wire
ohms test.
</li>
<li> BIT 11 (2048) -- Limit Test Fail LO: Indicates that reading has gone
below the lower limit in the limit test.
</li>
<li> BIT 12 (4096) -- Limit Test Fail HI: Indicates that reading has gone
above the upper limit in the limit test.
</li>
</ul>
<p>
You can read the Questionable Data register with the STATus:QUEStionable:
EVENT? query. This action clears the register. *CLS also clears this
register.
</p>
<p>
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 <em>always</em> 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.
</p>
<p>
* 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:
</p>
<pre><strong>
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.
</strong></pre>
<p>
* 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:
</p>
<pre><strong>
SYSTem:LOCal Put DMM into local state.
SYSTem:REMote Put DMM into remote operation.
SYSTem:RWLock Put DMM into local lockout.
</strong></pre>
<p>
Note that you will not get RS-232 communications to work properly unless
you send a SYSTem:REMote command after reset. <em>not</em>
</p>
<p>
* Error codes are not explained in this document, since a description of the
error accompanies the error code returned by the instrument.
</p>
<h2><a name="ib6_m3">[6.3] A SIMPLE 34401 EXAMPLE PROGRAM</a></h2>
<p>
* 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.
</p>
<pre><strong>
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
</strong></pre>
<hr />
<h1><a name="ib7_m0">[7.0] HPIB Tutor (7): Notes & Comments</a></h1>
<p>
* This last chapter covers a few interesting topics in HPIB not easily
discussed elsewhere.
</p>
<hr />
<ul>
<li>
<a href="#ib7_m1">[7.1] BENCHMARKS</a>
</li>
<li>
<a href="#ib7_m2">[7.2] PASS CONTROL & NON-CONTROLLER OPERATION</a>
</li>
</ul>
<hr />
<p>
<a href="#top">BACK TO INDEX</a>
</p>
<h2><a name="ib7_m1">[7.1] BENCHMARKS</a></h2>
<p>
* 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".
</p>
<p>
Benchmarking is a confusing topic where one is given a very specific value
whose <em>real</em> relationship to what he or she actually wants to know is no
more than an approximation, subject to a number of conditions.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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:
</p>
<ul>
<li> 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.)
</li>
<li> 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.
</li>
<li> 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.
</li>
<li> The speed at which the instrument can communicate. This is a <em>very</em>
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).
<p>
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.
</p>
</li>
</ul>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
The four constraints outlined for the typical benchmark above apply in the
maximum performance benchmark case as well, but with added subtleties:
</p>
<ul>
<li> 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).
<p>
PC configurations can vary enough so that even the same model of PC with
the same options can give surprisingly different results.
</p>
</li>
<li> 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 <em>as large blocks
of data as possible</em>. It will do <em>absolutely nothing else</em>.
<p>
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.
</p>
<p>
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.
</p>
<p>
The assumptions of the program's design are important again, though what
constitutes "realistic" and "unrealistic" in this case are a little more
evasive.
</p>
<p>
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.
</p>
<p>
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.)
</p>
<p>
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 <em>really</em> being stored in RAM.
</p>
<p>
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.
</p>
</li>
<li> 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.
<p>
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.
</p>
<p>
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.
</p>
</li>
<li> 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.
<p>
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.
</p>
</li>
</ul>
<p>
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.
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2><a name="ib7_m2">[7.2] PASS CONTROL & NON-CONTROLLER OPERATION</a></h2>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
The following discussion necessarily repeats information provided in a more
terse fashion in earlier chapters for the sake of coherence.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
This means that if you perform:
</p>
<pre><strong>
OUTPUT 705;"*IDN?"
</strong></pre>
<p>
-- 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:
</p>
<pre><strong>
ERROR 173 Active/system controller req'd
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
Fortunately, you can set a controller to another HPIB address by writing to
HPIB status register 3:
</p>
<pre><strong>
CONTROL 7,3;1 ! Set interface 7 to HPIB address 1.
</strong></pre>
<p>
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.
</p>
<p>
Given this knowledge, it is perfectly easy to pass control from the system
controller to the non-system controller with:
</p>
<pre><strong>
PASS CONTROL 701 ! Sends TCT (Take ConTrol) byte.
</strong></pre>
<p>
The non-system controller can then pass it back with:
</p>
<pre><strong>
PASS CONTROL 721
</strong></pre>
<p>
* Seems pretty simple, right? Well, it is simple, but not quite that
simple. There's a few other details to consider. <em>that</em>
</p>
<p>
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.
</p>
<p>
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):
</p>
<pre><strong>
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
</strong></pre>
<p>
Note that the five lowest bits of status register 3 also give the HPIB
address of the controller:
</p>
<pre><strong>
PRINT "HPIB Address =";BINAND(Sts,31) ! Print lowest five bits.
</strong></pre>
<p>
Anyway, this status is essential for avoiding confusion in
controller-noncontroller operation.
</p>
<p>
* 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.
</p>
<p>
So the inactive controller can assert an SRQ -- service request -- using
the REQUEST statement to ask the active controller to pass control:
</p>
<pre><strong>
REQUEST 7,64
</strong></pre>
<p>
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.
</p>
<p>
The active controller will then perform serial polls to see who asserted the
SRQ. If it's the inactive controller, it then passes control:
</p>
<pre><strong>
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
</strong></pre>
<p>
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:
</p>
<pre><strong>
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
</strong></pre>
<p>
* 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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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 <em>always</em> the system controller, and it is the <em>only</em>
system controller.
</p>
<p>
* This explains about all there is to know about passing control in itself,
with the exception of one final detail: why do it?
</p>
<p>
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.
</p>
<p>
However, it is a common misconception that this is the <em>only</em> 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?
</p>
<p>
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:
</p>
<pre><strong>
OUTPUT 713;"PRINT?"
SEND 7;UNT UNL TALK 713 LISTEN 705 DATA ""
</strong></pre>
<p>
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).
</p>
<p>
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.
</p>
<p>
* 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.
</p>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
ON INTR 7 GOSUB Tlacintr
ENABLE INTR 7;256
</strong></pre>
<p>
When the slave gets the TLAC interrupt, it can then check to see if it is
addresses to talk or listen and respond accordingly:
</p>
<pre><strong>
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
</strong></pre>
<p>
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).
</p>
<p>
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.
</p>
<p>
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:
</p>
<pre><strong>
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
</strong></pre>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<hr />
</body>
</html>
|